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
use fj_math::{Aabb, Vector};

use crate::{geometry::curve::Curve, objects::HalfEdge};

impl super::BoundingVolume<2> for HalfEdge {
    fn aabb(&self) -> Option<Aabb<2>> {
        match self.curve() {
            Curve::Circle(circle) => {
                // Just calculate the AABB of the whole circle. This is not the
                // most precise, but it should do for now.

                let center_to_min_max =
                    Vector::from([circle.radius(), circle.radius()]);

                Some(Aabb {
                    min: circle.center() - center_to_min_max,
                    max: circle.center() + center_to_min_max,
                })
            }
            Curve::Line(_) => {
                let points = self.boundary().map(|point_curve| {
                    self.curve().point_from_path_coords(point_curve)
                });

                Some(Aabb::<2>::from_points(points))
            }
        }
    }
}