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

Function orientation

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

Compute orientation of ordered triplet (p, q, r).

(p: [f64; 2], q: [f64; 2], r: [f64; 2])

Source from the content-addressed store, hash-verified

18
19/// Compute orientation of ordered triplet (p, q, r).
20pub fn orientation(p: [f64; 2], q: [f64; 2], r: [f64; 2]) -> Orientation {
21 let val = (q[1] - p[1]) * (r[0] - q[0]) - (q[0] - p[0]) * (r[1] - q[1]);
22 // Use epsilon for floating-point tolerance.
23 if val.abs() < 1e-12 {
24 Orientation::Collinear
25 } else if val > 0.0 {
26 Orientation::Clockwise
27 } else {
28 Orientation::CounterClockwise
29 }
30}
31
32/// Whether point q lies on segment p-r (given that p, q, r are collinear).
33pub fn on_segment(p: [f64; 2], q: [f64; 2], r: [f64; 2]) -> bool {

Callers 2

segments_intersectFunction · 0.85
edges_properly_crossFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected