diff --git a/crates/fj-core/src/objects/stores.rs b/crates/fj-core/src/objects/stores.rs index c9811c6a3..1eb4ae0ad 100644 --- a/crates/fj-core/src/objects/stores.rs +++ b/crates/fj-core/src/objects/stores.rs @@ -1,7 +1,8 @@ use fj_math::Vector; use crate::{ - geometry::{GlobalPath, SurfaceGeometry}, + geometry::GlobalPath, + operations::build::BuildSurface, storage::{Handle, Store}, }; @@ -94,27 +95,18 @@ impl Default for Surfaces { let xy_plane = store.reserve(); store.insert( xy_plane.clone(), - Surface::new(SurfaceGeometry { - u: GlobalPath::x_axis(), - v: Vector::unit_y(), - }), + Surface::plane_from_uv(GlobalPath::x_axis(), Vector::unit_y()), ); let xz_plane = store.reserve(); store.insert( xz_plane.clone(), - Surface::new(SurfaceGeometry { - u: GlobalPath::x_axis(), - v: Vector::unit_z(), - }), + Surface::plane_from_uv(GlobalPath::x_axis(), Vector::unit_z()), ); let yz_plane = store.reserve(); store.insert( yz_plane.clone(), - Surface::new(SurfaceGeometry { - u: GlobalPath::y_axis(), - v: Vector::unit_z(), - }), + Surface::plane_from_uv(GlobalPath::y_axis(), Vector::unit_z()), ); Self { diff --git a/crates/fj-core/src/operations/build/surface.rs b/crates/fj-core/src/operations/build/surface.rs index b4075a1c6..707463ed5 100644 --- a/crates/fj-core/src/operations/build/surface.rs +++ b/crates/fj-core/src/operations/build/surface.rs @@ -1,4 +1,4 @@ -use fj_math::{Point, Scalar}; +use fj_math::{Point, Scalar, Vector}; use crate::{ geometry::{GlobalPath, SurfaceGeometry}, @@ -20,8 +20,7 @@ pub trait BuildSurface { let (u, u_line) = GlobalPath::line_from_points([a, b]); let v = c - a; - let geometry = SurfaceGeometry { u, v }; - let surface = Surface::new(geometry); + let surface = Surface::plane_from_uv(u, v); let points_surface = { let [a, b] = @@ -33,6 +32,18 @@ pub trait BuildSurface { (surface, points_surface) } + + /// Build a plane from the provided `u` and `v` + fn plane_from_uv( + u: impl Into, + v: impl Into>, + ) -> Surface { + let geometry = SurfaceGeometry { + u: u.into(), + v: v.into(), + }; + Surface::new(geometry) + } } impl BuildSurface for Surface {} diff --git a/crates/fj-core/src/operations/sweep/path.rs b/crates/fj-core/src/operations/sweep/path.rs index f4f57cde4..e750f0210 100644 --- a/crates/fj-core/src/operations/sweep/path.rs +++ b/crates/fj-core/src/operations/sweep/path.rs @@ -3,6 +3,7 @@ use fj_math::{Circle, Line, Vector}; use crate::{ geometry::{GlobalPath, SurfaceGeometry, SurfacePath}, objects::Surface, + operations::build::BuildSurface, }; /// # Sweep a [`SurfacePath`] @@ -79,6 +80,6 @@ impl SweepSurfacePath for SurfacePath { } }; - Surface::new(SurfaceGeometry { u, v: path.into() }) + Surface::plane_from_uv(u, path) } } diff --git a/crates/fj-core/src/validate/solid.rs b/crates/fj-core/src/validate/solid.rs index c07832064..99fafc6a7 100644 --- a/crates/fj-core/src/validate/solid.rs +++ b/crates/fj-core/src/validate/solid.rs @@ -175,10 +175,10 @@ impl SolidValidationError { mod tests { use crate::{ assert_contains_err, - geometry::{GlobalPath, SurfaceGeometry}, + geometry::GlobalPath, objects::{Cycle, Face, HalfEdge, Region, Shell, Solid, Surface}, operations::{ - build::{BuildFace, BuildHalfEdge}, + build::{BuildFace, BuildHalfEdge, BuildSurface}, insert::Insert, }, validate::{ @@ -193,10 +193,10 @@ mod tests { let mut core = Core::new(); let shared_face = Face::new( - Surface::new(SurfaceGeometry { - u: GlobalPath::circle_from_radius(1.), - v: [0., 1., 1.].into(), - }) + Surface::plane_from_uv( + GlobalPath::circle_from_radius(1.), + [0., 1., 1.], + ) .insert(&mut core), Region::new( Cycle::new(vec![ @@ -255,19 +255,19 @@ mod tests { let invalid_solid = Solid::new(vec![Shell::new(vec![ Face::new( - Surface::new(SurfaceGeometry { - u: GlobalPath::circle_from_radius(1.), - v: [0., 1., 1.].into(), - }) + Surface::plane_from_uv( + GlobalPath::circle_from_radius(1.), + [0., 1., 1.], + ) .insert(&mut core), shared_region.clone(), ) .insert(&mut core), Face::new( - Surface::new(SurfaceGeometry { - u: GlobalPath::circle_from_radius(1.), - v: [0., 0., 1.].into(), - }) + Surface::plane_from_uv( + GlobalPath::circle_from_radius(1.), + [0., 0., 1.], + ) .insert(&mut core), shared_region.clone(), ) @@ -304,19 +304,19 @@ mod tests { let invalid_solid = Solid::new(vec![Shell::new(vec![ Face::new( - Surface::new(SurfaceGeometry { - u: GlobalPath::circle_from_radius(1.), - v: [0., 1., 1.].into(), - }) + Surface::plane_from_uv( + GlobalPath::circle_from_radius(1.), + [0., 1., 1.], + ) .insert(&mut core), Region::new(shared_cycle.clone(), vec![]).insert(&mut core), ) .insert(&mut core), Face::new( - Surface::new(SurfaceGeometry { - u: GlobalPath::circle_from_radius(1.), - v: [0., 0., 1.].into(), - }) + Surface::plane_from_uv( + GlobalPath::circle_from_radius(1.), + [0., 0., 1.], + ) .insert(&mut core), Region::new(shared_cycle, vec![]).insert(&mut core), ) @@ -349,10 +349,10 @@ mod tests { HalfEdge::circle([0., 0.], 1., &mut core).insert(&mut core); let invalid_solid = Solid::new(vec![Shell::new(vec![Face::new( - Surface::new(SurfaceGeometry { - u: GlobalPath::circle_from_radius(1.), - v: [0., 0., 1.].into(), - }) + Surface::plane_from_uv( + GlobalPath::circle_from_radius(1.), + [0., 0., 1.], + ) .insert(&mut core), Region::new( Cycle::new(vec![shared_edge.clone()]).insert(&mut core),