MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / point_on_segment

Function point_on_segment

nodedb-spatial/src/predicates/edge.rs:73–85  ·  view source on GitHub ↗

Whether a point lies exactly on a line segment (within epsilon tolerance).

(pt: [f64; 2], seg_a: [f64; 2], seg_b: [f64; 2])

Source from the content-addressed store, hash-verified

71
72/// Whether a point lies exactly on a line segment (within epsilon tolerance).
73pub fn point_on_segment(pt: [f64; 2], seg_a: [f64; 2], seg_b: [f64; 2]) -> bool {
74 // Check collinearity via cross product.
75 let cross =
76 (pt[0] - seg_a[0]) * (seg_b[1] - seg_a[1]) - (pt[1] - seg_a[1]) * (seg_b[0] - seg_a[0]);
77 if cross.abs() > 1e-10 {
78 return false;
79 }
80 // Check that pt is within the segment's bounding box.
81 pt[0] >= seg_a[0].min(seg_b[0]) - 1e-10
82 && pt[0] <= seg_a[0].max(seg_b[0]) + 1e-10
83 && pt[1] >= seg_a[1].min(seg_b[1]) - 1e-10
84 && pt[1] <= seg_a[1].max(seg_b[1]) + 1e-10
85}
86
87/// Whether a point lies on any edge of a polygon ring.
88pub fn point_on_ring_boundary(pt: [f64; 2], ring: &[[f64; 2]]) -> bool {

Callers 1

point_on_ring_boundaryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected