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
use fj_math::{Point, Scalar};

use crate::objects::Edge;

use super::{curve::RangeOnCurve, Approx};

impl Approx for Edge {
    type Approximation = Vec<(Point<2>, Point<3>)>;
    type Params = ();

    fn approx(
        &self,
        tolerance: super::Tolerance,
        (): Self::Params,
    ) -> Self::Approximation {
        // The range is only used for circles right now.
        let boundary = match self.vertices().get() {
            Some(vertices) => vertices
                .map(|vertex| (vertex.position(), vertex.global().position())),
            None => {
                let start_curve = Point::from([Scalar::ZERO]);
                let end_curve = Point::from([Scalar::TAU]);

                // We're dealing with a circle here. Start and end are identical
                // points, in global coordinates.
                let point_global = self
                    .global()
                    .curve()
                    .kind()
                    .point_from_curve_coords(start_curve);

                [(start_curve, point_global), (end_curve, point_global)]
            }
        };

        let range = RangeOnCurve { boundary };

        self.curve().approx(tolerance, range)
    }
}