fj_core/algorithms/intersect/
mod.rs

1//! Intersection algorithms
2
3pub mod ray_segment;
4
5mod line_segment;
6
7use fj_math::{Point, Vector};
8
9pub use self::line_segment::LineSegmentIntersection;
10
11/// Compute the intersection between a tuple of objects
12///
13/// # Implementation Note
14///
15/// This trait is newer than most of the intersection algorithms in this module.
16/// Most of them don't support it yet.
17pub trait Intersect {
18    /// The type that describes the intersection between the objects in `Self`
19    type Intersection;
20
21    /// Compute the intersection between a tuple of objects
22    fn intersect(self) -> Option<Self::Intersection>;
23}
24
25/// A horizontal ray that goes to the right
26///
27/// For in-kernel use, we don't need anything more flexible, and being exactly
28/// horizontal simplifies some calculations.
29#[derive(Clone, Copy, Debug, Eq, PartialEq)]
30pub struct HorizontalRayToTheRight<const D: usize> {
31    /// The point where the ray originates
32    pub origin: Point<D>,
33}
34
35impl<const D: usize> HorizontalRayToTheRight<D> {
36    /// Access the direction of this ray
37    pub fn direction(&self) -> Vector<D> {
38        let mut components = [0.; D];
39        components[0] = 1.;
40        components.into()
41    }
42}
43
44impl<P, const D: usize> From<P> for HorizontalRayToTheRight<D>
45where
46    P: Into<Point<D>>,
47{
48    fn from(point: P) -> Self {
49        Self {
50            origin: point.into(),
51        }
52    }
53}