Whether a point lies exactly on a line segment (within epsilon tolerance).
(pt: [f64; 2], seg_a: [f64; 2], seg_b: [f64; 2])
| 71 | |
| 72 | /// Whether a point lies exactly on a line segment (within epsilon tolerance). |
| 73 | pub 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. |
| 88 | pub fn point_on_ring_boundary(pt: [f64; 2], ring: &[[f64; 2]]) -> bool { |
no outgoing calls
no test coverage detected