Compute orientation of ordered triplet (p, q, r).
(p: [f64; 2], q: [f64; 2], r: [f64; 2])
| 18 | |
| 19 | /// Compute orientation of ordered triplet (p, q, r). |
| 20 | pub 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). |
| 33 | pub fn on_segment(p: [f64; 2], q: [f64; 2], r: [f64; 2]) -> bool { |
no outgoing calls
no test coverage detected