From 36b8057e9dbaea210fb4c2f816dcba22b49635fb Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 19 Sep 2022 17:33:15 +0200 Subject: [PATCH 1/4] Add `GlobalVertexBuilder` --- crates/fj-kernel/src/builder/mod.rs | 2 +- crates/fj-kernel/src/builder/vertex.rs | 3 +++ crates/fj-kernel/src/objects/vertex.rs | 7 ++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/builder/mod.rs b/crates/fj-kernel/src/builder/mod.rs index 5a659b739..1cb2939c3 100644 --- a/crates/fj-kernel/src/builder/mod.rs +++ b/crates/fj-kernel/src/builder/mod.rs @@ -17,5 +17,5 @@ pub use self::{ shell::ShellBuilder, sketch::SketchBuilder, solid::SolidBuilder, - vertex::VertexBuilder, + vertex::{GlobalVertexBuilder, VertexBuilder}, }; diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index e0fb64fc5..7fdb9a539 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -35,3 +35,6 @@ impl VertexBuilder { Vertex::new([0.], self.curve.clone(), surface_form, global_form) } } + +/// API for building a [`GlobalVertex`] +pub struct GlobalVertexBuilder; diff --git a/crates/fj-kernel/src/objects/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs index acac7f214..4d2f97598 100644 --- a/crates/fj-kernel/src/objects/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -1,7 +1,7 @@ use fj_math::Point; use pretty_assertions::assert_eq; -use crate::builder::VertexBuilder; +use crate::builder::{GlobalVertexBuilder, VertexBuilder}; use super::{Curve, Surface}; @@ -134,6 +134,11 @@ pub struct GlobalVertex { } impl GlobalVertex { + /// Build a `GlobalVertex` using [`GlobalVertexBuilder`] + pub fn build() -> GlobalVertexBuilder { + GlobalVertexBuilder + } + /// Construct a `GlobalVertex` from a point pub fn from_position(position: impl Into>) -> Self { let position = position.into(); From b1fa882ac2228b5e711592d36ea134db258850c1 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 19 Sep 2022 17:34:15 +0200 Subject: [PATCH 2/4] Add `GlobalVertexBuilder::from_curve_and_position` --- crates/fj-kernel/src/builder/vertex.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 7fdb9a539..bde41b778 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -20,12 +20,9 @@ impl VertexBuilder { let point = point.into(); let &surface = self.curve.surface(); - let global_form = GlobalVertex::from_position( - self.curve - .global_form() - .path() - .point_from_path_coords(point), - ); + let global_form = + GlobalVertex::build().from_curve_and_position(&self.curve, point); + let surface_form = SurfaceVertex::new( self.curve.path().point_from_path_coords(point), surface, @@ -38,3 +35,16 @@ impl VertexBuilder { /// API for building a [`GlobalVertex`] pub struct GlobalVertexBuilder; + +impl GlobalVertexBuilder { + /// Build a [`GlobalVertex`] from a curve and a position on that curve + pub fn from_curve_and_position( + &self, + curve: &Curve, + position: impl Into>, + ) -> GlobalVertex { + let position_global = + curve.global_form().path().point_from_path_coords(position); + GlobalVertex::from_position(position_global) + } +} From 9063b55f1dcd99975c3fe429680a488ada80cabd Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 19 Sep 2022 17:36:48 +0200 Subject: [PATCH 3/4] Bypass `GlobalCurve` in `GlobalVertexBuilder` --- crates/fj-kernel/src/builder/vertex.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index bde41b778..cf88ddd70 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -43,8 +43,9 @@ impl GlobalVertexBuilder { curve: &Curve, position: impl Into>, ) -> GlobalVertex { + let position_surface = curve.path().point_from_path_coords(position); let position_global = - curve.global_form().path().point_from_path_coords(position); + curve.surface().point_from_surface_coords(position_surface); GlobalVertex::from_position(position_global) } } From ee72b81c9defe90de6462f1283ede5b3a074f1ab Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 19 Sep 2022 17:39:40 +0200 Subject: [PATCH 4/4] Add additional `GlobalVertexBuilder` method Consolidate duplicated code into this new method. --- crates/fj-kernel/src/builder/edge.rs | 4 ++-- crates/fj-kernel/src/builder/vertex.rs | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 1153c75a1..e5b074c9a 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -68,8 +68,8 @@ impl<'a> HalfEdgeBuilder<'a> { let points = points.map(Into::into); let global_vertices = points.map(|position| { - let position = self.surface.point_from_surface_coords(position); - GlobalVertex::from_position(position) + GlobalVertex::build() + .from_surface_and_position(&self.surface, position) }); let surface_vertices = { diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index cf88ddd70..6eb4d30ba 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -1,6 +1,6 @@ use fj_math::Point; -use crate::objects::{Curve, GlobalVertex, SurfaceVertex, Vertex}; +use crate::objects::{Curve, GlobalVertex, Surface, SurfaceVertex, Vertex}; /// API for building a [`Vertex`] pub struct VertexBuilder { @@ -44,8 +44,16 @@ impl GlobalVertexBuilder { position: impl Into>, ) -> GlobalVertex { let position_surface = curve.path().point_from_path_coords(position); - let position_global = - curve.surface().point_from_surface_coords(position_surface); - GlobalVertex::from_position(position_global) + self.from_surface_and_position(curve.surface(), position_surface) + } + + /// Build a [`GlobalVertex`] from a surface and a position on that surface + pub fn from_surface_and_position( + &self, + surface: &Surface, + position: impl Into>, + ) -> GlobalVertex { + let position = surface.point_from_surface_coords(position); + GlobalVertex::from_position(position) } }