Remove PartialVertex::with_position

This commit is contained in:
Hanno Braun 2022-11-11 16:07:21 +01:00
parent b71665a895
commit 4f4ddeffe9
8 changed files with 56 additions and 52 deletions

View File

@ -170,8 +170,8 @@ mod tests {
algorithms::sweep::Sweep, algorithms::sweep::Sweep,
builder::{CurveBuilder, HalfEdgeBuilder}, builder::{CurveBuilder, HalfEdgeBuilder},
insert::Insert, insert::Insert,
objects::{HalfEdge, Objects, Vertex}, objects::{HalfEdge, Objects},
partial::{HasPartial, PartialCurve}, partial::{HasPartial, PartialCurve, PartialVertex},
}; };
#[test] #[test]
@ -185,8 +185,10 @@ mod tests {
}; };
curve.update_as_u_axis(); curve.update_as_u_axis();
let curve = curve.build(&objects)?.insert(&objects)?; let curve = curve.build(&objects)?.insert(&objects)?;
let vertex = Vertex::partial() let vertex = PartialVertex {
.with_position(Some([0.])) position: Some([0.].into()),
..Default::default()
}
.with_curve(curve) .with_curve(curve)
.build(&objects)? .build(&objects)?
.insert(&objects)?; .insert(&objects)?;

View File

@ -22,8 +22,10 @@ impl TransformObject for PartialVertex {
// Don't need to transform `self.position`, as that is in curve // Don't need to transform `self.position`, as that is in curve
// coordinates and thus transforming the curve takes care of it. // coordinates and thus transforming the curve takes care of it.
Ok(Self::default() Ok(Self {
.with_position(self.position) position: self.position,
..Default::default()
}
.with_curve(curve) .with_curve(curve)
.with_surface_form(surface_form)) .with_surface_form(surface_form))
} }

View File

