From 635fc5164529813c6e57dfef561e52c479fdc107 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 29 Apr 2024 13:48:15 +0200 Subject: [PATCH 1/3] Derive `Default` for `CurveGeom` --- crates/fj-core/src/geometry/curve.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-core/src/geometry/curve.rs b/crates/fj-core/src/geometry/curve.rs index 67ccd34d5..8563a0f35 100644 --- a/crates/fj-core/src/geometry/curve.rs +++ b/crates/fj-core/src/geometry/curve.rs @@ -5,7 +5,7 @@ use crate::{storage::Handle, topology::Surface}; use super::SurfacePath; /// The geometric definition of a curve -#[derive(Clone)] +#[derive(Clone, Default)] pub struct CurveGeom { /// # The redundant local definitions of the curve geometry /// From 128a15df5387ec08b16f415a200a893f5ef8bc64 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 29 Apr 2024 13:49:05 +0200 Subject: [PATCH 2/3] Fix API for defining curve geometry The previous version would not allow defining local curve geometry for multiple surfaces. --- crates/fj-core/src/geometry/geometry.rs | 11 +++++--- crates/fj-core/src/layers/geometry.rs | 27 +++++++++++++++---- .../fj-core/src/operations/build/half_edge.rs | 11 +++++--- .../fj-core/src/operations/geometry/curve.rs | 7 ++--- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/crates/fj-core/src/geometry/geometry.rs b/crates/fj-core/src/geometry/geometry.rs index 6b76d3661..5b180ccf0 100644 --- a/crates/fj-core/src/geometry/geometry.rs +++ b/crates/fj-core/src/geometry/geometry.rs @@ -7,7 +7,7 @@ use crate::{ topology::{Curve, HalfEdge, Surface, Topology}, }; -use super::{CurveGeom, GlobalPath, HalfEdgeGeom, SurfaceGeom}; +use super::{CurveGeom, GlobalPath, HalfEdgeGeom, LocalCurveGeom, SurfaceGeom}; /// Geometric data that is associated with topological objects pub struct Geometry { @@ -65,9 +65,14 @@ impl Geometry { pub(crate) fn define_curve_inner( &mut self, curve: Handle, - geometry: CurveGeom, + surface: Handle, + geometry: LocalCurveGeom, ) { - self.curve.insert(curve, geometry); + self.curve + .entry(curve) + .or_default() + .definitions + .insert(surface, geometry); } pub(crate) fn define_half_edge_inner( diff --git a/crates/fj-core/src/layers/geometry.rs b/crates/fj-core/src/layers/geometry.rs index b621acfff..b544e82e5 100644 --- a/crates/fj-core/src/layers/geometry.rs +++ b/crates/fj-core/src/layers/geometry.rs @@ -1,7 +1,7 @@ //! Layer infrastructure for [`Geometry`] use crate::{ - geometry::{CurveGeom, Geometry, HalfEdgeGeom, SurfaceGeom}, + geometry::{Geometry, HalfEdgeGeom, LocalCurveGeom, SurfaceGeom}, storage::Handle, topology::{Curve, HalfEdge, Surface}, }; @@ -10,9 +10,21 @@ use super::{Command, Event, Layer}; impl Layer { /// Define the geometry of the provided curve - pub fn define_curve(&mut self, curve: Handle, geometry: CurveGeom) { + pub fn define_curve( + &mut self, + curve: Handle, + surface: Handle, + geometry: LocalCurveGeom, + ) { let mut events = Vec::new(); - self.process(DefineCurve { curve, geometry }, &mut events); + self.process( + DefineCurve { + curve, + surface, + geometry, + }, + &mut events, + ); } /// Define the geometry of the provided half-edge @@ -50,7 +62,8 @@ impl Layer { /// Define the geometry of a curve pub struct DefineCurve { curve: Handle, - geometry: CurveGeom, + surface: Handle, + geometry: LocalCurveGeom, } impl Command for DefineCurve { @@ -68,7 +81,11 @@ impl Command for DefineCurve { impl Event for DefineCurve { fn evolve(&self, state: &mut Geometry) { - state.define_curve_inner(self.curve.clone(), self.geometry.clone()); + state.define_curve_inner( + self.curve.clone(), + self.surface.clone(), + self.geometry.clone(), + ); } } diff --git a/crates/fj-core/src/operations/build/half_edge.rs b/crates/fj-core/src/operations/build/half_edge.rs index 7baa68e27..8ba8b3008 100644 --- a/crates/fj-core/src/operations/build/half_edge.rs +++ b/crates/fj-core/src/operations/build/half_edge.rs @@ -2,7 +2,7 @@ use fj_interop::ext::ArrayExt; use fj_math::{Arc, Point, Scalar}; use crate::{ - geometry::{CurveGeom, HalfEdgeGeom, SurfacePath}, + geometry::{HalfEdgeGeom, LocalCurveGeom, SurfacePath}, operations::{geometry::UpdateHalfEdgeGeometry, insert::Insert}, storage::Handle, topology::{Curve, HalfEdge, Surface, Vertex}, @@ -65,7 +65,8 @@ pub trait BuildHalfEdge { core.layers.geometry.define_curve( half_edge.curve().clone(), - CurveGeom::from_path_and_surface(path, surface), + surface, + LocalCurveGeom { path }, ); core.layers.geometry.define_half_edge( half_edge.clone(), @@ -93,7 +94,8 @@ pub trait BuildHalfEdge { core.layers.geometry.define_curve( half_edge.curve().clone(), - CurveGeom::from_path_and_surface(path, surface), + surface, + LocalCurveGeom { path }, ); core.layers.geometry.define_half_edge( half_edge.clone(), @@ -123,7 +125,8 @@ pub trait BuildHalfEdge { core.layers.geometry.define_curve( half_edge.curve().clone(), - CurveGeom::from_path_and_surface(path, surface), + surface, + LocalCurveGeom { path }, ); core.layers.geometry.define_half_edge( half_edge.clone(), diff --git a/crates/fj-core/src/operations/geometry/curve.rs b/crates/fj-core/src/operations/geometry/curve.rs index 65e9a8eba..2d5577a1a 100644 --- a/crates/fj-core/src/operations/geometry/curve.rs +++ b/crates/fj-core/src/operations/geometry/curve.rs @@ -1,5 +1,5 @@ use crate::{ - geometry::{CurveGeom, Geometry, SurfacePath}, + geometry::{Geometry, LocalCurveGeom, SurfacePath}, layers::Layer, storage::Handle, topology::{Curve, Surface}, @@ -23,10 +23,7 @@ impl UpdateCurveGeometry for Handle { surface: Handle, geometry: &mut Layer, ) -> Self { - geometry.define_curve( - self.clone(), - CurveGeom::from_path_and_surface(path, surface), - ); + geometry.define_curve(self.clone(), surface, LocalCurveGeom { path }); self } From 99cb0240e82d87cc16e4626f9b53b9d97cde3479 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 29 Apr 2024 13:50:04 +0200 Subject: [PATCH 3/3] Remove unused constructor --- crates/fj-core/src/geometry/curve.rs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/crates/fj-core/src/geometry/curve.rs b/crates/fj-core/src/geometry/curve.rs index 8563a0f35..6944a7c4f 100644 --- a/crates/fj-core/src/geometry/curve.rs +++ b/crates/fj-core/src/geometry/curve.rs @@ -27,19 +27,6 @@ pub struct CurveGeom { pub definitions: BTreeMap, LocalCurveGeom>, } -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 { - let mut definitions = BTreeMap::new(); - definitions.insert(surface, LocalCurveGeom { path }); - - Self { definitions } - } -} - /// The geometric definition of a curve in 2D surface coordinates #[derive(Clone)] pub struct LocalCurveGeom {