From 0102aae831073515ca41084cf91c5f4565bb84bf Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 11:35:23 +0100 Subject: [PATCH 01/37] Add accessors for `PartialCurve` fields --- .../fj-kernel/src/algorithms/transform/curve.rs | 6 +++--- crates/fj-kernel/src/partial/maybe_partial.rs | 4 +--- crates/fj-kernel/src/partial/objects/curve.rs | 17 +++++++++++++++++ crates/fj-kernel/src/partial/objects/edge.rs | 2 +- crates/fj-kernel/src/partial/objects/vertex.rs | 4 ++-- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/curve.rs b/crates/fj-kernel/src/algorithms/transform/curve.rs index 68fcb24ca..9ef9df0c6 100644 --- a/crates/fj-kernel/src/algorithms/transform/curve.rs +++ b/crates/fj-kernel/src/algorithms/transform/curve.rs @@ -34,12 +34,12 @@ impl TransformObject for PartialCurve { objects: &Objects, ) -> Result { let surface = self - .surface + .surface() .map(|surface| surface.transform(transform, objects)) .transpose()?; let global_form = self - .global_form - .map(|global_form| global_form.0.transform(transform, objects)) + .global_form() + .map(|global_form| global_form.transform(transform, objects)) .transpose()?; // Don't need to transform `self.path`, as that's defined in surface diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index 71406b779..bef29ad48 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -99,9 +99,7 @@ impl MaybePartial { pub fn global_form(&self) -> Option> { match self { Self::Full(full) => Some(full.global_form().clone()), - Self::Partial(partial) => { - partial.global_form.clone().map(Into::into) - } + Self::Partial(partial) => partial.global_form(), } } } diff --git a/crates/fj-kernel/src/partial/objects/curve.rs b/crates/fj-kernel/src/partial/objects/curve.rs index b0d0a2343..72e141346 100644 --- a/crates/fj-kernel/src/partial/objects/curve.rs +++ b/crates/fj-kernel/src/partial/objects/curve.rs @@ -30,6 +30,23 @@ pub struct PartialCurve { } impl PartialCurve { + /// Access the path that defines the [`Curve`] + pub fn path(&self) -> Option { + self.path + } + + /// Access the surface that the [`Curve`] is defined in + pub fn surface(&self) -> Option> { + self.surface.clone() + } + + /// Access the global form of the [`Curve`] + pub fn global_form(&self) -> Option> { + self.global_form + .clone() + .map(|handle_wrapper| handle_wrapper.0) + } + /// Provide a path for the partial curve pub fn with_path(mut self, path: Option) -> Self { if let Some(path) = path { diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 5faf78ef3..898ce3df6 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -131,7 +131,7 @@ impl PartialHalfEdge { .with_surface(self.surface.clone()) .as_circle_from_radius(radius); - let path = curve.path.expect("Expected path that was just created"); + let path = curve.path().expect("Expected path that was just created"); let [a_curve, b_curve] = [Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord])); diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 75cd15a4a..d6e735eda 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -249,10 +249,10 @@ impl PartialGlobalVertex { ) -> Self { let curve = curve.into().into_partial(); - let path = curve.path.expect( + let path = curve.path().expect( "Need path to create `GlobalVertex` from curve and position", ); - let surface = curve.surface.expect( + let surface = curve.surface().expect( "Need surface to create `GlobalVertex` from curve and position", ); From 5d043a8bad077e8f6f6765850e8e22f6d0e9ed15 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 11:40:20 +0100 Subject: [PATCH 02/37] Make `PartialCurve` fields private --- .../src/algorithms/transform/curve.rs | 9 ++++----- crates/fj-kernel/src/partial/objects/curve.rs | 18 +++--------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/curve.rs b/crates/fj-kernel/src/algorithms/transform/curve.rs index 9ef9df0c6..9ee9497fa 100644 --- a/crates/fj-kernel/src/algorithms/transform/curve.rs +++ b/crates/fj-kernel/src/algorithms/transform/curve.rs @@ -44,10 +44,9 @@ impl TransformObject for PartialCurve { // Don't need to transform `self.path`, as that's defined in surface // coordinates, and thus transforming `surface` takes care of it. - Ok(Self { - surface, - path: self.path, - global_form: global_form.map(Into::into), - }) + Ok(Self::default() + .with_surface(surface) + .with_path(self.path()) + .with_global_form(global_form)) } } diff --git a/crates/fj-kernel/src/partial/objects/curve.rs b/crates/fj-kernel/src/partial/objects/curve.rs index 72e141346..28cc743be 100644 --- a/crates/fj-kernel/src/partial/objects/curve.rs +++ b/crates/fj-kernel/src/partial/objects/curve.rs @@ -12,21 +12,9 @@ use crate::{ /// See [`crate::partial`] for more information. #[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct PartialCurve { - /// The path that defines the [`Curve`] - /// - /// Must be provided before calling [`PartialCurve::build`]. - pub path: Option, - - /// The surface that the [`Curve`] is defined in - /// - /// Must be provided before calling [`PartialCurve::build`]. - pub surface: Option>, - - /// The global form of the [`Curve`] - /// - /// Will be computed from `path` and `surface` in [`PartialCurve::build`], - /// if not provided. - pub global_form: Option>, + path: Option, + surface: Option>, + global_form: Option>, } impl PartialCurve { From 3d7ea29b48154c3de6675467e3e299caf2c9279f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 12:06:23 +0100 Subject: [PATCH 03/37] Add accessor for `PartialGlobalVertex` field --- crates/fj-kernel/src/algorithms/transform/vertex.rs | 2 +- crates/fj-kernel/src/partial/objects/vertex.rs | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index 32e11f798..62868e8c1 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -60,7 +60,7 @@ impl TransformObject for PartialGlobalVertex { _: &Objects, ) -> Result { let position = self - .position + .position() .map(|position| transform.transform_point(&position)); Ok(Self { position }) diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index d6e735eda..9dce2017f 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -230,6 +230,11 @@ pub struct PartialGlobalVertex { } impl PartialGlobalVertex { + /// Access the position of the [`GlobalVertex`] + pub fn position(&self) -> Option> { + self.position + } + /// Provide a position for the partial global vertex pub fn with_position( mut self, From ab487e7494e3f99ef7806fb026cf84f074e6a494 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 12:06:40 +0100 Subject: [PATCH 04/37] Make field of `PartialGlobalVertex` private --- crates/fj-kernel/src/algorithms/transform/vertex.rs | 2 +- crates/fj-kernel/src/partial/objects/vertex.rs | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index 62868e8c1..46e12123a 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -63,6 +63,6 @@ impl TransformObject for PartialGlobalVertex { .position() .map(|position| transform.transform_point(&position)); - Ok(Self { position }) + Ok(Self::default().with_position(position)) } } diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 9dce2017f..367cbe084 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -223,10 +223,7 @@ impl From<&SurfaceVertex> for PartialSurfaceVertex { /// See [`crate::partial`] for more information. #[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct PartialGlobalVertex { - /// The position of the [`GlobalVertex`] - /// - /// Must be provided before [`PartialGlobalVertex::build`] is called. - pub position: Option>, + position: Option>, } impl PartialGlobalVertex { From 8286f9b24fe9188d239dec153dbc23f5b1d6b392 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 12:19:22 +0100 Subject: [PATCH 05/37] Extract builder methods from `PartialCurve` --- .../fj-kernel/src/algorithms/approx/curve.rs | 1 + .../src/algorithms/intersect/curve_edge.rs | 1 + .../src/algorithms/intersect/curve_face.rs | 1 + .../src/algorithms/intersect/face_face.rs | 1 + .../algorithms/intersect/surface_surface.rs | 1 + .../fj-kernel/src/algorithms/sweep/vertex.rs | 1 + crates/fj-kernel/src/builder/curve.rs | 43 +++++++++++++++++++ crates/fj-kernel/src/builder/mod.rs | 10 ++++- crates/fj-kernel/src/iter.rs | 1 + crates/fj-kernel/src/partial/objects/curve.rs | 28 ------------ crates/fj-kernel/src/partial/objects/cycle.rs | 1 + crates/fj-kernel/src/partial/objects/edge.rs | 1 + crates/fj-kernel/src/validate/vertex.rs | 1 + 13 files changed, 61 insertions(+), 30 deletions(-) create mode 100644 crates/fj-kernel/src/builder/curve.rs diff --git a/crates/fj-kernel/src/algorithms/approx/curve.rs b/crates/fj-kernel/src/algorithms/approx/curve.rs index 2e26e9d2b..0395303e2 100644 --- a/crates/fj-kernel/src/algorithms/approx/curve.rs +++ b/crates/fj-kernel/src/algorithms/approx/curve.rs @@ -197,6 +197,7 @@ mod tests { use crate::{ algorithms::approx::{path::RangeOnPath, Approx, ApproxPoint}, + builder::CurveBuilder, objects::{Curve, Objects, Surface}, partial::HasPartial, path::GlobalPath, diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs index c91425878..734d735dc 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs @@ -75,6 +75,7 @@ mod tests { use fj_math::Point; use crate::{ + builder::CurveBuilder, objects::{Curve, HalfEdge, Objects}, partial::HasPartial, }; diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index a293fc2d5..98caff254 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -150,6 +150,7 @@ where #[cfg(test)] mod tests { use crate::{ + builder::CurveBuilder, objects::{Curve, Face, Objects}, partial::HasPartial, }; diff --git a/crates/fj-kernel/src/algorithms/intersect/face_face.rs b/crates/fj-kernel/src/algorithms/intersect/face_face.rs index 455db524b..d92c799a2 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_face.rs @@ -67,6 +67,7 @@ mod tests { use crate::{ algorithms::intersect::CurveFaceIntersection, + builder::CurveBuilder, objects::{Curve, Face, Objects}, partial::HasPartial, }; diff --git a/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs b/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs index d69090a9f..3c5342b84 100644 --- a/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs +++ b/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs @@ -92,6 +92,7 @@ mod tests { use crate::{ algorithms::transform::TransformObject, + builder::CurveBuilder, objects::{Curve, Objects}, partial::HasPartial, }; diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index dcb71f14b..c7db751fe 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -168,6 +168,7 @@ mod tests { use crate::{ algorithms::sweep::Sweep, + builder::CurveBuilder, objects::{Curve, HalfEdge, Objects, Vertex}, partial::HasPartial, }; diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs new file mode 100644 index 000000000..f363f0b78 --- /dev/null +++ b/crates/fj-kernel/src/builder/curve.rs @@ -0,0 +1,43 @@ +use fj_math::{Point, Scalar, Vector}; + +use crate::{partial::PartialCurve, path::SurfacePath}; + +/// Builder API for [`PartialCurve`] +#[allow(clippy::wrong_self_convention)] +pub trait CurveBuilder { + /// Update partial curve to represent the u-axis + fn as_u_axis(self) -> Self; + + /// Update partial curve to represent the v-axis + fn as_v_axis(self) -> Self; + + /// Update partial curve as a circle, from the provided radius + fn as_circle_from_radius(self, radius: impl Into) -> Self; + + /// Update partial curve as a line, from the provided points + fn as_line_from_points(self, points: [impl Into>; 2]) -> Self; +} + +impl CurveBuilder for PartialCurve { + fn as_u_axis(self) -> Self { + let a = Point::origin(); + let b = a + Vector::unit_u(); + + self.as_line_from_points([a, b]) + } + + fn as_v_axis(self) -> Self { + let a = Point::origin(); + let b = a + Vector::unit_v(); + + self.as_line_from_points([a, b]) + } + + fn as_circle_from_radius(self, radius: impl Into) -> Self { + self.with_path(Some(SurfacePath::circle_from_radius(radius))) + } + + fn as_line_from_points(self, points: [impl Into>; 2]) -> Self { + self.with_path(Some(SurfacePath::line_from_points(points))) + } +} diff --git a/crates/fj-kernel/src/builder/mod.rs b/crates/fj-kernel/src/builder/mod.rs index 70b8e6fcf..6c7c080b3 100644 --- a/crates/fj-kernel/src/builder/mod.rs +++ b/crates/fj-kernel/src/builder/mod.rs @@ -1,11 +1,17 @@ //! API for building objects +// These are the old-style builders that need to be transferred to the partial +// object API. Issue: +// https://github.com/hannobraun/Fornjot/issues/1147 mod face; mod shell; mod sketch; mod solid; +// These are new-style builders that build on top of the partial object API. +mod curve; + pub use self::{ - face::FaceBuilder, shell::ShellBuilder, sketch::SketchBuilder, - solid::SolidBuilder, + curve::CurveBuilder, face::FaceBuilder, shell::ShellBuilder, + sketch::SketchBuilder, solid::SolidBuilder, }; diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index 43b34f558..210e0d773 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -360,6 +360,7 @@ impl Iterator for Iter { #[cfg(test)] mod tests { use crate::{ + builder::CurveBuilder, objects::{ Curve, Cycle, Face, GlobalCurve, GlobalVertex, HalfEdge, Objects, Shell, Sketch, Solid, SurfaceVertex, Vertex, diff --git a/crates/fj-kernel/src/partial/objects/curve.rs b/crates/fj-kernel/src/partial/objects/curve.rs index 28cc743be..489b9ab58 100644 --- a/crates/fj-kernel/src/partial/objects/curve.rs +++ b/crates/fj-kernel/src/partial/objects/curve.rs @@ -1,5 +1,3 @@ -use fj_math::{Point, Scalar, Vector}; - use crate::{ objects::{Curve, GlobalCurve, Objects, Surface}, path::SurfacePath, @@ -62,32 +60,6 @@ impl PartialCurve { self } - /// Update partial curve to represent the u-axis - pub fn as_u_axis(self) -> Self { - let a = Point::origin(); - let b = a + Vector::unit_u(); - - self.as_line_from_points([a, b]) - } - - /// Update partial curve to represent the v-axis - pub fn as_v_axis(self) -> Self { - let a = Point::origin(); - let b = a + Vector::unit_v(); - - self.as_line_from_points([a, b]) - } - - /// Update partial curve as a circle, from the provided radius - pub fn as_circle_from_radius(self, radius: impl Into) -> Self { - self.with_path(Some(SurfacePath::circle_from_radius(radius))) - } - - /// Update partial curve as a line, from the provided points - pub fn as_line_from_points(self, points: [impl Into>; 2]) -> Self { - self.with_path(Some(SurfacePath::line_from_points(points))) - } - /// Build a full [`Curve`] from the partial curve pub fn build( self, diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index e96be1939..88137d501 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -1,6 +1,7 @@ use fj_math::Point; use crate::{ + builder::CurveBuilder, objects::{ Curve, Cycle, HalfEdge, Objects, Surface, SurfaceVertex, Vertex, }, diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 898ce3df6..f61b86d2d 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -2,6 +2,7 @@ use fj_interop::ext::ArrayExt; use fj_math::{Point, Scalar}; use crate::{ + builder::CurveBuilder, objects::{ Curve, GlobalCurve, GlobalEdge, GlobalVertex, HalfEdge, Objects, Surface, SurfaceVertex, Vertex, VerticesInNormalizedOrder, diff --git a/crates/fj-kernel/src/validate/vertex.rs b/crates/fj-kernel/src/validate/vertex.rs index 790c88aba..c65269560 100644 --- a/crates/fj-kernel/src/validate/vertex.rs +++ b/crates/fj-kernel/src/validate/vertex.rs @@ -179,6 +179,7 @@ impl SurfaceVertexValidationError { #[cfg(test)] mod tests { use crate::{ + builder::CurveBuilder, objects::{Curve, GlobalVertex, Objects, SurfaceVertex, Vertex}, partial::HasPartial, validate::Validate2, From 5fbce144e60be23985ee2cc1772f204134fc198a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 12:33:57 +0100 Subject: [PATCH 06/37] Improve method name --- crates/fj-kernel/src/algorithms/intersect/curve_edge.rs | 8 ++++---- .../fj-kernel/src/algorithms/intersect/surface_surface.rs | 4 ++-- crates/fj-kernel/src/algorithms/sweep/vertex.rs | 2 +- crates/fj-kernel/src/builder/curve.rs | 4 ++-- crates/fj-kernel/src/iter.rs | 4 ++-- crates/fj-kernel/src/validate/vertex.rs | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs index 734d735dc..55486f2ee 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs @@ -89,7 +89,7 @@ mod tests { let surface = objects.surfaces.xy_plane(); let curve = Curve::partial() .with_surface(Some(surface.clone())) - .as_u_axis() + .update_as_u_axis() .build(&objects)?; let half_edge = HalfEdge::partial() .with_surface(Some(surface)) @@ -114,7 +114,7 @@ mod tests { let surface = objects.surfaces.xy_plane(); let curve = Curve::partial() .with_surface(Some(surface.clone())) - .as_u_axis() + .update_as_u_axis() .build(&objects)?; let half_edge = HalfEdge::partial() .with_surface(Some(surface)) @@ -139,7 +139,7 @@ mod tests { let surface = objects.surfaces.xy_plane(); let curve = Curve::partial() .with_surface(Some(surface.clone())) - .as_u_axis() + .update_as_u_axis() .build(&objects)?; let half_edge = HalfEdge::partial() .with_surface(Some(surface)) @@ -159,7 +159,7 @@ mod tests { let surface = objects.surfaces.xy_plane(); let curve = Curve::partial() .with_surface(Some(surface.clone())) - .as_u_axis() + .update_as_u_axis() .build(&objects)?; let half_edge = HalfEdge::partial() .with_surface(Some(surface)) diff --git a/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs b/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs index 3c5342b84..869e7cc4a 100644 --- a/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs +++ b/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs @@ -123,11 +123,11 @@ mod tests { let expected_xy = Curve::partial() .with_surface(Some(xy.clone())) - .as_u_axis() + .update_as_u_axis() .build(&objects)?; let expected_xz = Curve::partial() .with_surface(Some(xz.clone())) - .as_u_axis() + .update_as_u_axis() .build(&objects)?; assert_eq!( diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index c7db751fe..8b55c5d46 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -180,7 +180,7 @@ mod tests { let surface = objects.surfaces.xz_plane(); let curve = Curve::partial() .with_surface(Some(surface.clone())) - .as_u_axis() + .update_as_u_axis() .build(&objects)?; let vertex = Vertex::partial() .with_position(Some([0.])) diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index f363f0b78..99395d9c5 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -6,7 +6,7 @@ use crate::{partial::PartialCurve, path::SurfacePath}; #[allow(clippy::wrong_self_convention)] pub trait CurveBuilder { /// Update partial curve to represent the u-axis - fn as_u_axis(self) -> Self; + fn update_as_u_axis(self) -> Self; /// Update partial curve to represent the v-axis fn as_v_axis(self) -> Self; @@ -19,7 +19,7 @@ pub trait CurveBuilder { } impl CurveBuilder for PartialCurve { - fn as_u_axis(self) -> Self { + fn update_as_u_axis(self) -> Self { let a = Point::origin(); let b = a + Vector::unit_u(); diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index 210e0d773..2538869c6 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -377,7 +377,7 @@ mod tests { let surface = objects.surfaces.xy_plane(); let object = Curve::partial() .with_surface(Some(surface)) - .as_u_axis() + .update_as_u_axis() .build(&objects); assert_eq!(1, object.curve_iter().count()); @@ -594,7 +594,7 @@ mod tests { let surface = objects.surfaces.xy_plane(); let curve = Curve::partial() .with_surface(Some(surface.clone())) - .as_u_axis() + .update_as_u_axis() .build(&objects)?; let global_vertex = objects .global_vertices diff --git a/crates/fj-kernel/src/validate/vertex.rs b/crates/fj-kernel/src/validate/vertex.rs index c65269560..46be55a1b 100644 --- a/crates/fj-kernel/src/validate/vertex.rs +++ b/crates/fj-kernel/src/validate/vertex.rs @@ -194,7 +194,7 @@ mod tests { .with_curve(Some( Curve::partial() .with_surface(Some(objects.surfaces.xy_plane())) - .as_u_axis(), + .update_as_u_axis(), )) .build(&objects)?; let invalid = Vertex::new( @@ -222,7 +222,7 @@ mod tests { .with_curve(Some( Curve::partial() .with_surface(Some(objects.surfaces.xy_plane())) - .as_u_axis(), + .update_as_u_axis(), )) .build(&objects)?; let invalid = Vertex::new( From 42ebe33091c2db417c60e24bc2a03ae107afffbe Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 12:34:26 +0100 Subject: [PATCH 07/37] Improve method name --- crates/fj-kernel/src/builder/curve.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index 99395d9c5..8effa2ff5 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -9,7 +9,7 @@ pub trait CurveBuilder { fn update_as_u_axis(self) -> Self; /// Update partial curve to represent the v-axis - fn as_v_axis(self) -> Self; + fn update_as_v_axis(self) -> Self; /// Update partial curve as a circle, from the provided radius fn as_circle_from_radius(self, radius: impl Into) -> Self; @@ -26,7 +26,7 @@ impl CurveBuilder for PartialCurve { self.as_line_from_points([a, b]) } - fn as_v_axis(self) -> Self { + fn update_as_v_axis(self) -> Self { let a = Point::origin(); let b = a + Vector::unit_v(); From 604590c69ab92c2b4c2d59364c4b7162a5eac1c4 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 12:34:41 +0100 Subject: [PATCH 08/37] Improve method name --- crates/fj-kernel/src/algorithms/approx/curve.rs | 2 +- crates/fj-kernel/src/builder/curve.rs | 4 ++-- crates/fj-kernel/src/partial/objects/edge.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/curve.rs b/crates/fj-kernel/src/algorithms/approx/curve.rs index 0395303e2..62b16f196 100644 --- a/crates/fj-kernel/src/algorithms/approx/curve.rs +++ b/crates/fj-kernel/src/algorithms/approx/curve.rs @@ -286,7 +286,7 @@ mod tests { .insert(Surface::new(GlobalPath::x_axis(), [0., 0., 1.]))?; let curve = Curve::partial() .with_surface(Some(surface)) - .as_circle_from_radius(1.) + .update_as_circle_from_radius(1.) .build(&objects)?; let range = RangeOnPath::from([[0.], [TAU]]); diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index 8effa2ff5..c2513a18f 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -12,7 +12,7 @@ pub trait CurveBuilder { fn update_as_v_axis(self) -> Self; /// Update partial curve as a circle, from the provided radius - fn as_circle_from_radius(self, radius: impl Into) -> Self; + fn update_as_circle_from_radius(self, radius: impl Into) -> Self; /// Update partial curve as a line, from the provided points fn as_line_from_points(self, points: [impl Into>; 2]) -> Self; @@ -33,7 +33,7 @@ impl CurveBuilder for PartialCurve { self.as_line_from_points([a, b]) } - fn as_circle_from_radius(self, radius: impl Into) -> Self { + fn update_as_circle_from_radius(self, radius: impl Into) -> Self { self.with_path(Some(SurfacePath::circle_from_radius(radius))) } diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index f61b86d2d..515b945ce 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -130,7 +130,7 @@ impl PartialHalfEdge { let curve = Curve::partial() .with_global_form(self.extract_global_curve()) .with_surface(self.surface.clone()) - .as_circle_from_radius(radius); + .update_as_circle_from_radius(radius); let path = curve.path().expect("Expected path that was just created"); From 7a7e186b73ee8106c52143795a0b7db7c6e37676 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 12:35:02 +0100 Subject: [PATCH 09/37] Improve method name --- crates/fj-kernel/src/algorithms/approx/curve.rs | 6 +++--- .../src/algorithms/intersect/curve_face.rs | 2 +- .../src/algorithms/intersect/face_face.rs | 2 +- crates/fj-kernel/src/builder/curve.rs | 14 ++++++++++---- crates/fj-kernel/src/partial/objects/cycle.rs | 2 +- crates/fj-kernel/src/partial/objects/edge.rs | 2 +- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/curve.rs b/crates/fj-kernel/src/algorithms/approx/curve.rs index 62b16f196..2f06121a0 100644 --- a/crates/fj-kernel/src/algorithms/approx/curve.rs +++ b/crates/fj-kernel/src/algorithms/approx/curve.rs @@ -214,7 +214,7 @@ mod tests { .insert(Surface::new(GlobalPath::x_axis(), [0., 0., 1.]))?; let curve = Curve::partial() .with_surface(Some(surface)) - .as_line_from_points([[1., 1.], [2., 1.]]) + .update_as_line_from_points([[1., 1.], [2., 1.]]) .build(&objects)?; let range = RangeOnPath::from([[0.], [1.]]); @@ -235,7 +235,7 @@ mod tests { ))?; let curve = Curve::partial() .with_surface(Some(surface)) - .as_line_from_points([[1., 1.], [1., 2.]]) + .update_as_line_from_points([[1., 1.], [1., 2.]]) .build(&objects)?; let range = RangeOnPath::from([[0.], [1.]]); @@ -254,7 +254,7 @@ mod tests { objects.surfaces.insert(Surface::new(path, [0., 0., 1.]))?; let curve = Curve::partial() .with_surface(Some(surface.clone())) - .as_line_from_points([[0., 1.], [1., 1.]]) + .update_as_line_from_points([[0., 1.], [1., 1.]]) .build(&objects)?; let range = RangeOnPath::from([[0.], [TAU]]); diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index 98caff254..9ede7f995 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -165,7 +165,7 @@ mod tests { let curve = Curve::partial() .with_surface(Some(surface.clone())) - .as_line_from_points([[-3., 0.], [-2., 0.]]) + .update_as_line_from_points([[-3., 0.], [-2., 0.]]) .build(&objects)?; #[rustfmt::skip] diff --git a/crates/fj-kernel/src/algorithms/intersect/face_face.rs b/crates/fj-kernel/src/algorithms/intersect/face_face.rs index d92c799a2..ac9e2776c 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_face.rs @@ -125,7 +125,7 @@ mod tests { let expected_curves = surfaces.try_map_ext(|surface| { Curve::partial() .with_surface(Some(surface)) - .as_line_from_points([[0., 0.], [1., 0.]]) + .update_as_line_from_points([[0., 0.], [1., 0.]]) .build(&objects) })?; let expected_intervals = diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index c2513a18f..4d18d55ae 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -15,7 +15,10 @@ pub trait CurveBuilder { fn update_as_circle_from_radius(self, radius: impl Into) -> Self; /// Update partial curve as a line, from the provided points - fn as_line_from_points(self, points: [impl Into>; 2]) -> Self; + fn update_as_line_from_points( + self, + points: [impl Into>; 2], + ) -> Self; } impl CurveBuilder for PartialCurve { @@ -23,21 +26,24 @@ impl CurveBuilder for PartialCurve { let a = Point::origin(); let b = a + Vector::unit_u(); - self.as_line_from_points([a, b]) + self.update_as_line_from_points([a, b]) } fn update_as_v_axis(self) -> Self { let a = Point::origin(); let b = a + Vector::unit_v(); - self.as_line_from_points([a, b]) + self.update_as_line_from_points([a, b]) } fn update_as_circle_from_radius(self, radius: impl Into) -> Self { self.with_path(Some(SurfacePath::circle_from_radius(radius))) } - fn as_line_from_points(self, points: [impl Into>; 2]) -> Self { + fn update_as_line_from_points( + self, + points: [impl Into>; 2], + ) -> Self { self.with_path(Some(SurfacePath::line_from_points(points))) } } diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index 88137d501..988105eba 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -83,7 +83,7 @@ impl PartialCycle { let curve = Curve::partial() .with_surface(Some(surface.clone())) - .as_line_from_points([position_prev, position_next]); + .update_as_line_from_points([position_prev, position_next]); let [from, to] = [(0., from), (1., to)].map(|(position, surface_form)| { diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 515b945ce..35cf9c943 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -205,7 +205,7 @@ impl PartialHalfEdge { let curve = Curve::partial() .with_global_form(self.extract_global_curve()) .with_surface(Some(surface)) - .as_line_from_points(points); + .update_as_line_from_points(points); let [back, front] = { let vertices = [(from, 0.), (to, 1.)].map(|(vertex, position)| { From dad8544bd0e41e62d90dc0ee6db423a9c1a5c5fa Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 12:35:17 +0100 Subject: [PATCH 10/37] Remove unused attribute --- crates/fj-kernel/src/builder/curve.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index 4d18d55ae..9135009e6 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -3,7 +3,6 @@ use fj_math::{Point, Scalar, Vector}; use crate::{partial::PartialCurve, path::SurfacePath}; /// Builder API for [`PartialCurve`] -#[allow(clippy::wrong_self_convention)] pub trait CurveBuilder { /// Update partial curve to represent the u-axis fn update_as_u_axis(self) -> Self; From 3518ac0a20707cca7acd9274701d8d9b5371c0b0 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 12:38:18 +0100 Subject: [PATCH 11/37] Refactor --- crates/fj-kernel/src/partial/objects/vertex.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 367cbe084..e46c371ec 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -264,12 +264,11 @@ impl PartialGlobalVertex { /// Update partial global vertex from the given surface and position on it pub fn from_surface_and_position( - mut self, + self, surface: &Surface, position: impl Into>, ) -> Self { - self.position = Some(surface.point_from_surface_coords(position)); - self + self.with_position(Some(surface.point_from_surface_coords(position))) } /// Build a full [`GlobalVertex`] from the partial global vertex From ac783852edabd5499bb3134956b4d4e8b78cddd7 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 12:39:51 +0100 Subject: [PATCH 12/37] Extract builder methods from `PartialGlobalVertex` --- crates/fj-kernel/src/builder/mod.rs | 3 +- crates/fj-kernel/src/builder/vertex.rs | 52 +++++++++++++++++++ crates/fj-kernel/src/partial/objects/edge.rs | 2 +- .../fj-kernel/src/partial/objects/vertex.rs | 29 +---------- 4 files changed, 56 insertions(+), 30 deletions(-) create mode 100644 crates/fj-kernel/src/builder/vertex.rs diff --git a/crates/fj-kernel/src/builder/mod.rs b/crates/fj-kernel/src/builder/mod.rs index 6c7c080b3..53e7d85b1 100644 --- a/crates/fj-kernel/src/builder/mod.rs +++ b/crates/fj-kernel/src/builder/mod.rs @@ -10,8 +10,9 @@ mod solid; // These are new-style builders that build on top of the partial object API. mod curve; +mod vertex; pub use self::{ curve::CurveBuilder, face::FaceBuilder, shell::ShellBuilder, - sketch::SketchBuilder, solid::SolidBuilder, + sketch::SketchBuilder, solid::SolidBuilder, vertex::GlobalVertexBuilder, }; diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs new file mode 100644 index 000000000..460a46f2f --- /dev/null +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -0,0 +1,52 @@ +use fj_math::Point; + +use crate::{ + objects::{Curve, Surface}, + partial::{MaybePartial, PartialGlobalVertex}, +}; + +/// Builder API for [`PartialGlobalVertex`] +#[allow(clippy::wrong_self_convention)] +pub trait GlobalVertexBuilder { + /// Update partial global vertex from the given curve and position on it + fn from_curve_and_position( + self, + curve: impl Into>, + position: impl Into>, + ) -> Self; + + /// Update partial global vertex from the given surface and position on it + fn from_surface_and_position( + self, + surface: &Surface, + position: impl Into>, + ) -> Self; +} + +impl GlobalVertexBuilder for PartialGlobalVertex { + fn from_curve_and_position( + self, + curve: impl Into>, + position: impl Into>, + ) -> Self { + let curve = curve.into().into_partial(); + + let path = curve.path().expect( + "Need path to create `GlobalVertex` from curve and position", + ); + let surface = curve.surface().expect( + "Need surface to create `GlobalVertex` from curve and position", + ); + + let position_surface = path.point_from_path_coords(position); + self.from_surface_and_position(&surface, position_surface) + } + + fn from_surface_and_position( + self, + surface: &Surface, + position: impl Into>, + ) -> Self { + self.with_position(Some(surface.point_from_surface_coords(position))) + } +} diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 35cf9c943..70d6e6e3a 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -2,7 +2,7 @@ use fj_interop::ext::ArrayExt; use fj_math::{Point, Scalar}; use crate::{ - builder::CurveBuilder, + builder::{CurveBuilder, GlobalVertexBuilder}, objects::{ Curve, GlobalCurve, GlobalEdge, GlobalVertex, HalfEdge, Objects, Surface, SurfaceVertex, Vertex, VerticesInNormalizedOrder, diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index e46c371ec..59180bcd7 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -1,6 +1,7 @@ use fj_math::Point; use crate::{ + builder::GlobalVertexBuilder, objects::{Curve, GlobalVertex, Objects, Surface, SurfaceVertex, Vertex}, partial::{HasPartial, MaybePartial}, storage::Handle, @@ -243,34 +244,6 @@ impl PartialGlobalVertex { self } - /// Update partial global vertex from the given curve and position on it - pub fn from_curve_and_position( - self, - curve: impl Into>, - position: impl Into>, - ) -> Self { - let curve = curve.into().into_partial(); - - let path = curve.path().expect( - "Need path to create `GlobalVertex` from curve and position", - ); - let surface = curve.surface().expect( - "Need surface to create `GlobalVertex` from curve and position", - ); - - let position_surface = path.point_from_path_coords(position); - self.from_surface_and_position(&surface, position_surface) - } - - /// Update partial global vertex from the given surface and position on it - pub fn from_surface_and_position( - self, - surface: &Surface, - position: impl Into>, - ) -> Self { - self.with_position(Some(surface.point_from_surface_coords(position))) - } - /// Build a full [`GlobalVertex`] from the partial global vertex pub fn build( self, From 8b0265d8961c0fc3877b9512065142350018b0af Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 12:40:20 +0100 Subject: [PATCH 13/37] Improve method name --- crates/fj-kernel/src/builder/vertex.rs | 4 ++-- crates/fj-kernel/src/partial/objects/edge.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 460a46f2f..941f65051 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -9,7 +9,7 @@ use crate::{ #[allow(clippy::wrong_self_convention)] pub trait GlobalVertexBuilder { /// Update partial global vertex from the given curve and position on it - fn from_curve_and_position( + fn update_from_curve_and_position( self, curve: impl Into>, position: impl Into>, @@ -24,7 +24,7 @@ pub trait GlobalVertexBuilder { } impl GlobalVertexBuilder for PartialGlobalVertex { - fn from_curve_and_position( + fn update_from_curve_and_position( self, curve: impl Into>, position: impl Into>, diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 70d6e6e3a..7e8f8aaa9 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -142,7 +142,7 @@ impl PartialHalfEdge { .map(|[global_form, _]| global_form) .unwrap_or_else(|| { GlobalVertex::partial() - .from_curve_and_position(curve.clone(), a_curve) + .update_from_curve_and_position(curve.clone(), a_curve) .into() }); From cca99566d7f3f9bb434694af85b1acbcdc5dd78c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 12:40:36 +0100 Subject: [PATCH 14/37] Improve method name --- crates/fj-kernel/src/builder/vertex.rs | 6 +++--- crates/fj-kernel/src/partial/objects/vertex.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 941f65051..b43625a43 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -16,7 +16,7 @@ pub trait GlobalVertexBuilder { ) -> Self; /// Update partial global vertex from the given surface and position on it - fn from_surface_and_position( + fn update_from_surface_and_position( self, surface: &Surface, position: impl Into>, @@ -39,10 +39,10 @@ impl GlobalVertexBuilder for PartialGlobalVertex { ); let position_surface = path.point_from_path_coords(position); - self.from_surface_and_position(&surface, position_surface) + self.update_from_surface_and_position(&surface, position_surface) } - fn from_surface_and_position( + fn update_from_surface_and_position( self, surface: &Surface, position: impl Into>, diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 59180bcd7..88542bfe4 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -197,7 +197,7 @@ impl PartialSurfaceVertex { let global_form = self .global_form .update_partial(|global_form| { - global_form.from_surface_and_position(&surface, position) + global_form.update_from_surface_and_position(&surface, position) }) .into_full(objects)?; From e83691eaffc1da47dfac76de9fa52781dcdd8028 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 12:41:04 +0100 Subject: [PATCH 15/37] Remove unused attribute --- crates/fj-kernel/src/builder/vertex.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index b43625a43..ef5e4a640 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -6,7 +6,6 @@ use crate::{ }; /// Builder API for [`PartialGlobalVertex`] -#[allow(clippy::wrong_self_convention)] pub trait GlobalVertexBuilder { /// Update partial global vertex from the given curve and position on it fn update_from_curve_and_position( From 9e9e0eb784d9597b1cc27b0c70a2ec5372496cca Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 12:47:51 +0100 Subject: [PATCH 16/37] Simplify return value --- crates/fj-kernel/src/partial/maybe_partial.rs | 6 +++--- crates/fj-kernel/src/partial/objects/edge.rs | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index bef29ad48..828132bc1 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -157,10 +157,10 @@ impl MaybePartial { } /// Access the surface - pub fn surface(&self) -> Option<&Handle> { + pub fn surface(&self) -> Option> { match self { - Self::Full(full) => Some(full.surface()), - Self::Partial(partial) => partial.surface.as_ref(), + Self::Full(full) => Some(full.surface().clone()), + Self::Partial(partial) => partial.surface.clone(), } } } diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 7e8f8aaa9..5314302dc 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -191,11 +191,10 @@ impl PartialHalfEdge { let surface = self .surface - .as_ref() + .clone() .or_else(|| from_surface.surface()) .or_else(|| to_surface.surface()) - .expect("Can't infer line segment without a surface") - .clone(); + .expect("Can't infer line segment without a surface"); let points = [&from_surface, &to_surface].map(|vertex| { vertex .position() From b2085a4497eec72752902cae7af04a97d7edbe83 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 12:48:49 +0100 Subject: [PATCH 17/37] Add accessors for `PartialSurfaceVertex` fields --- .../fj-kernel/src/algorithms/transform/vertex.rs | 6 +++--- crates/fj-kernel/src/partial/maybe_partial.rs | 4 ++-- crates/fj-kernel/src/partial/objects/vertex.rs | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index 46e12123a..79f6c8272 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -38,15 +38,15 @@ impl TransformObject for PartialSurfaceVertex { objects: &Objects, ) -> Result { let surface = self - .surface + .surface() .map(|surface| surface.transform(transform, objects)) .transpose()?; - let global_form = self.global_form.transform(transform, objects)?; + let global_form = self.global_form().transform(transform, objects)?; // Don't need to transform `self.position`, as that is in surface // coordinates and thus transforming the surface takes care of it. Ok(Self { - position: self.position, + position: self.position(), surface, global_form, }) diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index 828132bc1..f40b21aec 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -152,7 +152,7 @@ impl MaybePartial { pub fn position(&self) -> Option> { match self { Self::Full(full) => Some(full.position()), - Self::Partial(partial) => partial.position, + Self::Partial(partial) => partial.position(), } } @@ -160,7 +160,7 @@ impl MaybePartial { pub fn surface(&self) -> Option> { match self { Self::Full(full) => Some(full.surface().clone()), - Self::Partial(partial) => partial.surface.clone(), + Self::Partial(partial) => partial.surface(), } } } diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 88542bfe4..2fc7d8c90 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -140,6 +140,21 @@ pub struct PartialSurfaceVertex { } impl PartialSurfaceVertex { + /// Access the position of the [`SurfaceVertex`] + pub fn position(&self) -> Option> { + self.position + } + + /// Access the surface that the [`SurfaceVertex`] is defined in + pub fn surface(&self) -> Option> { + self.surface.clone() + } + + /// Access the global form of the [`SurfaceVertex`] + pub fn global_form(&self) -> MaybePartial { + self.global_form.clone() + } + /// Provide a position for the partial surface vertex pub fn with_position( mut self, From d8844c49e9fd1cf6a67313d449f9f2eaa38b0443 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 12:49:43 +0100 Subject: [PATCH 18/37] Make fields of `PartialSurfaceVertex` private --- .../src/algorithms/transform/vertex.rs | 9 ++++----- crates/fj-kernel/src/partial/objects/vertex.rs | 18 +++--------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index 79f6c8272..92d4434e7 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -45,11 +45,10 @@ impl TransformObject for PartialSurfaceVertex { // Don't need to transform `self.position`, as that is in surface // coordinates and thus transforming the surface takes care of it. - Ok(Self { - position: self.position(), - surface, - global_form, - }) + Ok(Self::default() + .with_position(self.position()) + .with_surface(surface) + .with_global_form(Some(global_form))) } } diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 2fc7d8c90..c3f0d737d 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -122,21 +122,9 @@ impl From<&Vertex> for PartialVertex { /// See [`crate::partial`] for more information. #[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct PartialSurfaceVertex { - /// The position of the [`SurfaceVertex`] in the [`Surface`] - /// - /// Must be provided before [`PartialSurfaceVertex::build`] is called. - pub position: Option>, - - /// The surface that the [`SurfaceVertex`] is defined in - /// - /// Must be provided before [`PartialSurfaceVertex::build`] is called. - pub surface: Option>, - - /// The global form of the [`SurfaceVertex`] - /// - /// Can be provided, if already available, or computed from the position on - /// the [`Surface`]. - pub global_form: MaybePartial, + position: Option>, + surface: Option>, + global_form: MaybePartial, } impl PartialSurfaceVertex { From 27b4253d7207c619587e79256b4699f9e83d7bf1 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 13:15:23 +0100 Subject: [PATCH 19/37] Refactor --- crates/fj-kernel/src/partial/objects/vertex.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index c3f0d737d..7421a2895 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -174,9 +174,8 @@ impl PartialSurfaceVertex { } /// Remove the global form of the partial vertex, inferring it on build - pub fn infer_global_form(mut self) -> Self { - self.global_form = GlobalVertex::partial().into(); - self + pub fn infer_global_form(self) -> Self { + self.with_global_form(Some(GlobalVertex::partial())) } /// Build a full [`SurfaceVertex`] from the partial surface vertex From 627c9dbc59002e5f6aa9a38f2ffab12099d7fdb9 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 13:16:58 +0100 Subject: [PATCH 20/37] Extract builder API from `PartialSurfaceVertex` --- crates/fj-kernel/src/builder/mod.rs | 8 ++++++-- crates/fj-kernel/src/builder/vertex.rs | 18 ++++++++++++++++-- crates/fj-kernel/src/partial/objects/vertex.rs | 5 ----- crates/fj-kernel/src/validate/vertex.rs | 2 +- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/crates/fj-kernel/src/builder/mod.rs b/crates/fj-kernel/src/builder/mod.rs index 53e7d85b1..eaca1bcfe 100644 --- a/crates/fj-kernel/src/builder/mod.rs +++ b/crates/fj-kernel/src/builder/mod.rs @@ -13,6 +13,10 @@ mod curve; mod vertex; pub use self::{ - curve::CurveBuilder, face::FaceBuilder, shell::ShellBuilder, - sketch::SketchBuilder, solid::SolidBuilder, vertex::GlobalVertexBuilder, + curve::CurveBuilder, + face::FaceBuilder, + shell::ShellBuilder, + sketch::SketchBuilder, + solid::SolidBuilder, + vertex::{GlobalVertexBuilder, SurfaceVertexBuilder}, }; diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index ef5e4a640..4a619647a 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -1,10 +1,24 @@ use fj_math::Point; use crate::{ - objects::{Curve, Surface}, - partial::{MaybePartial, PartialGlobalVertex}, + objects::{Curve, GlobalVertex, Surface}, + partial::{ + HasPartial, MaybePartial, PartialGlobalVertex, PartialSurfaceVertex, + }, }; +/// Builder API for [`PartialSurfaceVertex`] +pub trait SurfaceVertexBuilder { + /// Remove the global form of the partial vertex, inferring it in `build` + fn infer_global_form(self) -> Self; +} + +impl SurfaceVertexBuilder for PartialSurfaceVertex { + fn infer_global_form(self) -> Self { + self.with_global_form(Some(GlobalVertex::partial())) + } +} + /// Builder API for [`PartialGlobalVertex`] pub trait GlobalVertexBuilder { /// Update partial global vertex from the given curve and position on it diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 7421a2895..ecd9a9892 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -173,11 +173,6 @@ impl PartialSurfaceVertex { self } - /// Remove the global form of the partial vertex, inferring it on build - pub fn infer_global_form(self) -> Self { - self.with_global_form(Some(GlobalVertex::partial())) - } - /// Build a full [`SurfaceVertex`] from the partial surface vertex /// /// # Panics diff --git a/crates/fj-kernel/src/validate/vertex.rs b/crates/fj-kernel/src/validate/vertex.rs index 46be55a1b..2257510e0 100644 --- a/crates/fj-kernel/src/validate/vertex.rs +++ b/crates/fj-kernel/src/validate/vertex.rs @@ -179,7 +179,7 @@ impl SurfaceVertexValidationError { #[cfg(test)] mod tests { use crate::{ - builder::CurveBuilder, + builder::{CurveBuilder, SurfaceVertexBuilder}, objects::{Curve, GlobalVertex, Objects, SurfaceVertex, Vertex}, partial::HasPartial, validate::Validate2, From b4d892c2dc5f8d703e147bf0ce002cf649486838 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 13:37:18 +0100 Subject: [PATCH 21/37] Add `MaybePartial::is_full`/`is_partial` --- crates/fj-kernel/src/partial/maybe_partial.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index f40b21aec..e70044a04 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -30,6 +30,24 @@ pub enum MaybePartial { } impl MaybePartial { + /// Indicate whether this is a full object + pub fn is_full(&self) -> bool { + if let Self::Full(_) = self { + return true; + } + + false + } + + /// Indicate whether this is a partial object + pub fn is_partial(&self) -> bool { + if let Self::Partial(_) = self { + return true; + } + + false + } + /// If this is a partial object, update it /// /// This is useful whenever a partial object can infer something about its From 5ddbb8aac856f59ce666bf7bf6481049b2181236 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 13:48:26 +0100 Subject: [PATCH 22/37] Add `PartialGlobalCurve` --- .../src/algorithms/transform/curve.rs | 15 ++++------ crates/fj-kernel/src/partial/mod.rs | 2 +- crates/fj-kernel/src/partial/objects/curve.rs | 28 +++++++++++++++++++ crates/fj-kernel/src/partial/objects/mod.rs | 7 +++-- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/curve.rs b/crates/fj-kernel/src/algorithms/transform/curve.rs index 9ee9497fa..109002f10 100644 --- a/crates/fj-kernel/src/algorithms/transform/curve.rs +++ b/crates/fj-kernel/src/algorithms/transform/curve.rs @@ -1,29 +1,24 @@ use fj_math::Transform; use crate::{ - objects::{GlobalCurve, Objects}, - partial::PartialCurve, - storage::Handle, + objects::Objects, + partial::{PartialCurve, PartialGlobalCurve}, validate::ValidationError, }; use super::TransformObject; -impl TransformObject for Handle { +impl TransformObject for PartialGlobalCurve { fn transform( self, _: &Transform, - objects: &Objects, + _: &Objects, ) -> Result { // `GlobalCurve` doesn't contain any internal geometry. If it did, that // would just be redundant with the geometry of other objects, and this // other geometry is already being transformed by other implementations // of this trait. - // - // All we need to do here is create a new `GlobalCurve` instance, to - // make sure the transformed `GlobalCurve` has a different identity than - // the original one. - Ok(objects.global_curves.insert(GlobalCurve)?) + Ok(self) } } diff --git a/crates/fj-kernel/src/partial/mod.rs b/crates/fj-kernel/src/partial/mod.rs index 87567f44d..87ac53f2d 100644 --- a/crates/fj-kernel/src/partial/mod.rs +++ b/crates/fj-kernel/src/partial/mod.rs @@ -41,7 +41,7 @@ mod traits; pub use self::{ maybe_partial::MaybePartial, objects::{ - curve::PartialCurve, + curve::{PartialCurve, PartialGlobalCurve}, cycle::PartialCycle, edge::{PartialGlobalEdge, PartialHalfEdge}, vertex::{PartialGlobalVertex, PartialSurfaceVertex, PartialVertex}, diff --git a/crates/fj-kernel/src/partial/objects/curve.rs b/crates/fj-kernel/src/partial/objects/curve.rs index 489b9ab58..58f5f97c5 100644 --- a/crates/fj-kernel/src/partial/objects/curve.rs +++ b/crates/fj-kernel/src/partial/objects/curve.rs @@ -89,3 +89,31 @@ impl From<&Curve> for PartialCurve { } } } + +/// A partial [`GlobalCurve`] +/// +/// This struct might seem unnecessary. [`GlobalCurve`] literally has nothing in +/// it. Why would we need to represent a part of nothing? However, having this +/// provides some regularity that helps simplify some things within the partial +/// object and builder APIs. +/// +/// See [`crate::partial`] for more information. +#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Ord, PartialOrd)] +pub struct PartialGlobalCurve; + +impl PartialGlobalCurve { + /// Build a full [`GlobalCurve`] from the partial global curve + pub fn build( + self, + objects: &Objects, + ) -> Result, ValidationError> { + let global_curve = objects.global_curves.insert(GlobalCurve)?; + Ok(global_curve) + } +} + +impl From<&GlobalCurve> for PartialGlobalCurve { + fn from(_: &GlobalCurve) -> Self { + Self + } +} diff --git a/crates/fj-kernel/src/partial/objects/mod.rs b/crates/fj-kernel/src/partial/objects/mod.rs index 19d5ef35a..4032519a7 100644 --- a/crates/fj-kernel/src/partial/objects/mod.rs +++ b/crates/fj-kernel/src/partial/objects/mod.rs @@ -5,7 +5,7 @@ pub mod vertex; use crate::{ objects::{ - Curve, Cycle, GlobalEdge, GlobalVertex, HalfEdge, Objects, + Curve, Cycle, GlobalCurve, GlobalEdge, GlobalVertex, HalfEdge, Objects, SurfaceVertex, Vertex, }, storage::Handle, @@ -13,8 +13,8 @@ use crate::{ use super::{ HasPartial, MaybePartial, Partial, PartialCurve, PartialCycle, - PartialGlobalEdge, PartialGlobalVertex, PartialHalfEdge, - PartialSurfaceVertex, PartialVertex, + PartialGlobalCurve, PartialGlobalEdge, PartialGlobalVertex, + PartialHalfEdge, PartialSurfaceVertex, PartialVertex, }; macro_rules! impl_traits { @@ -49,6 +49,7 @@ macro_rules! impl_traits { impl_traits!( Curve, PartialCurve; Cycle, PartialCycle; + GlobalCurve, PartialGlobalCurve; GlobalEdge, PartialGlobalEdge; GlobalVertex, PartialGlobalVertex; HalfEdge, PartialHalfEdge; From 14d31d7b8c0a1d3671cac79f8cfeb45b61819456 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 14:11:44 +0100 Subject: [PATCH 23/37] Simplify return value --- crates/fj-kernel/src/partial/maybe_partial.rs | 6 +++--- crates/fj-kernel/src/partial/objects/edge.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index e70044a04..41c8e966f 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -124,11 +124,11 @@ impl MaybePartial { impl MaybePartial { /// Access the curve - pub fn curve(&self) -> Option<&Handle> { + pub fn curve(&self) -> Option> { match self { - Self::Full(full) => Some(full.curve()), + Self::Full(full) => Some(full.curve().clone()), Self::Partial(partial) => { - partial.curve.as_ref().map(|wrapper| &wrapper.0) + partial.curve.clone().map(|wrapper| wrapper.0) } } } diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 5314302dc..960be0cb1 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -39,7 +39,7 @@ impl PartialHalfEdge { pub fn extract_global_curve(&self) -> Option> { self.curve .global_form() - .or_else(|| self.global_form.curve().cloned()) + .or_else(|| self.global_form.curve()) } /// Access the vertices of the global form, if available From 71ef34a6f28588eefec43296f683bb25658f6fe3 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 14:16:55 +0100 Subject: [PATCH 24/37] Un-derive various traits from partial objects It will be hard to support them going forward, and they're not used anyway. --- crates/fj-kernel/src/partial/objects/curve.rs | 2 +- crates/fj-kernel/src/partial/objects/cycle.rs | 2 +- crates/fj-kernel/src/partial/objects/edge.rs | 4 ++-- crates/fj-kernel/src/partial/objects/vertex.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/curve.rs b/crates/fj-kernel/src/partial/objects/curve.rs index 58f5f97c5..9438c5511 100644 --- a/crates/fj-kernel/src/partial/objects/curve.rs +++ b/crates/fj-kernel/src/partial/objects/curve.rs @@ -8,7 +8,7 @@ use crate::{ /// A partial [`Curve`] /// /// See [`crate::partial`] for more information. -#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Ord, PartialOrd)] +#[derive(Clone, Debug, Default)] pub struct PartialCurve { path: Option, surface: Option>, diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index 988105eba..65c16f6d4 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -13,7 +13,7 @@ use crate::{ /// A partial [`Cycle`] /// /// See [`crate::partial`] for more information. -#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Ord, PartialOrd)] +#[derive(Clone, Debug, Default)] pub struct PartialCycle { /// The surface that the [`Cycle`] is defined in pub surface: Option>, diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 960be0cb1..22193b525 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -15,7 +15,7 @@ use crate::{ /// A partial [`HalfEdge`] /// /// See [`crate::partial`] for more information. -#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Ord, PartialOrd)] +#[derive(Clone, Debug, Default)] pub struct PartialHalfEdge { /// The surface that the [`HalfEdge`]'s [`Curve`] is defined in pub surface: Option>, @@ -312,7 +312,7 @@ impl From<&HalfEdge> for PartialHalfEdge { /// A partial [`GlobalEdge`] /// /// See [`crate::partial`] for more information. -#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Ord, PartialOrd)] +#[derive(Clone, Debug, Default)] pub struct PartialGlobalEdge { /// The curve that the [`GlobalEdge`] is defined in /// diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index ecd9a9892..13cc81570 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -11,7 +11,7 @@ use crate::{ /// A partial [`Vertex`] /// /// See [`crate::partial`] for more information. -#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Ord, PartialOrd)] +#[derive(Clone, Debug, Default)] pub struct PartialVertex { /// The position of the [`Vertex`] on the [`Curve`] /// From 4a4452a853816bbab2032a0829816ccdd350dcdd Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 14:18:22 +0100 Subject: [PATCH 25/37] Use `MaybePartial` --- .../fj-kernel/src/algorithms/transform/edge.rs | 2 +- crates/fj-kernel/src/partial/maybe_partial.rs | 12 +++++------- crates/fj-kernel/src/partial/objects/curve.rs | 16 ++++++++-------- crates/fj-kernel/src/partial/objects/edge.rs | 18 +++++++++++------- crates/fj-kernel/src/validate/edge.rs | 4 +++- 5 files changed, 28 insertions(+), 24 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index 0a997a3c4..5364d76e6 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -59,7 +59,7 @@ impl TransformObject for PartialGlobalEdge { ) -> Result { let curve = self .curve - .map(|curve| curve.0.transform(transform, objects)) + .map(|curve| curve.transform(transform, objects)) .transpose()?; let vertices = self .vertices diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index 41c8e966f..c1ea59453 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -114,9 +114,9 @@ where impl MaybePartial { /// Access the global form - pub fn global_form(&self) -> Option> { + pub fn global_form(&self) -> Option> { match self { - Self::Full(full) => Some(full.global_form().clone()), + Self::Full(full) => Some(full.global_form().clone().into()), Self::Partial(partial) => partial.global_form(), } } @@ -124,12 +124,10 @@ impl MaybePartial { impl MaybePartial { /// Access the curve - pub fn curve(&self) -> Option> { + pub fn curve(&self) -> Option> { match self { - Self::Full(full) => Some(full.curve().clone()), - Self::Partial(partial) => { - partial.curve.clone().map(|wrapper| wrapper.0) - } + Self::Full(full) => Some(full.curve().clone().into()), + Self::Partial(partial) => partial.curve.clone(), } } diff --git a/crates/fj-kernel/src/partial/objects/curve.rs b/crates/fj-kernel/src/partial/objects/curve.rs index 9438c5511..f55b97924 100644 --- a/crates/fj-kernel/src/partial/objects/curve.rs +++ b/crates/fj-kernel/src/partial/objects/curve.rs @@ -1,7 +1,8 @@ use crate::{ objects::{Curve, GlobalCurve, Objects, Surface}, + partial::MaybePartial, path::SurfacePath, - storage::{Handle, HandleWrapper}, + storage::Handle, validate::ValidationError, }; @@ -12,7 +13,7 @@ use crate::{ pub struct PartialCurve { path: Option, surface: Option>, - global_form: Option>, + global_form: Option>, } impl PartialCurve { @@ -27,10 +28,8 @@ impl PartialCurve { } /// Access the global form of the [`Curve`] - pub fn global_form(&self) -> Option> { - self.global_form - .clone() - .map(|handle_wrapper| handle_wrapper.0) + pub fn global_form(&self) -> Option> { + self.global_form.clone() } /// Provide a path for the partial curve @@ -52,7 +51,7 @@ impl PartialCurve { /// Provide a global form for the partial curve pub fn with_global_form( mut self, - global_form: Option>>, + global_form: Option>>, ) -> Self { if let Some(global_form) = global_form { self.global_form = Some(global_form.into()); @@ -72,7 +71,8 @@ impl PartialCurve { let global_form = match self.global_form { Some(global_form) => global_form, None => objects.global_curves.insert(GlobalCurve)?.into(), - }; + } + .into_full(objects)?; Ok(objects .curves diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 22193b525..130d43129 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -8,7 +8,7 @@ use crate::{ Surface, SurfaceVertex, Vertex, VerticesInNormalizedOrder, }, partial::{HasPartial, MaybePartial}, - storage::{Handle, HandleWrapper}, + storage::Handle, validate::ValidationError, }; @@ -36,7 +36,7 @@ impl PartialHalfEdge { /// Extract the global curve from either the curve or global form /// /// If a global curve is available through both, the curve is preferred. - pub fn extract_global_curve(&self) -> Option> { + pub fn extract_global_curve(&self) -> Option> { self.curve .global_form() .or_else(|| self.global_form.curve()) @@ -317,7 +317,7 @@ pub struct PartialGlobalEdge { /// The curve that the [`GlobalEdge`] is defined in /// /// Must be provided before [`PartialGlobalEdge::build`] is called. - pub curve: Option>, + pub curve: Option>, /// The vertices that bound the [`GlobalEdge`] in the curve /// @@ -327,9 +327,12 @@ pub struct PartialGlobalEdge { impl PartialGlobalEdge { /// Update the partial global edge with the given curve - pub fn with_curve(mut self, curve: Option>) -> Self { + pub fn with_curve( + mut self, + curve: Option>, + ) -> Self { if let Some(curve) = curve { - self.curve = Some(curve.into()); + self.curve = Some(curve); } self } @@ -351,7 +354,7 @@ impl PartialGlobalEdge { curve: &Curve, vertices: &[Handle; 2], ) -> Self { - self.with_curve(Some(curve.global_form().clone())) + self.with_curve(Some(curve.global_form().clone().into())) .with_vertices(Some( vertices.clone().map(|vertex| vertex.global_form().clone()), )) @@ -364,7 +367,8 @@ impl PartialGlobalEdge { ) -> Result, ValidationError> { let curve = self .curve - .expect("Can't build `GlobalEdge` without `GlobalCurve`"); + .expect("Can't build `GlobalEdge` without `GlobalCurve`") + .into_full(objects)?; let vertices = self .vertices .expect("Can't build `GlobalEdge` without vertices") diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index 31779a45b..2258782dd 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -239,7 +239,9 @@ mod tests { valid .global_form() .to_partial() - .with_curve(Some(objects.global_curves.insert(GlobalCurve)?)) + .with_curve(Some( + objects.global_curves.insert(GlobalCurve)?.into(), + )) .build(&objects)?, ); From 11dd6f899a362abfda7031d39dc31a4261e0a5c6 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 14:19:29 +0100 Subject: [PATCH 26/37] Make method more convenient --- crates/fj-kernel/src/partial/objects/edge.rs | 6 +++--- crates/fj-kernel/src/validate/edge.rs | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 130d43129..3b40c4590 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -329,10 +329,10 @@ impl PartialGlobalEdge { /// Update the partial global edge with the given curve pub fn with_curve( mut self, - curve: Option>, + curve: Option>>, ) -> Self { if let Some(curve) = curve { - self.curve = Some(curve); + self.curve = Some(curve.into()); } self } @@ -354,7 +354,7 @@ impl PartialGlobalEdge { curve: &Curve, vertices: &[Handle; 2], ) -> Self { - self.with_curve(Some(curve.global_form().clone().into())) + self.with_curve(Some(curve.global_form().clone())) .with_vertices(Some( vertices.clone().map(|vertex| vertex.global_form().clone()), )) diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index 2258782dd..31779a45b 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -239,9 +239,7 @@ mod tests { valid .global_form() .to_partial() - .with_curve(Some( - objects.global_curves.insert(GlobalCurve)?.into(), - )) + .with_curve(Some(objects.global_curves.insert(GlobalCurve)?)) .build(&objects)?, ); From cd5b9681be90db401f9f783b58c11b167fcc31d3 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 14:21:24 +0100 Subject: [PATCH 27/37] Simplify struct field --- crates/fj-kernel/src/algorithms/transform/edge.rs | 10 ++-------- crates/fj-kernel/src/partial/maybe_partial.rs | 2 +- crates/fj-kernel/src/partial/objects/edge.rs | 11 ++++------- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index 5364d76e6..2d9b3b95f 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -57,10 +57,7 @@ impl TransformObject for PartialGlobalEdge { transform: &Transform, objects: &Objects, ) -> Result { - let curve = self - .curve - .map(|curve| curve.transform(transform, objects)) - .transpose()?; + let curve = self.curve.transform(transform, objects)?; let vertices = self .vertices .map(|vertices| { @@ -70,9 +67,6 @@ impl TransformObject for PartialGlobalEdge { }) .transpose()?; - Ok(Self { - curve: curve.map(Into::into), - vertices, - }) + Ok(Self { curve, vertices }) } } diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index c1ea59453..5a992df2c 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -127,7 +127,7 @@ impl MaybePartial { pub fn curve(&self) -> Option> { match self { Self::Full(full) => Some(full.curve().clone().into()), - Self::Partial(partial) => partial.curve.clone(), + Self::Partial(partial) => Some(partial.curve.clone()), } } diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 3b40c4590..e333eaa61 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -317,7 +317,7 @@ pub struct PartialGlobalEdge { /// The curve that the [`GlobalEdge`] is defined in /// /// Must be provided before [`PartialGlobalEdge::build`] is called. - pub curve: Option>, + pub curve: MaybePartial, /// The vertices that bound the [`GlobalEdge`] in the curve /// @@ -332,7 +332,7 @@ impl PartialGlobalEdge { curve: Option>>, ) -> Self { if let Some(curve) = curve { - self.curve = Some(curve.into()); + self.curve = curve.into(); } self } @@ -365,10 +365,7 @@ impl PartialGlobalEdge { self, objects: &Objects, ) -> Result, ValidationError> { - let curve = self - .curve - .expect("Can't build `GlobalEdge` without `GlobalCurve`") - .into_full(objects)?; + let curve = self.curve.into_full(objects)?; let vertices = self .vertices .expect("Can't build `GlobalEdge` without vertices") @@ -383,7 +380,7 @@ impl PartialGlobalEdge { impl From<&GlobalEdge> for PartialGlobalEdge { fn from(global_edge: &GlobalEdge) -> Self { Self { - curve: Some(global_edge.curve().clone().into()), + curve: global_edge.curve().clone().into(), vertices: Some( global_edge .vertices() From aa4c3ca80e1d050c1fd9a3bb367031d4c1cd9597 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 14:23:02 +0100 Subject: [PATCH 28/37] Simplify return value --- crates/fj-kernel/src/partial/maybe_partial.rs | 6 +++--- crates/fj-kernel/src/partial/objects/edge.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index 5a992df2c..399223781 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -124,10 +124,10 @@ impl MaybePartial { impl MaybePartial { /// Access the curve - pub fn curve(&self) -> Option> { + pub fn curve(&self) -> MaybePartial { match self { - Self::Full(full) => Some(full.curve().clone().into()), - Self::Partial(partial) => Some(partial.curve.clone()), + Self::Full(full) => full.curve().clone().into(), + Self::Partial(partial) => partial.curve.clone(), } } diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index e333eaa61..2e1eb217c 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -39,7 +39,7 @@ impl PartialHalfEdge { pub fn extract_global_curve(&self) -> Option> { self.curve .global_form() - .or_else(|| self.global_form.curve()) + .or_else(|| Some(self.global_form.curve())) } /// Access the vertices of the global form, if available From 8ab64a250bc0a0fd8dff7e119ec1802159045c66 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 14:23:56 +0100 Subject: [PATCH 29/37] Simplify return value --- crates/fj-kernel/src/partial/objects/edge.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 2e1eb217c..9b58e0362 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -36,10 +36,10 @@ impl PartialHalfEdge { /// Extract the global curve from either the curve or global form /// /// If a global curve is available through both, the curve is preferred. - pub fn extract_global_curve(&self) -> Option> { + pub fn extract_global_curve(&self) -> MaybePartial { self.curve .global_form() - .or_else(|| Some(self.global_form.curve())) + .unwrap_or_else(|| self.global_form.curve()) } /// Access the vertices of the global form, if available @@ -128,7 +128,7 @@ impl PartialHalfEdge { objects: &Objects, ) -> Result { let curve = Curve::partial() - .with_global_form(self.extract_global_curve()) + .with_global_form(Some(self.extract_global_curve())) .with_surface(self.surface.clone()) .update_as_circle_from_radius(radius); @@ -202,7 +202,7 @@ impl PartialHalfEdge { }); let curve = Curve::partial() - .with_global_form(self.extract_global_curve()) + .with_global_form(Some(self.extract_global_curve())) .with_surface(Some(surface)) .update_as_line_from_points(points); From 55f4a9dcb98499946637a7ea2387b6953cc9977f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 11:11:55 +0100 Subject: [PATCH 30/37] Improve doc comments --- crates/fj-kernel/src/builder/vertex.rs | 2 +- crates/fj-kernel/src/partial/objects/vertex.rs | 18 ++++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 4a619647a..591712562 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -9,7 +9,7 @@ use crate::{ /// Builder API for [`PartialSurfaceVertex`] pub trait SurfaceVertexBuilder { - /// Remove the global form of the partial vertex, inferring it in `build` + /// Infer the global form of the partial vertex fn infer_global_form(self) -> Self; } diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 13cc81570..f8fb2f5b4 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -15,18 +15,18 @@ use crate::{ pub struct PartialVertex { /// The position of the [`Vertex`] on the [`Curve`] /// - /// Must be provided before [`PartialVertex::build`] is called. + /// Must be provided before calling [`PartialVertex::build`]. pub position: Option>, /// The curve that the [`Vertex`] is defined in /// - /// Must be provided before [`PartialVertex::build`] is called. + /// Must be provided before calling [`PartialVertex::build`]. pub curve: MaybePartial, /// The surface form of the [`Vertex`] /// - /// Can be provided, if already available, or computed from the position on - /// the [`Curve`]. + /// Will be computed from `position` and `curve` in + /// [`PartialVertex::build`], if not provided. pub surface_form: MaybePartial, } @@ -74,9 +74,9 @@ impl PartialVertex { /// /// # Panics /// - /// Panics, if no position has been provided. + /// Panics, if position has not been provided. /// - /// Panics, if no curve has been provided. + /// Panics, if curve has not been provided. pub fn build( self, objects: &Objects, @@ -174,12 +174,6 @@ impl PartialSurfaceVertex { } /// Build a full [`SurfaceVertex`] from the partial surface vertex - /// - /// # Panics - /// - /// Panics, if no position has been provided. - /// - /// Panics, if no surface has been provided. pub fn build( self, objects: &Objects, From 5047dccf56fea0b12d41b2ff154e9b1e1626ec53 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 14:44:42 +0100 Subject: [PATCH 31/37] Refactor --- crates/fj-kernel/src/partial/objects/vertex.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index f8fb2f5b4..63212eeec 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -65,9 +65,8 @@ impl PartialVertex { } /// Remove the surface form of the partial vertex, inferring it on build - pub fn infer_surface_form(mut self) -> Self { - self.surface_form = SurfaceVertex::partial().into(); - self + pub fn infer_surface_form(self) -> Self { + self.with_surface_form(Some(SurfaceVertex::partial())) } /// Build a full [`Vertex`] from the partial vertex From d68db01d116f91332eda1477cb727fdd9ac662c6 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 14:46:58 +0100 Subject: [PATCH 32/37] Refactor --- crates/fj-kernel/src/partial/objects/vertex.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 63212eeec..0ad07245a 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -3,7 +3,7 @@ use fj_math::Point; use crate::{ builder::GlobalVertexBuilder, objects::{Curve, GlobalVertex, Objects, Surface, SurfaceVertex, Vertex}, - partial::{HasPartial, MaybePartial}, + partial::MaybePartial, storage::Handle, validate::ValidationError, }; @@ -66,7 +66,7 @@ impl PartialVertex { /// Remove the surface form of the partial vertex, inferring it on build pub fn infer_surface_form(self) -> Self { - self.with_surface_form(Some(SurfaceVertex::partial())) + self.with_surface_form(Some(PartialSurfaceVertex::default())) } /// Build a full [`Vertex`] from the partial vertex From 5034dc15a48cbf4472e47d55b3927036af3f9619 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 14:47:50 +0100 Subject: [PATCH 33/37] Extract builder methods from `PartialVertex` --- crates/fj-kernel/src/builder/mod.rs | 2 +- crates/fj-kernel/src/builder/vertex.rs | 13 +++++++++++++ crates/fj-kernel/src/partial/objects/vertex.rs | 5 ----- crates/fj-kernel/src/validate/edge.rs | 1 + 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/builder/mod.rs b/crates/fj-kernel/src/builder/mod.rs index eaca1bcfe..ab4abf95d 100644 --- a/crates/fj-kernel/src/builder/mod.rs +++ b/crates/fj-kernel/src/builder/mod.rs @@ -18,5 +18,5 @@ pub use self::{ shell::ShellBuilder, sketch::SketchBuilder, solid::SolidBuilder, - vertex::{GlobalVertexBuilder, SurfaceVertexBuilder}, + vertex::{GlobalVertexBuilder, SurfaceVertexBuilder, VertexBuilder}, }; diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 591712562..56c817738 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -4,9 +4,22 @@ use crate::{ objects::{Curve, GlobalVertex, Surface}, partial::{ HasPartial, MaybePartial, PartialGlobalVertex, PartialSurfaceVertex, + PartialVertex, }, }; +/// Builder API for [`PartialVertex`] +pub trait VertexBuilder { + /// Remove the surface form of the partial vertex, inferring it on build + fn infer_surface_form(self) -> Self; +} + +impl VertexBuilder for PartialVertex { + fn infer_surface_form(self) -> Self { + self.with_surface_form(Some(PartialSurfaceVertex::default())) + } +} + /// Builder API for [`PartialSurfaceVertex`] pub trait SurfaceVertexBuilder { /// Infer the global form of the partial vertex diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 0ad07245a..b2dd46917 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -64,11 +64,6 @@ impl PartialVertex { self } - /// Remove the surface form of the partial vertex, inferring it on build - pub fn infer_surface_form(self) -> Self { - self.with_surface_form(Some(PartialSurfaceVertex::default())) - } - /// Build a full [`Vertex`] from the partial vertex /// /// # Panics diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index 31779a45b..fddd9a618 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -196,6 +196,7 @@ mod tests { use fj_interop::ext::ArrayExt; use crate::{ + builder::VertexBuilder, objects::{GlobalCurve, HalfEdge, Objects}, partial::HasPartial, validate::Validate2, From 00b75c0a9b35941c8d6561d03849eebc8e1d6d32 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 14:51:04 +0100 Subject: [PATCH 34/37] Add getters for `PartialVertex` methods --- .../fj-kernel/src/algorithms/transform/vertex.rs | 6 +++--- crates/fj-kernel/src/partial/maybe_partial.rs | 2 +- crates/fj-kernel/src/partial/objects/edge.rs | 8 +++++--- crates/fj-kernel/src/partial/objects/vertex.rs | 15 +++++++++++++++ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index 92d4434e7..f628b4bae 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -14,9 +14,9 @@ impl TransformObject for PartialVertex { transform: &Transform, objects: &Objects, ) -> Result { - let curve = self.curve.transform(transform, objects)?; + let curve = self.curve().transform(transform, objects)?; let surface_form = self - .surface_form + .surface_form() .into_partial() .transform(transform, objects)? .into(); @@ -24,7 +24,7 @@ impl TransformObject for PartialVertex { // Don't need to transform `self.position`, as that is in curve // coordinates and thus transforming the curve takes care of it. Ok(Self { - position: self.position, + position: self.position(), curve, surface_form, }) diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index 399223781..099ce24bd 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -186,7 +186,7 @@ impl MaybePartial { pub fn surface_form(&self) -> MaybePartial { match self { Self::Full(full) => full.surface_form().clone().into(), - Self::Partial(partial) => partial.surface_form.clone(), + Self::Partial(partial) => partial.surface_form(), } } } diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 9b58e0362..3df61f925 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -252,9 +252,11 @@ impl PartialHalfEdge { vertices.zip_ext(global_forms).map(|(vertex, global_form)| { vertex.update_partial(|vertex| { vertex.clone().with_surface_form(Some( - vertex.surface_form.update_partial(|surface_vertex| { - surface_vertex.with_global_form(global_form) - }), + vertex.surface_form().update_partial( + |surface_vertex| { + surface_vertex.with_global_form(global_form) + }, + ), )) }) }) diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index b2dd46917..3374ee48c 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -31,6 +31,21 @@ pub struct PartialVertex { } impl PartialVertex { + /// Access the position of the [`Vertex`] on the curve + pub fn position(&self) -> Option> { + self.position + } + + /// Access the curve that the [`Vertex`] is defined in + pub fn curve(&self) -> MaybePartial { + self.curve.clone() + } + + /// Access the surface form of the [`Vertex`] + pub fn surface_form(&self) -> MaybePartial { + self.surface_form.clone() + } + /// Provide a position for the partial vertex pub fn with_position( mut self, From 5081e9c34ae1c2ac9b12692b7b6782d520fba068 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 14:52:09 +0100 Subject: [PATCH 35/37] Make fields of `PartialVertex` private --- .../src/algorithms/transform/vertex.rs | 9 ++++----- crates/fj-kernel/src/partial/objects/vertex.rs | 18 +++--------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index f628b4bae..a1a370621 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -23,11 +23,10 @@ impl TransformObject for PartialVertex { // Don't need to transform `self.position`, as that is in curve // coordinates and thus transforming the curve takes care of it. - Ok(Self { - position: self.position(), - curve, - surface_form, - }) + Ok(Self::default() + .with_position(self.position()) + .with_curve(Some(curve)) + .with_surface_form(surface_form)) } } diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 3374ee48c..778d9b068 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -13,21 +13,9 @@ use crate::{ /// See [`crate::partial`] for more information. #[derive(Clone, Debug, Default)] pub struct PartialVertex { - /// The position of the [`Vertex`] on the [`Curve`] - /// - /// Must be provided before calling [`PartialVertex::build`]. - pub position: Option>, - - /// The curve that the [`Vertex`] is defined in - /// - /// Must be provided before calling [`PartialVertex::build`]. - pub curve: MaybePartial, - - /// The surface form of the [`Vertex`] - /// - /// Will be computed from `position` and `curve` in - /// [`PartialVertex::build`], if not provided. - pub surface_form: MaybePartial, + position: Option>, + curve: MaybePartial, + surface_form: MaybePartial, } impl PartialVertex { From 5fec6dec06e9857536f6b4117baac8d967de9090 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 14:58:03 +0100 Subject: [PATCH 36/37] Add `MaybePartial::path` --- crates/fj-kernel/src/partial/maybe_partial.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index 099ce24bd..e2a968719 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -5,6 +5,7 @@ use crate::{ Curve, GlobalCurve, GlobalEdge, GlobalVertex, HalfEdge, Objects, Surface, SurfaceVertex, Vertex, }, + path::SurfacePath, storage::Handle, validate::ValidationError, }; @@ -113,6 +114,14 @@ where // `MaybePartial`, as that would conflict. impl MaybePartial { + /// Access the path + pub fn path(&self) -> Option { + match self { + MaybePartial::Full(full) => Some(full.path()), + MaybePartial::Partial(partial) => partial.path(), + } + } + /// Access the global form pub fn global_form(&self) -> Option> { match self { From f3ef0042c235bd98bbb13eb9acbfc49655ad0193 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Nov 2022 15:00:56 +0100 Subject: [PATCH 37/37] Add `MaybePartial::surface` --- crates/fj-kernel/src/partial/maybe_partial.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index e2a968719..5b5e43988 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -122,6 +122,14 @@ impl MaybePartial { } } + /// Access the surface + pub fn surface(&self) -> Option> { + match self { + MaybePartial::Full(full) => Some(full.surface().clone()), + MaybePartial::Partial(partial) => partial.surface(), + } + } + /// Access the global form pub fn global_form(&self) -> Option> { match self {