Module v2

Module v2 

Source
Expand description

Plane vectors and ring primitives over [f64; 2]: the one home for the 2D kit that geom2d, bool2d, scan_outline, the triangulator, the export plates and the processing PDF/scan code each used to carry a copy of (#7773). Every function is FMA-free with the op order written out; see the module conventions.

Rings are implicitly closed (edge i runs ring[i] -> ring[(i + 1) % n]). The _by forms take an index accessor instead of a slice so a flat [x0, y0, x1, y1, ..] buffer, a nalgebra Point2 contour or a half-edge cycle run through the very same loop without being copied first.

The exact (Shewchuk) predicates live in geom2d; nothing here is adaptive.

Functions§

add
area_centroid
Area centroid of a ring whose signed area is area (non-zero): the (p + q) * cross moment sum over six times the area. Non-finite when the area is zero; the caller screens that.
bbox
Bounding box [min_x, min_y, max_x, max_y] of points; the empty set gives [+INF, +INF, -INF, -INF]. f64::min/max skip NaN, so a NaN coordinate never poisons the box.
cross
The z component of the 3D cross product: a0*b1 - a1*b0, never fused.
dist
Distance via hypot (no intermediate overflow).
dist2
Squared distance, dx*dx + dy*dy.
dot
a0*b0 + a1*b1, never fused.
norm
Euclidean length, dot(a, a).sqrt().
point_in_polygon
Ray-cast point-in-polygon for an arbitrary simple ring.
point_in_ring_by
Even-odd ray cast of p against the closed ring at(0..n); false below three vertices. A point on the boundary is decided by the half-open crossing rule (an edge counts when exactly one endpoint is above p.y and p.x is strictly left of the crossing), and a NaN comparison never counts as a crossing.
point_segment_distance
Distance from p to the closed segment a-b (the point distance when the segment is a point).
polygon_area
Signed shoelace area: positive for a counter-clockwise ring, 0 below three vertices.
scale
shoelace2_by
Twice the signed shoelace area of the closed ring at(0..n): positive for counter-clockwise. No degenerate guard (n < 3 sums to zero or the caller’s own NaN); polygon_area adds it.
shoelace2_edges
shoelace2_by over explicit directed edges (from, to), for a cycle that is not stored as a vertex array (a half-edge loop).
signed_area_by
Signed shoelace area of the closed ring at(0..n); 0 below three vertices. Non-finite coordinates propagate as NaN.
sub

Type Aliases§

P2
A plane point or vector.