Skip to main content

contour_gap

Function contour_gap 

Source
pub fn contour_gap(
    a: &[(&[[f64; 2]], bool)],
    b: &[(&[[f64; 2]], bool)],
) -> Result<Option<Gap2>>
Expand description

The minimum distance between the segments of the polylines a and those of b, each with whether it is closed, with the closest pair of points.

An open polyline of n points has n − 1 segments, and a closed one also joins its last point to its first. When segments of the two sides cross or touch, the distance is 0 and both points are the same point where they meet. Returns None when either side has no segments.

The segments of b are binned in a uniform grid with about one cell per segment, and each segment of a searches outward through it ring by ring until no unvisited cell can be closer. The segments of a are taken nearest b’s bounding box first, and the search stops at the first one whose box is at least the best distance from it. The result is the exact minimum of the pairwise distances, not an approximation.

Known limits: a segment of a starts from every cell its box overlaps, so a very long one still visits many cells on its first ring (mesh sections have short segments). Coordinates beyond about 1e154 overflow the squared distances.

§Errors