Skip to main content

spread

Function spread 

Source
pub fn spread(
    positions: &mut Positions,
    obstacles: &[Point],
    params: &SpreadParams,
) -> Result<SpreadReport, GeometryError>
Available on crate feature geometry only.
Expand description

Pushes points apart until none is closer than min_distance to another, within a fixed number of steps.

Rules, in order of a step: every point meets the points of the nine cells around it that come later in insertion order, at most max_neighbours of them; a close pair is pushed apart by half the shortfall each along the line between them; two points on one spot part along a direction chosen from the two ids, so adding a far node changes no other node’s bits; each point’s summed push is cut to half the distance; obstacles (which never move) push points out to the distance in full; all points move at once; then bounds, if set, clamp.

steps = 0 changes nothing. Overlaps that remain (for example when bounds are narrower than the distance) are reported in SpreadReport::overlaps_left, never looped on.

§Errors

GeometryError::BadParameter for a min_distance that is not finite and above zero, a max_neighbours of zero, or invalid bounds; GeometryError::NonFinitePosition for a point (named by id) or an obstacle (named #<index>) that is not finite.