Skip to main content

use_intersection/
lib.rs

1#![forbid(unsafe_code)]
2#![doc = include_str!("../README.md")]
3
4use use_point::Point2;
5
6/// A minimal two-dimensional intersection result.
7#[derive(Debug, Clone, Copy, PartialEq)]
8pub enum Intersection2 {
9    /// No intersection was found.
10    None,
11    /// A single point intersection.
12    Point(Point2),
13    /// A finite overlapping region or segment.
14    Overlap,
15    /// Infinitely many intersections, such as coincident infinite primitives.
16    Infinite,
17}
18
19impl Intersection2 {
20    /// Returns `true` when this is [`Intersection2::None`].
21    #[must_use]
22    pub const fn is_empty(self) -> bool {
23        matches!(self, Self::None)
24    }
25}
26
27/// A trait for values that can report whether they intersect `Rhs`.
28pub trait Intersects<Rhs = Self> {
29    /// Returns `true` when `self` intersects `rhs`.
30    fn intersects(&self, rhs: &Rhs) -> bool;
31}
32
33#[cfg(test)]
34mod tests {
35    use super::Intersection2;
36    use use_point::Point2;
37
38    #[test]
39    fn classifies_empty_and_point_intersections() {
40        assert!(Intersection2::None.is_empty());
41        assert!(!Intersection2::Point(Point2::new(1.0, 2.0)).is_empty());
42    }
43}