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,
builder::{CurveBuilder, HalfEdgeBuilder},
insert::Insert,
objects::{HalfEdge, Objects, Vertex},
partial::{HasPartial, PartialCurve},
objects::{HalfEdge, Objects},
partial::{HasPartial, PartialCurve, PartialVertex},
};
#[test]
@ -185,8 +185,10 @@ mod tests {
};
curve.update_as_u_axis();
let curve = curve.build(&objects)?.insert(&objects)?;
let vertex = Vertex::partial()
.with_position(Some([0.]))
let vertex = PartialVertex {
position: Some([0.].into()),
..Default::default()
}
.with_curve(curve)
.build(&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
// coordinates and thus transforming the curve takes care of it.
Ok(Self::default()
.with_position(self.position)
Ok(Self {
position: self.position,
..Default::default()
}
.with_curve(curve)
.with_surface_form(surface_form))
}

View File

@ -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,9 +76,11 @@ impl CycleBuilder for PartialCycle {
let vertices = [(0., vertex_prev), (1., vertex_next)].map(
|(position, surface_form)| {
Vertex::partial()
PartialVertex {
position: Some([position].into()),
..Default::default()
}
.with_curve(curve.clone())
.with_position(Some([position]))
.with_surface_form(surface_form)
},
);

View File

@ -9,7 +9,7 @@ use crate::{
},
partial::{
HasPartial, MaybePartial, PartialCurve, PartialGlobalEdge,
PartialHalfEdge, PartialSurfaceVertex,
PartialHalfEdge, PartialSurfaceVertex, PartialVertex,
},
storage::Handle,
validate::ValidationError,
@ -97,8 +97,10 @@ impl HalfEdgeBuilder for PartialHalfEdge {
.insert(objects)?;
let [back, front] = [a_curve, b_curve].map(|point_curve| {
Vertex::partial()
.with_position(Some(point_curve))
PartialVertex {
position: Some(point_curve),
..Default::default()
}
.with_curve(curve.clone())
.with_surface_form(surface_vertex.clone())
});
@ -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())
})
});

View File

@ -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,8 +277,10 @@ impl<'a> ShellBuilder<'a> {
.zip(surface_vertices.clone())
.collect::<[_; 2]>()
.map(|(vertex, surface_form)| {
Vertex::partial()
.with_position(Some(vertex.position()))
PartialVertex {
position: Some(vertex.position()),
..Default::default()
}
.with_surface_form(surface_form)
});

View File

@ -24,17 +24,6 @@ pub struct 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
pub fn with_curve(mut self, curve: impl Into<MaybePartial<Curve>>) -> Self {
self.curve = curve.into();

View File

@ -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)?)

View File

@ -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,8 +198,10 @@ mod tests {
};
curve.update_as_u_axis();
let valid = Vertex::partial()
.with_position(Some([0.]))
let valid = PartialVertex {
position: Some([0.].into()),
..Default::default()
}
.with_curve(curve)
.build(&objects)?;
let invalid = Vertex::new(valid.position(), valid.curve().clone(), {
@ -223,8 +227,10 @@ mod tests {
};
curve.update_as_u_axis();
Vertex::partial()
.with_position(Some([0.]))
PartialVertex {
position: Some([0.].into()),
..Default::default()
}
.with_curve(curve)
.build(&objects)?
};