Simplify `PartialHalfEdge::with_surface`

This commit is contained in:
Hanno Braun 2022-11-05 21:45:08 +01:00
parent 3278ae73ad
commit 076400632c
5 changed files with 20 additions and 22 deletions

View File

@ -219,7 +219,7 @@ mod tests {
) )
.build(&objects)?; .build(&objects)?;
let side_up = HalfEdge::partial() let side_up = HalfEdge::partial()
.with_surface(Some(surface.clone())) .with_surface(surface.clone())
.with_back_vertex(Vertex::partial().with_surface_form( .with_back_vertex(Vertex::partial().with_surface_form(
bottom.front().surface_form().clone(), bottom.front().surface_form().clone(),
)) ))
@ -229,7 +229,7 @@ mod tests {
.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(surface.clone())
.with_back_vertex(Vertex::partial().with_surface_form( .with_back_vertex(Vertex::partial().with_surface_form(
SurfaceVertex::partial().with_position(Some([0., 1.])), SurfaceVertex::partial().with_position(Some([0., 1.])),
)) ))
@ -241,7 +241,7 @@ mod tests {
.reverse(&objects)?; .reverse(&objects)?;
let side_down = let side_down =
HalfEdge::partial() HalfEdge::partial()
.with_surface(Some(surface)) .with_surface(surface)
.with_back_vertex(Vertex::partial().with_surface_form( .with_back_vertex(Vertex::partial().with_surface_form(
bottom.back().surface_form().clone(), bottom.back().surface_form().clone(),
)) ))

View File

@ -97,7 +97,7 @@ impl HalfEdgeBuilder for PartialHalfEdge {
Vertex::partial().with_surface_form(surface_form) Vertex::partial().with_surface_form(surface_form)
}); });
self.with_surface(Some(surface)) self.with_surface(surface)
.with_vertices(Some(vertices)) .with_vertices(Some(vertices))
.update_as_line_segment() .update_as_line_segment()
} }

View File

@ -58,7 +58,7 @@ impl PartialCycle {
if let Some(surface) = surface { if let Some(surface) = surface {
for half_edge in &mut self.half_edges { for half_edge in &mut self.half_edges {
*half_edge = half_edge.clone().update_partial(|half_edge| { *half_edge = half_edge.clone().update_partial(|half_edge| {
half_edge.with_surface(Some(surface.clone())) half_edge.with_surface(surface.clone())
}); });
} }
} }

View File

@ -47,24 +47,22 @@ impl PartialHalfEdge {
} }
/// Update the partial half-edge with the given surface /// Update the partial half-edge with the given surface
pub fn with_surface(mut self, surface: Option<Handle<Surface>>) -> Self { pub fn with_surface(mut self, surface: Handle<Surface>) -> Self {
if let Some(surface) = surface { self.curve = self
self.curve = self.curve.update_partial(|curve| { .curve
curve.with_surface(Some(surface.clone())) .update_partial(|curve| curve.with_surface(Some(surface.clone())));
});
self.vertices = self.vertices.map(|vertex| { self.vertices = self.vertices.map(|vertex| {
vertex.update_partial(|vertex| { vertex.update_partial(|vertex| {
let surface_form = vertex.surface_form().update_partial( let surface_form =
|surface_vertex| { vertex.surface_form().update_partial(|surface_vertex| {
surface_vertex.with_surface(Some(surface.clone())) surface_vertex.with_surface(Some(surface.clone()))
}, });
);
vertex.with_surface_form(surface_form)
})
});
vertex.with_surface_form(surface_form)
})
});
}
self self
} }

View File

@ -28,7 +28,7 @@ impl Shape for fj::Sketch {
// none need to be added here. // none need to be added here.
let half_edge = HalfEdge::partial() let half_edge = HalfEdge::partial()
.with_surface(Some(surface)) .with_surface(surface)
.update_as_circle_from_radius(circle.radius(), objects)? .update_as_circle_from_radius(circle.radius(), objects)?
.build(objects)?; .build(objects)?;
let cycle = objects.cycles.insert(Cycle::new([half_edge]))?; let cycle = objects.cycles.insert(Cycle::new([half_edge]))?;