Remove `PartialVertex::with_surface_form`

This commit is contained in:
Hanno Braun 2022-11-11 16:41:15 +01:00
parent 8c1077ae2a
commit 807f824746
9 changed files with 139 additions and 125 deletions

View File

@ -199,8 +199,8 @@ mod tests {
algorithms::{reverse::Reverse, sweep::Sweep}, algorithms::{reverse::Reverse, sweep::Sweep},
builder::HalfEdgeBuilder, builder::HalfEdgeBuilder,
insert::Insert, insert::Insert,
objects::{Cycle, Face, HalfEdge, Objects, Vertex}, objects::{Cycle, Face, HalfEdge, Objects},
partial::{HasPartial, PartialSurfaceVertex}, partial::{HasPartial, PartialSurfaceVertex, PartialVertex},
}; };
#[test] #[test]
@ -218,8 +218,7 @@ 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()
@ -231,42 +230,49 @@ mod tests {
.insert(&objects)?; .insert(&objects)?;
let side_up = HalfEdge::partial() let side_up = HalfEdge::partial()
.with_surface(surface.clone()) .with_surface(surface.clone())
.with_back_vertex(Vertex::partial().with_surface_form( .with_back_vertex(PartialVertex {
bottom.front().surface_form().clone(), surface_form: bottom.front().surface_form().clone().into(),
)) ..Default::default()
.with_front_vertex(Vertex::partial().with_surface_form( })
PartialSurfaceVertex { .with_front_vertex(PartialVertex {
surface_form: PartialSurfaceVertex {
position: Some([1., 1.].into()), position: Some([1., 1.].into()),
..Default::default() ..Default::default()
}, }
)) .into(),
..Default::default()
})
.update_as_line_segment() .update_as_line_segment()
.build(&objects)? .build(&objects)?
.insert(&objects)?; .insert(&objects)?;
let top = HalfEdge::partial() let top = HalfEdge::partial()
.with_surface(surface.clone()) .with_surface(surface.clone())
.with_back_vertex(Vertex::partial().with_surface_form( .with_back_vertex(PartialVertex {
PartialSurfaceVertex { surface_form: PartialSurfaceVertex {
position: Some([0., 1.].into()), position: Some([0., 1.].into()),
..Default::default() ..Default::default()
}, }
)) .into(),
.with_front_vertex(Vertex::partial().with_surface_form( ..Default::default()
side_up.front().surface_form().clone(), })
)) .with_front_vertex(PartialVertex {
surface_form: side_up.front().surface_form().clone().into(),
..Default::default()
})
.update_as_line_segment() .update_as_line_segment()
.build(&objects)? .build(&objects)?
.insert(&objects)? .insert(&objects)?
.reverse(&objects)?; .reverse(&objects)?;
let side_down = let side_down = HalfEdge::partial()
HalfEdge::partial()
.with_surface(surface) .with_surface(surface)
.with_back_vertex(Vertex::partial().with_surface_form( .with_back_vertex(PartialVertex {
bottom.back().surface_form().clone(), surface_form: bottom.back().surface_form().clone().into(),
)) ..Default::default()
.with_front_vertex(Vertex::partial().with_surface_form( })
top.front().surface_form().clone(), .with_front_vertex(PartialVertex {
)) surface_form: top.front().surface_form().clone().into(),
..Default::default()
})
.update_as_line_segment() .update_as_line_segment()
.build(&objects)? .build(&objects)?
.insert(&objects)? .insert(&objects)?

View File

@ -25,9 +25,8 @@ impl TransformObject for PartialVertex {
Ok(Self { Ok(Self {
position: self.position, position: self.position,
curve, curve,
..Default::default() surface_form: surface_form.into(),
} })
.with_surface_form(surface_form))
} }
} }

View File

