From 676b470de9fa75df7347b50586d1dff66f94465d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 26 Feb 2024 14:35:14 +0100 Subject: [PATCH 1/2] Add `BuildSurface::plane_from_uv` --- crates/fj-core/src/operations/build/surface.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/fj-core/src/operations/build/surface.rs b/crates/fj-core/src/operations/build/surface.rs index b4075a1c69..f9092d6a20 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}, @@ -33,6 +33,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 {} From d97a4bd619f7816626631978b63510d29a0c3365 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 26 Feb 2024 14:35:14 +0100 Subject: [PATCH 2/2] Make use of `BuildSurface::plane_from_uv` --- crates/fj-core/src/objects/stores.rs | 18 ++----- .../fj-core/src/operations/build/surface.rs | 3 +- crates/fj-core/src/operations/sweep/path.rs | 3 +- crates/fj-core/src/validate/solid.rs | 52 +++++++++---------- 4 files changed, 34 insertions(+), 42 deletions(-) diff --git a/crates/fj-core/src/objects/stores.rs b/crates/fj-core/src/objects/stores.rs index c9811c6a3e..1eb4ae0ad4 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 f9092d6a20..707463ed5d 100644 --- a/crates/fj-core/src/operations/build/surface.rs +++ b/crates/fj-core/src/operations/build/surface.rs @@ -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] = diff --git a/crates/fj-core/src/operations/sweep/path.rs b/crates/fj-core/src/operations/sweep/path.rs index f4f57cde45..e750f02101 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 c07832064a..99fafc6a7c 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),