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) * crossmoment 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]ofpoints; the empty set gives[+INF, +INF, -INF, -INF].f64::min/maxskip 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
pagainst the closed ringat(0..n);falsebelow three vertices. A point on the boundary is decided by the half-open crossing rule (an edge counts when exactly one endpoint is abovep.yandp.xis strictly left of the crossing), and a NaN comparison never counts as a crossing. - point_
segment_ distance - Distance from
pto the closed segmenta-b(the point distance when the segment is a point). - polygon_
area - Signed shoelace area: positive for a counter-clockwise ring,
0below 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 < 3sums to zero or the caller’s own NaN);polygon_areaadds it. - shoelace2_
edges shoelace2_byover 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);0below three vertices. Non-finite coordinates propagate as NaN. - sub
Type Aliases§
- P2
- A plane point or vector.