diff --git a/crates/fj-core/src/algorithms/approx/curve.rs b/crates/fj-core/src/algorithms/approx/curve.rs index d14ea7a5c..fcd2dc82b 100644 --- a/crates/fj-core/src/algorithms/approx/curve.rs +++ b/crates/fj-core/src/algorithms/approx/curve.rs @@ -183,7 +183,7 @@ mod tests { use crate::{ algorithms::approx::{Approx, ApproxPoint}, geometry::{CurveBoundary, GlobalPath, HalfEdgeGeom, SurfacePath}, - operations::{build::BuildSurface, insert::Insert}, + operations::build::{BuildCurve, BuildSurface}, topology::{Curve, Surface}, Core, }; @@ -195,7 +195,8 @@ mod tests { let surface = core.layers.topology.surfaces.xz_plane(); let (path, boundary) = SurfacePath::line_from_points([[1., 1.], [2., 1.]]); - let curve = Curve::new().insert(&mut core); + let curve = + Curve::from_path_and_surface(path, surface.clone(), &mut core); let boundary = CurveBoundary::from(boundary); let half_edge = HalfEdgeGeom { path, boundary }; @@ -217,7 +218,8 @@ mod tests { ); let (path, boundary) = SurfacePath::line_from_points([[1., 1.], [2., 1.]]); - let curve = Curve::new().insert(&mut core); + let curve = + Curve::from_path_and_surface(path, surface.clone(), &mut core); let boundary = CurveBoundary::from(boundary); let half_edge = HalfEdgeGeom { path, boundary }; @@ -238,7 +240,8 @@ mod tests { ([0.], [0., 1.]), ([TAU], [TAU, 1.]), ]); - let curve = Curve::new().insert(&mut core); + let curve = + Curve::from_path_and_surface(path, surface.clone(), &mut core); let boundary = CurveBoundary::from([[0.], [TAU]]); let half_edge = HalfEdgeGeom { path, boundary }; @@ -268,7 +271,8 @@ mod tests { let surface = core.layers.topology.surfaces.xz_plane(); let path = SurfacePath::circle_from_center_and_radius([0., 0.], 1.); - let curve = Curve::new().insert(&mut core); + let curve = + Curve::from_path_and_surface(path, surface.clone(), &mut core); let boundary = CurveBoundary::from([[0.], [TAU]]); let half_edge = HalfEdgeGeom { path, boundary }; diff --git a/crates/fj-core/src/geometry/curve.rs b/crates/fj-core/src/geometry/curve.rs index a85d43329..392ef64cc 100644 --- a/crates/fj-core/src/geometry/curve.rs +++ b/crates/fj-core/src/geometry/curve.rs @@ -25,6 +25,18 @@ pub struct CurveGeom { pub definitions: Vec, } +impl CurveGeom { + /// Create a new instance of `CurveGeom` from a path and a surface + pub fn from_path_and_surface( + path: SurfacePath, + surface: Handle, + ) -> Self { + Self { + definitions: vec![LocalCurveGeom { path, surface }], + } + } +} + /// The geometric definition of a curve in 2D surface coordinates #[derive(Clone)] pub struct LocalCurveGeom { diff --git a/crates/fj-core/src/operations/build/curve.rs b/crates/fj-core/src/operations/build/curve.rs new file mode 100644 index 000000000..4623fa43b --- /dev/null +++ b/crates/fj-core/src/operations/build/curve.rs @@ -0,0 +1,32 @@ +use crate::{ + geometry::{CurveGeom, SurfacePath}, + operations::insert::Insert, + storage::Handle, + topology::{Curve, Surface}, + Core, +}; + +/// Build a [`Curve`] +/// +/// See [module-level documentation] for context. +/// +/// [module-level documentation]: super +pub trait BuildCurve { + /// Build a curve from the provided path and surface + fn from_path_and_surface( + path: SurfacePath, + surface: Handle, + core: &mut Core, + ) -> Handle { + let curve = Curve::new().insert(core); + + core.layers.geometry.define_curve( + curve.clone(), + CurveGeom::from_path_and_surface(path, surface), + ); + + curve + } +} + +impl BuildCurve for Curve {} diff --git a/crates/fj-core/src/operations/build/mod.rs b/crates/fj-core/src/operations/build/mod.rs index 4f6a5b503..a992276f9 100644 --- a/crates/fj-core/src/operations/build/mod.rs +++ b/crates/fj-core/src/operations/build/mod.rs @@ -17,6 +17,7 @@ //! the top-level object itself, but also to the other objects that make up its //! components. +mod curve; mod cycle; mod face; mod half_edge; @@ -27,6 +28,7 @@ mod solid; mod surface; pub use self::{ + curve::BuildCurve, cycle::BuildCycle, face::{BuildFace, Polygon}, half_edge::BuildHalfEdge,