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
//! Intersection between a ray and an edge in 2D

use fj_math::Segment;

use crate::{
    algorithms::intersect::{HorizontalRayToTheRight, Intersect},
    geometry::curve::Curve,
    objects::HalfEdge,
    storage::Handle,
};

use super::ray_segment::RaySegmentIntersection;

impl Intersect for (&HorizontalRayToTheRight<2>, &Handle<HalfEdge>) {
    type Intersection = RaySegmentIntersection;

    fn intersect(self) -> Option<Self::Intersection> {
        let (ray, edge) = self;

        let line = match edge.curve() {
            Curve::Line(line) => line,
            Curve::Circle(_) => {
                todo!("Casting rays against circles is not supported yet")
            }
        };

        let points = edge
            .boundary()
            .map(|point| line.point_from_line_coords(point));
        let segment = Segment::from_points(points);

        (ray, &segment).intersect()
    }
}