fj_core/operations/build/
surface.rs

1use fj_math::{Point, Scalar, Vector};
2
3use crate::{
4    geometry::{GlobalPath, SurfaceGeometry},
5    objects::Surface,
6    operations::insert::Insert,
7    storage::Handle,
8    Core,
9};
10
11/// Build a [`Surface`]
12///
13/// See [module-level documentation] for context.
14///
15/// [module-level documentation]: super
16pub trait BuildSurface {
17    /// Build a plane from the provided points
18    fn plane_from_points(
19        points: [impl Into<Point<3>>; 3],
20        core: &mut Core,
21    ) -> (Handle<Surface>, [Point<2>; 3]) {
22        let [a, b, c] = points.map(Into::into);
23
24        let (u, u_line) = GlobalPath::line_from_points([a, b]);
25        let v = c - a;
26
27        let surface = Surface::surface_from_uv(u, v, core);
28
29        let points_surface = {
30            let [a, b] =
31                u_line.map(|point| Point::from([point.t, Scalar::ZERO]));
32            let c = Point::from([a.u, Scalar::ONE]);
33
34            [a, b, c]
35        };
36
37        (surface, points_surface)
38    }
39
40    /// Build a plane from the provided `u` and `v`
41    fn surface_from_uv(
42        u: impl Into<GlobalPath>,
43        v: impl Into<Vector<3>>,
44        core: &mut Core,
45    ) -> Handle<Surface> {
46        let surface = Surface::new().insert(core);
47
48        core.layers.geometry.define_surface(
49            surface.clone(),
50            SurfaceGeometry {
51                u: u.into(),
52                v: v.into(),
53            },
54        );
55
56        surface
57    }
58}
59
60impl BuildSurface for Surface {}