Move non-essential methods to builder trait

This commit is contained in:
Hanno Braun 2022-11-08 13:26:59 +01:00
parent aeb686c5cd
commit e24c56b69a
3 changed files with 18 additions and 23 deletions

View File

@ -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<MaybePartial<Vertex>>) -> Self;
/// Update the partial half-edge with the given front vertex
fn with_front_vertex(self, front: impl Into<MaybePartial<Vertex>>) -> 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<MaybePartial<Vertex>>) -> Self {
let [_, front] = self.vertices();
self.with_vertices([back.into(), front])
}
fn with_front_vertex(self, front: impl Into<MaybePartial<Vertex>>) -> Self {
let [back, _] = self.vertices();
self.with_vertices([back, front.into()])
}
fn update_as_circle_from_radius(
self,
radius: impl Into<Scalar>,

View File

@ -1,4 +1,5 @@
use crate::{
builder::HalfEdgeBuilder,
objects::{Cycle, HalfEdge, Objects, Surface},
partial::{
util::merge_options, MaybePartial, PartialHalfEdge, PartialVertex,

View File

@ -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<MaybePartial<Vertex>>,
) -> 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<MaybePartial<Vertex>>,
) -> 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,