@ -75,13 +75,10 @@ impl CycleBuilder for PartialCycle {
.update_as_line_from_points([position_prev, position_next]); .update_as_line_from_points([position_prev, position_next]);
let vertices = [(0., vertex_prev), (1., vertex_next)].map( let vertices = [(0., vertex_prev), (1., vertex_next)].map(
|(position, surface_form)| { |(position, surface_form)| PartialVertex {
PartialVertex {
position: Some([position].into()), position: Some([position].into()),
curve: curve.clone().into(), curve: curve.clone().into(),
..Default::default() surface_form,
}
.with_surface_form(surface_form)
}, },
); );

View File

@ -96,13 +96,11 @@ impl HalfEdgeBuilder for PartialHalfEdge {
.build(objects)? .build(objects)?
.insert(objects)?; .insert(objects)?;
let [back, front] = [a_curve, b_curve].map(|point_curve| { let [back, front] =
PartialVertex { [a_curve, b_curve].map(|point_curve| PartialVertex {
position: Some(point_curve), position: Some(point_curve),
curve: curve.clone().into(), curve: curve.clone().into(),
..Default::default() surface_form: surface_vertex.clone().into(),
}
.with_surface_form(surface_vertex.clone())
}); });
Ok(self.with_curve(curve).with_vertices([back, front])) Ok(self.with_curve(curve).with_vertices([back, front]))
@ -120,7 +118,10 @@ impl HalfEdgeBuilder for PartialHalfEdge {
..Default::default() ..Default::default()
}; };
Vertex::partial().with_surface_form(surface_form) PartialVertex {
surface_form: surface_form.into(),
..Default::default()
}
}); });
self.with_surface(surface) self.with_surface(surface)
@ -201,18 +202,16 @@ impl HalfEdgeBuilder for PartialHalfEdge {
.zip(global_forms) .zip(global_forms)
.collect::<[_; 2]>() .collect::<[_; 2]>()
.map(|(vertex, global_form)| { .map(|(vertex, global_form)| {
vertex.update_partial(|vertex| { vertex.update_partial(|mut vertex| {
vertex.clone().with_surface_form( vertex.surface_form = vertex
vertex.surface_form.update_partial( .surface_form
|mut surface_vertex| { .update_partial(|mut surface_vertex| {
if let Some(global_form) = global_form { if let Some(global_form) = global_form {
surface_vertex.global_form = surface_vertex.global_form = global_form;
global_form;
} }
surface_vertex surface_vertex
}, });
), vertex
)
}) })
}) })
}; };

View File

