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