Simplify PartialHalfEdge::with_back_vertex

This commit is contained in:
Hanno Braun 2022-11-05 20:19:20 +01:00
parent 162aba8caa
commit e2ddd014b1
3 changed files with 50 additions and 56 deletions

View File

@ -208,61 +208,56 @@ mod tests {
let face = let face =
(half_edge, Color::default()).sweep([0., 0., 1.], &objects)?; (half_edge, Color::default()).sweep([0., 0., 1.], &objects)?;
let expected_face = { let expected_face =
let surface = objects.surfaces.xz_plane(); {
let surface = objects.surfaces.xz_plane();
let bottom = HalfEdge::partial() let bottom = HalfEdge::partial()
.update_as_line_segment_from_points( .update_as_line_segment_from_points(
surface.clone(), surface.clone(),
[[0., 0.], [1., 0.]], [[0., 0.], [1., 0.]],
) )
.build(&objects)?; .build(&objects)?;
let side_up = HalfEdge::partial() let side_up = HalfEdge::partial()
.with_surface(Some(surface.clone())) .with_surface(Some(surface.clone()))
.with_back_vertex(Some( .with_back_vertex(Vertex::partial().with_surface_form(
Vertex::partial().with_surface_form(
bottom.front().surface_form().clone(), bottom.front().surface_form().clone(),
), ))
)) .with_front_vertex(Vertex::partial().with_surface_form(
.with_front_vertex(Vertex::partial().with_surface_form( SurfaceVertex::partial().with_position(Some([1., 1.])),
SurfaceVertex::partial().with_position(Some([1., 1.])), ))
)) .update_as_line_segment()
.update_as_line_segment() .build(&objects)?;
.build(&objects)?; let top = HalfEdge::partial()
let top = HalfEdge::partial() .with_surface(Some(surface.clone()))
.with_surface(Some(surface.clone())) .with_back_vertex(Vertex::partial().with_surface_form(
.with_back_vertex(Some(Vertex::partial().with_surface_form( SurfaceVertex::partial().with_position(Some([0., 1.])),
SurfaceVertex::partial().with_position(Some([0., 1.])), ))
))) .with_front_vertex(Vertex::partial().with_surface_form(
.with_front_vertex(
Vertex::partial().with_surface_form(
side_up.front().surface_form().clone(), side_up.front().surface_form().clone(),
), ))
) .update_as_line_segment()
.update_as_line_segment() .build(&objects)?
.build(&objects)? .reverse(&objects)?;
.reverse(&objects)?; let side_down =
let side_down = HalfEdge::partial() HalfEdge::partial()
.with_surface(Some(surface)) .with_surface(Some(surface))
.with_back_vertex(Some( .with_back_vertex(Vertex::partial().with_surface_form(
Vertex::partial().with_surface_form( bottom.back().surface_form().clone(),
bottom.back().surface_form().clone(), ))
), .with_front_vertex(Vertex::partial().with_surface_form(
)) top.front().surface_form().clone(),
.with_front_vertex( ))
Vertex::partial() .update_as_line_segment()
.with_surface_form(top.front().surface_form().clone()), .build(&objects)?
) .reverse(&objects)?;
.update_as_line_segment()
.build(&objects)?
.reverse(&objects)?;
let cycle = objects let cycle = objects
.cycles .cycles
.insert(Cycle::new([bottom, side_up, top, side_down]))?; .insert(Cycle::new([bottom, side_up, top, side_down]))?;
Face::builder(&objects).with_exterior(cycle).build() Face::builder(&objects).with_exterior(cycle).build()
}; };
assert_eq!(face, expected_face); assert_eq!(face, expected_face);
Ok(()) Ok(())

View File

@ -118,7 +118,7 @@ impl PartialCycle {
partial.with_surface_form(previous_vertex) partial.with_surface_form(previous_vertex)
}); });
half_edge.with_back_vertex(Some(back)) half_edge.with_back_vertex(back)
}) })
.into_full(objects)?; .into_full(objects)?;

View File

@ -82,12 +82,11 @@ impl PartialHalfEdge {
/// Update the partial half-edge with the given back vertex /// Update the partial half-edge with the given back vertex
pub fn with_back_vertex( pub fn with_back_vertex(
mut self, mut self,
vertex: Option<impl Into<MaybePartial<Vertex>>>, vertex: impl Into<MaybePartial<Vertex>>,
) -> Self { ) -> Self {
if let Some(vertex) = vertex { let [from, _] = &mut self.vertices;
let [from, _] = &mut self.vertices; *from = vertex.into();
*from = vertex.into();
}
self self
} }