@ -1,10 +1,10 @@
use fj_math::Point; use fj_math::Point;
use crate::{ use crate::{
objects::{HalfEdge, Surface, SurfaceVertex, Vertex}, objects::{HalfEdge, Surface, SurfaceVertex},
partial::{ partial::{
HasPartial, MaybePartial, PartialCurve, PartialCycle, HasPartial, MaybePartial, PartialCurve, PartialCycle,
PartialSurfaceVertex, PartialSurfaceVertex, PartialVertex,
}, },
storage::Handle, storage::Handle,
}; };
@ -76,9 +76,11 @@ impl CycleBuilder for PartialCycle {
let vertices = [(0., vertex_prev), (1., vertex_next)].map( let vertices = [(0., vertex_prev), (1., vertex_next)].map(
|(position, surface_form)| { |(position, surface_form)| {
Vertex::partial() PartialVertex {
position: Some([position].into()),
..Default::default()
}
.with_curve(curve.clone()) .with_curve(curve.clone())
.with_position(Some([position]))
.with_surface_form(surface_form) .with_surface_form(surface_form)
}, },
); );

View File

@ -9,7 +9,7 @@ use crate::{
}, },
partial::{ partial::{
HasPartial, MaybePartial, PartialCurve, PartialGlobalEdge, HasPartial, MaybePartial, PartialCurve, PartialGlobalEdge,
PartialHalfEdge, PartialSurfaceVertex, PartialHalfEdge, PartialSurfaceVertex, PartialVertex,
}, },
storage::Handle, storage::Handle,
validate::ValidationError, validate::ValidationError,
@ -97,8 +97,10 @@ impl HalfEdgeBuilder for PartialHalfEdge {
.insert(objects)?; .insert(objects)?;
let [back, front] = [a_curve, b_curve].map(|point_curve| { let [back, front] = [a_curve, b_curve].map(|point_curve| {
Vertex::partial() PartialVertex {
.with_position(Some(point_curve)) position: Some(point_curve),
..Default::default()
}
.with_curve(curve.clone()) .with_curve(curve.clone())
.with_surface_form(surface_vertex.clone()) .with_surface_form(surface_vertex.clone())
}); });
@ -152,10 +154,9 @@ impl HalfEdgeBuilder for PartialHalfEdge {
let [back, front] = { let [back, front] = {
let vertices = [(from, 0.), (to, 1.)].map(|(vertex, position)| { let vertices = [(from, 0.), (to, 1.)].map(|(vertex, position)| {
vertex.update_partial(|vertex| { vertex.update_partial(|mut vertex| {
vertex vertex.position = Some([position].into());
.with_position(Some([position])) vertex.with_curve(curve.clone())
.with_curve(curve.clone())
}) })
}); });

View File

@ -11,7 +11,7 @@ use crate::{
objects::{ objects::{
Cycle, Face, FaceSet, HalfEdge, Objects, Shell, Surface, Vertex, Cycle, Face, FaceSet, HalfEdge, Objects, Shell, Surface, Vertex,
}, },
partial::{HasPartial, PartialCurve, PartialSurfaceVertex}, partial::{HasPartial, PartialCurve, PartialSurfaceVertex, PartialVertex},
storage::Handle, storage::Handle,
}; };
@ -277,8 +277,10 @@ impl<'a> ShellBuilder<'a> {
.zip(surface_vertices.clone()) .zip(surface_vertices.clone())
.collect::<[_; 2]>() .collect::<[_; 2]>()
.map(|(vertex, surface_form)| { .map(|(vertex, surface_form)| {
Vertex::partial() PartialVertex {
.with_position(Some(vertex.position())) position: Some(vertex.position()),
..Default::default()
}
.with_surface_form(surface_form) .with_surface_form(surface_form)
}); });

View File

@ -24,17 +24,6 @@ pub struct PartialVertex {
} }
impl PartialVertex { impl PartialVertex {
/// Provide a position for the partial vertex
pub fn with_position(
mut self,
position: Option<impl Into<Point<1>>>,
) -> Self {
if let Some(position) = position {
self.position = Some(position.into());
}
self
}
/// Provide a curve for the partial vertex /// Provide a curve for the partial vertex
pub fn with_curve(mut self, curve: impl Into<MaybePartial<Curve>>) -> Self { pub fn with_curve(mut self, curve: impl Into<MaybePartial<Curve>>) -> Self {
self.curve = curve.into(); self.curve = curve.into();

View File

@ -308,9 +308,9 @@ mod tests {
let invalid = HalfEdge::new( let invalid = HalfEdge::new(
valid.vertices().clone().try_map_ext( valid.vertices().clone().try_map_ext(
|vertex| -> anyhow::Result<_, ValidationError> { |vertex| -> anyhow::Result<_, ValidationError> {
let mut vertex = vertex.to_partial();
vertex.position = Some([0.].into());
Ok(vertex Ok(vertex
.to_partial()
.with_position(Some([0.]))
.infer_surface_form() .infer_surface_form()
.build(&objects)? .build(&objects)?
.insert(&objects)?) .insert(&objects)?)

View File

@ -182,7 +182,9 @@ mod tests {
builder::{CurveBuilder, SurfaceVertexBuilder}, builder::{CurveBuilder, SurfaceVertexBuilder},
insert::Insert, insert::Insert,
objects::{GlobalVertex, Objects, SurfaceVertex, Vertex}, objects::{GlobalVertex, Objects, SurfaceVertex, Vertex},
partial::{HasPartial, PartialCurve, PartialSurfaceVertex}, partial::{
HasPartial, PartialCurve, PartialSurfaceVertex, PartialVertex,
},
validate::Validate, validate::Validate,
}; };
@ -196,8 +198,10 @@ mod tests {
}; };
curve.update_as_u_axis(); curve.update_as_u_axis();
let valid = Vertex::partial() let valid = PartialVertex {
.with_position(Some([0.])) position: Some([0.].into()),
..Default::default()
}
.with_curve(curve) .with_curve(curve)
.build(&objects)?; .build(&objects)?;
let invalid = Vertex::new(valid.position(), valid.curve().clone(), { let invalid = Vertex::new(valid.position(), valid.curve().clone(), {
@ -223,8 +227,10 @@ mod tests {
}; };
curve.update_as_u_axis(); curve.update_as_u_axis();
Vertex::partial() PartialVertex {
.with_position(Some([0.])) position: Some([0.].into()),
..Default::default()
}
.with_curve(curve) .with_curve(curve)
.build(&objects)? .build(&objects)?
}; };