From 4f4ddeffe9ac3558a5a648ca0640b7d505962e1f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 16:07:21 +0100 Subject: [PATCH] Remove `PartialVertex::with_position` --- .../fj-kernel/src/algorithms/sweep/vertex.rs | 16 +++++++------ .../src/algorithms/transform/vertex.rs | 10 ++++---- crates/fj-kernel/src/builder/cycle.rs | 14 ++++++----- crates/fj-kernel/src/builder/edge.rs | 19 ++++++++------- crates/fj-kernel/src/builder/shell.rs | 10 ++++---- .../fj-kernel/src/partial/objects/vertex.rs | 11 --------- crates/fj-kernel/src/validate/edge.rs | 4 ++-- crates/fj-kernel/src/validate/vertex.rs | 24 ++++++++++++------- 8 files changed, 56 insertions(+), 52 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index 69c557727..b572a9f65 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -170,8 +170,8 @@ mod tests { algorithms::sweep::Sweep, builder::{CurveBuilder, HalfEdgeBuilder}, insert::Insert, - objects::{HalfEdge, Objects, Vertex}, - partial::{HasPartial, PartialCurve}, + objects::{HalfEdge, Objects}, + partial::{HasPartial, PartialCurve, PartialVertex}, }; #[test] @@ -185,11 +185,13 @@ mod tests { }; curve.update_as_u_axis(); let curve = curve.build(&objects)?.insert(&objects)?; - let vertex = Vertex::partial() - .with_position(Some([0.])) - .with_curve(curve) - .build(&objects)? - .insert(&objects)?; + let vertex = PartialVertex { + position: Some([0.].into()), + ..Default::default() + } + .with_curve(curve) + .build(&objects)? + .insert(&objects)?; let half_edge = (vertex, surface.clone()).sweep([0., 0., 1.], &objects)?; diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index 84ebeab51..442d4a50a 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -22,10 +22,12 @@ 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::default() - .with_position(self.position) - .with_curve(curve) - .with_surface_form(surface_form)) + Ok(Self { + position: self.position, + ..Default::default() + } + .with_curve(curve) + .with_surface_form(surface_form)) } } diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 85458a107..65317238b 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -1,10 +1,10 @@ use fj_math::Point; use crate::{ - objects::{HalfEdge, Surface, SurfaceVertex, Vertex}, + objects::{HalfEdge, Surface, SurfaceVertex}, partial::{ HasPartial, MaybePartial, PartialCurve, PartialCycle, - PartialSurfaceVertex, + PartialSurfaceVertex, PartialVertex, }, storage::Handle, }; @@ -76,10 +76,12 @@ impl CycleBuilder for PartialCycle { let vertices = [(0., vertex_prev), (1., vertex_next)].map( |(position, surface_form)| { - Vertex::partial() - .with_curve(curve.clone()) - .with_position(Some([position])) - .with_surface_form(surface_form) + PartialVertex { + position: Some([position].into()), + ..Default::default() + } + .with_curve(curve.clone()) + .with_surface_form(surface_form) }, ); diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index fc6bc557f..a246fc0b5 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -9,7 +9,7 @@ use crate::{ }, partial::{ HasPartial, MaybePartial, PartialCurve, PartialGlobalEdge, - PartialHalfEdge, PartialSurfaceVertex, + PartialHalfEdge, PartialSurfaceVertex, PartialVertex, }, storage::Handle, validate::ValidationError, @@ -97,10 +97,12 @@ impl HalfEdgeBuilder for PartialHalfEdge { .insert(objects)?; let [back, front] = [a_curve, b_curve].map(|point_curve| { - Vertex::partial() - .with_position(Some(point_curve)) - .with_curve(curve.clone()) - .with_surface_form(surface_vertex.clone()) + PartialVertex { + position: Some(point_curve), + ..Default::default() + } + .with_curve(curve.clone()) + .with_surface_form(surface_vertex.clone()) }); Ok(self.with_curve(curve).with_vertices([back, front])) @@ -152,10 +154,9 @@ impl HalfEdgeBuilder for PartialHalfEdge { let [back, front] = { let vertices = [(from, 0.), (to, 1.)].map(|(vertex, position)| { - vertex.update_partial(|vertex| { - vertex - .with_position(Some([position])) - .with_curve(curve.clone()) + vertex.update_partial(|mut vertex| { + vertex.position = Some([position].into()); + vertex.with_curve(curve.clone()) }) }); diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 3ba3cccd2..eb86fb61e 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -11,7 +11,7 @@ use crate::{ objects::{ Cycle, Face, FaceSet, HalfEdge, Objects, Shell, Surface, Vertex, }, - partial::{HasPartial, PartialCurve, PartialSurfaceVertex}, + partial::{HasPartial, PartialCurve, PartialSurfaceVertex, PartialVertex}, storage::Handle, }; @@ -277,9 +277,11 @@ impl<'a> ShellBuilder<'a> { .zip(surface_vertices.clone()) .collect::<[_; 2]>() .map(|(vertex, surface_form)| { - Vertex::partial() - .with_position(Some(vertex.position())) - .with_surface_form(surface_form) + PartialVertex { + position: Some(vertex.position()), + ..Default::default() + } + .with_surface_form(surface_form) }); edges.push( diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 3a519b11a..1149c9206 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -24,17 +24,6 @@ pub struct PartialVertex { } impl PartialVertex { - /// Provide a position for the partial vertex - pub fn with_position( - mut self, - position: Option>>, - ) -> Self { - if let Some(position) = position { - self.position = Some(position.into()); - } - self - } - /// Provide a curve for the partial vertex pub fn with_curve(mut self, curve: impl Into>) -> Self { self.curve = curve.into(); diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index 7a4b837d1..809c735dd 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -308,9 +308,9 @@ mod tests { let invalid = HalfEdge::new( valid.vertices().clone().try_map_ext( |vertex| -> anyhow::Result<_, ValidationError> { + let mut vertex = vertex.to_partial(); + vertex.position = Some([0.].into()); Ok(vertex - .to_partial() - .with_position(Some([0.])) .infer_surface_form() .build(&objects)? .insert(&objects)?) diff --git a/crates/fj-kernel/src/validate/vertex.rs b/crates/fj-kernel/src/validate/vertex.rs index 11a6dc4be..b27d46f08 100644 --- a/crates/fj-kernel/src/validate/vertex.rs +++ b/crates/fj-kernel/src/validate/vertex.rs @@ -182,7 +182,9 @@ mod tests { builder::{CurveBuilder, SurfaceVertexBuilder}, insert::Insert, objects::{GlobalVertex, Objects, SurfaceVertex, Vertex}, - partial::{HasPartial, PartialCurve, PartialSurfaceVertex}, + partial::{ + HasPartial, PartialCurve, PartialSurfaceVertex, PartialVertex, + }, validate::Validate, }; @@ -196,10 +198,12 @@ mod tests { }; curve.update_as_u_axis(); - let valid = Vertex::partial() - .with_position(Some([0.])) - .with_curve(curve) - .build(&objects)?; + let valid = PartialVertex { + position: Some([0.].into()), + ..Default::default() + } + .with_curve(curve) + .build(&objects)?; let invalid = Vertex::new(valid.position(), valid.curve().clone(), { let mut tmp = valid.surface_form().to_partial(); tmp.surface = Some(objects.surfaces.xz_plane()); @@ -223,10 +227,12 @@ mod tests { }; curve.update_as_u_axis(); - Vertex::partial() - .with_position(Some([0.])) - .with_curve(curve) - .build(&objects)? + PartialVertex { + position: Some([0.].into()), + ..Default::default() + } + .with_curve(curve) + .build(&objects)? }; let invalid = Vertex::new(valid.position(), valid.curve().clone(), { let mut tmp = valid.surface_form().to_partial();