spade/delaunay_core/line_side_info.rs
1/// Describes on which side of a line a point lies.
2///
3/// Created by [DirectedEdgeHandle::side_query](crate::handles::DirectedEdgeHandle::side_query)
4#[derive(Debug, Clone, Copy)]
5pub struct LineSideInfo {
6 signed_side: f64,
7}
8
9impl PartialEq for LineSideInfo {
10 fn eq(&self, other: &LineSideInfo) -> bool {
11 if self.is_on_line() || other.is_on_line() {
12 self.is_on_line() && other.is_on_line()
13 } else {
14 self.is_on_right_side() == other.is_on_right_side()
15 }
16 }
17}
18
19impl LineSideInfo {
20 #[inline]
21 pub(crate) fn from_determinant(s: f64) -> LineSideInfo {
22 LineSideInfo { signed_side: s }
23 }
24
25 /// Returns `true` if a point lies on the left side of a line.
26 ///
27 /// For left-handed coordinate systems, this method returns if a point lies on the right side of a line.
28 /// This method returns `false` if the point lies exactly on the line.
29 pub fn is_on_left_side(&self) -> bool {
30 self.signed_side > 0.0
31 }
32
33 /// Returns `true` if a point lies on the right side of a line.
34 ///
35 /// For left-handed coordinate systems, this method returns if a point lies on the left side of a line.
36 /// This method returns `false` if the point lies exactly on the line.
37 pub fn is_on_right_side(&self) -> bool {
38 self.signed_side < 0.0
39 }
40
41 /// Returns `true` if a point lies on the left side of a line or is on the line itself.
42 ///
43 /// For left-handed coordinate systems, this method returns if a point lies on the left side of a line.
44 pub fn is_on_left_side_or_on_line(&self) -> bool {
45 self.signed_side >= 0.0
46 }
47
48 /// Returns `true` if a point lies on the right side of a line or is on the line itself.
49 ///
50 /// For left handed coordinate systems, this method returns if a point lies on the left side of a line.
51 pub fn is_on_right_side_or_on_line(self) -> bool {
52 self.signed_side <= 0.0
53 }
54
55 /// Returns `true` if a point lies exactly on this line.
56 #[inline]
57 pub fn is_on_line(self) -> bool {
58 self.signed_side.abs() == 0.0
59 }
60
61 /// Returns the opposite of this `LineSideInfo`.
62 pub fn reversed(self) -> LineSideInfo {
63 LineSideInfo {
64 signed_side: -self.signed_side,
65 }
66 }
67}