From e24c56b69ad7c5240b0f5e568c8d4d0303d142db Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 8 Nov 2022 13:26:59 +0100 Subject: [PATCH] Move non-essential methods to builder trait --- crates/fj-kernel/src/builder/edge.rs | 18 ++++++++++++++- crates/fj-kernel/src/partial/objects/cycle.rs | 1 + crates/fj-kernel/src/partial/objects/edge.rs | 22 ------------------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index f85b1bc45..ba5f3369a 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -6,7 +6,7 @@ use crate::{ Curve, GlobalVertex, Objects, Surface, SurfaceVertex, Vertex, VerticesInNormalizedOrder, }, - partial::{HasPartial, PartialGlobalEdge, PartialHalfEdge}, + partial::{HasPartial, MaybePartial, PartialGlobalEdge, PartialHalfEdge}, storage::Handle, validate::ValidationError, }; @@ -15,6 +15,12 @@ use super::{CurveBuilder, GlobalVertexBuilder}; /// Builder API for [`PartialHalfEdge`] pub trait HalfEdgeBuilder: Sized { + /// Update the partial half-edge with the given back vertex + fn with_back_vertex(self, back: impl Into>) -> Self; + + /// Update the partial half-edge with the given front vertex + fn with_front_vertex(self, front: impl Into>) -> Self; + /// Update partial half-edge as a circle, from the given radius /// /// # Implementation Note @@ -40,6 +46,16 @@ pub trait HalfEdgeBuilder: Sized { } impl HalfEdgeBuilder for PartialHalfEdge { + fn with_back_vertex(self, back: impl Into>) -> Self { + let [_, front] = self.vertices(); + self.with_vertices([back.into(), front]) + } + + fn with_front_vertex(self, front: impl Into>) -> Self { + let [back, _] = self.vertices(); + self.with_vertices([back, front.into()]) + } + fn update_as_circle_from_radius( self, radius: impl Into, diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index bc8479abf..461c48fdb 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -1,4 +1,5 @@ use crate::{ + builder::HalfEdgeBuilder, objects::{Cycle, HalfEdge, Objects, Surface}, partial::{ util::merge_options, MaybePartial, PartialHalfEdge, PartialVertex, diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 7b5ffe3c9..fb8d268ad 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -73,28 +73,6 @@ impl PartialHalfEdge { self } - /// Update the partial half-edge with the given back vertex - pub fn with_back_vertex( - mut self, - vertex: impl Into>, - ) -> Self { - let [from, _] = &mut self.vertices; - *from = vertex.into(); - - self - } - - /// Update the partial half-edge with the given front vertex - pub fn with_front_vertex( - mut self, - vertex: impl Into>, - ) -> Self { - let [_, to] = &mut self.vertices; - *to = vertex.into(); - - self - } - /// Update the partial half-edge with the given vertices pub fn with_vertices( mut self,