Skip to main content

Module primitives

Module primitives 

Source
Expand description

Fundamental integer geometry primitives. All coordinates are i64 (fixed-point). All intermediate computations use i128. ZERO floating point. ZERO epsilon. Exact integer arithmetic throughout.

Enums§

Orientation
Orientation of three points.

Functions§

cross2d
2D cross product of vectors (A→B) × (A→C). Equivalent to: (bx-ax)(cy-ay) - (by-ay)(cx-ax) Positive = CCW (left turn), Negative = CW (right turn), Zero = collinear. Casts to i128 before multiply — no overflow for coords up to MAX_WORLD=40_075_017_000_000.
edge_squared_length
Squared Euclidean distance between two points (using i128 to avoid overflow). Returns dx² + dy². Used for edge length validation (compare against MIN_EDGE_LENGTH_SQUARED).
is_collinear_pts
True if P is collinear with A and B (cross product == 0).
is_left
True if P is strictly left of line A→B (cross product > 0 for CCW polygon).
is_left_or_on
True if P is strictly left of or on line A→B.
is_reflex
True if vertex curr is a reflex vertex in a CCW polygon. A reflex vertex has a CW turn (cross product < 0) in a CCW polygon. prev → curr → next should be a left turn for convex, right turn for reflex.
is_right
True if P is strictly right of line A→B.
is_right_or_on
True if P is strictly right of or on line A→B.
orientation
Orientation of three points A, B, C.
point_on_segment
True if point P lies on segment A→B (collinear AND within the bounding box of A→B).
segments_intersect
True if segments A1→A2 and B1→B2 intersect (proper crossing OR endpoint on segment).
segments_properly_intersect
True if segments A1→A2 and B1→B2 properly intersect (cross each other, not collinear). Proper intersection: each segment straddles the other’s line (both endpoints on opposite sides). Does NOT count T-junctions (endpoint on segment) as proper intersection.