@ -8,9 +8,7 @@ use crate::{
algorithms::transform::TransformObject, algorithms::transform::TransformObject,
builder::{FaceBuilder, HalfEdgeBuilder}, builder::{FaceBuilder, HalfEdgeBuilder},
insert::Insert, insert::Insert,
objects::{ objects::{Cycle, Face, FaceSet, HalfEdge, Objects, Shell, Surface},
Cycle, Face, FaceSet, HalfEdge, Objects, Shell, Surface, Vertex,
},
partial::{HasPartial, PartialCurve, PartialSurfaceVertex, PartialVertex}, partial::{HasPartial, PartialCurve, PartialSurfaceVertex, PartialVertex},
storage::Handle, storage::Handle,
}; };
@ -121,8 +119,14 @@ impl<'a> ShellBuilder<'a> {
HalfEdge::partial() HalfEdge::partial()
.with_vertices([ .with_vertices([
Vertex::partial().with_surface_form(from), PartialVertex {
Vertex::partial().with_surface_form(to), surface_form: from.into(),
..Default::default()
},
PartialVertex {
surface_form: to.into(),
..Default::default()
},
]) ])
.update_as_line_segment() .update_as_line_segment()
.build(self.objects) .build(self.objects)
@ -166,8 +170,14 @@ impl<'a> ShellBuilder<'a> {
HalfEdge::partial() HalfEdge::partial()
.with_curve(curve) .with_curve(curve)
.with_vertices([ .with_vertices([
Vertex::partial().with_surface_form(from), PartialVertex {
Vertex::partial().with_surface_form(to), surface_form: from.into(),
..Default::default()
},
PartialVertex {
surface_form: to.into(),
..Default::default()
},
]) ])
.update_as_line_segment() .update_as_line_segment()
.build(self.objects) .build(self.objects)
@ -189,8 +199,14 @@ impl<'a> ShellBuilder<'a> {
let from = from.surface_form().clone(); let from = from.surface_form().clone();
let to = to.surface_form().clone(); let to = to.surface_form().clone();
let from = Vertex::partial().with_surface_form(from); let from = PartialVertex {
let to = Vertex::partial().with_surface_form(to); surface_form: from.into(),
..Default::default()
};
let to = PartialVertex {
surface_form: to.into(),
..Default::default()
};
HalfEdge::partial() HalfEdge::partial()
.with_vertices([from, to]) .with_vertices([from, to])
@ -276,12 +292,10 @@ impl<'a> ShellBuilder<'a> {
.into_iter_fixed() .into_iter_fixed()
.zip(surface_vertices.clone()) .zip(surface_vertices.clone())
.collect::<[_; 2]>() .collect::<[_; 2]>()
.map(|(vertex, surface_form)| { .map(|(vertex, surface_form)| PartialVertex {
PartialVertex {
position: Some(vertex.position()), position: Some(vertex.position()),
surface_form: surface_form.into(),
..Default::default() ..Default::default()
}
.with_surface_form(surface_form)
}); });
edges.push( edges.push(

View File

@ -15,8 +15,9 @@ pub trait VertexBuilder {
} }
impl VertexBuilder for PartialVertex { impl VertexBuilder for PartialVertex {
fn infer_surface_form(self) -> Self { fn infer_surface_form(mut self) -> Self {
self.with_surface_form(PartialSurfaceVertex::default()) self.surface_form = PartialSurfaceVertex::default().into();
self
} }
} }

View File

@ -96,9 +96,14 @@ impl PartialCycle {
*half_edge = half_edge.clone().merge_with( *half_edge = half_edge.clone().merge_with(
PartialHalfEdge::default().with_vertices([ PartialHalfEdge::default().with_vertices([
PartialVertex::default().with_surface_form(back_vertex), PartialVertex {
PartialVertex::default() surface_form: back_vertex,
.with_surface_form(front_vertex.clone()), ..Default::default()
},
PartialVertex {
surface_form: front_vertex.clone().into(),
..Default::default()
},
]), ]),
); );
@ -111,9 +116,10 @@ impl PartialCycle {
let back_vertex = previous_vertex.unwrap_or_default(); let back_vertex = previous_vertex.unwrap_or_default();
*half_edge = half_edge.clone().merge_with( *half_edge = half_edge.clone().merge_with(
PartialHalfEdge::default().with_back_vertex( PartialHalfEdge::default().with_back_vertex(PartialVertex {
PartialVertex::default().with_surface_form(back_vertex), surface_form: back_vertex,
), ..Default::default()
}),
); );
} }

View File

@ -54,7 +54,7 @@ impl PartialHalfEdge {
}); });
self.vertices = self.vertices.map(|vertex| { self.vertices = self.vertices.map(|vertex| {
vertex.update_partial(|vertex| { vertex.update_partial(|mut vertex| {
let surface_form = vertex.surface_form.clone().update_partial( let surface_form = vertex.surface_form.clone().update_partial(
|mut surface_vertex| { |mut surface_vertex| {
surface_vertex.surface = Some(surface.clone()); surface_vertex.surface = Some(surface.clone());
@ -62,7 +62,8 @@ impl PartialHalfEdge {
}, },
); );
vertex.with_surface_form(surface_form) vertex.surface_form = surface_form;
vertex
}) })
}); });

View File

@ -24,15 +24,6 @@ pub struct PartialVertex {
} }
impl PartialVertex { impl PartialVertex {
/// Provide a surface form for the partial vertex
pub fn with_surface_form(
mut self,
surface_form: impl Into<MaybePartial<SurfaceVertex>>,
) -> Self {
self.surface_form = surface_form.into();
self
}
/// Build a full [`Vertex`] from the partial vertex /// Build a full [`Vertex`] from the partial vertex
/// ///
/// # Panics /// # Panics