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},
builder::HalfEdgeBuilder,
insert::Insert,
objects::{Cycle, Face, HalfEdge, Objects, Vertex},
partial::{HasPartial, PartialSurfaceVertex},
objects::{Cycle, Face, HalfEdge, Objects},
partial::{HasPartial, PartialSurfaceVertex, PartialVertex},
};
#[test]
@ -218,69 +218,75 @@ mod tests {
let face =
(half_edge, Color::default()).sweep([0., 0., 1.], &objects)?;
let expected_face =
{
let surface = objects.surfaces.xz_plane();
let expected_face = {
let surface = objects.surfaces.xz_plane();
let bottom = HalfEdge::partial()
.update_as_line_segment_from_points(
surface.clone(),
[[0., 0.], [1., 0.]],
)
.build(&objects)?
.insert(&objects)?;
let side_up = HalfEdge::partial()
.with_surface(surface.clone())
.with_back_vertex(Vertex::partial().with_surface_form(
bottom.front().surface_form().clone(),
))
.with_front_vertex(Vertex::partial().with_surface_form(
PartialSurfaceVertex {
position: Some([1., 1.].into()),
..Default::default()
},
))
.update_as_line_segment()
.build(&objects)?
.insert(&objects)?;
let top = HalfEdge::partial()
.with_surface(surface.clone())
.with_back_vertex(Vertex::partial().with_surface_form(
PartialSurfaceVertex {
position: Some([0., 1.].into()),
..Default::default()
},
))
.with_front_vertex(Vertex::partial().with_surface_form(
side_up.front().surface_form().clone(),
))
.update_as_line_segment()
.build(&objects)?
.insert(&objects)?
.reverse(&objects)?;
let side_down =
HalfEdge::partial()
.with_surface(surface)
.with_back_vertex(Vertex::partial().with_surface_form(
bottom.back().surface_form().clone(),
))
.with_front_vertex(Vertex::partial().with_surface_form(
top.front().surface_form().clone(),
))
.update_as_line_segment()
.build(&objects)?
.insert(&objects)?
.reverse(&objects)?;
let bottom = HalfEdge::partial()
.update_as_line_segment_from_points(
surface.clone(),
[[0., 0.], [1., 0.]],
)
.build(&objects)?
.insert(&objects)?;
let side_up = HalfEdge::partial()
.with_surface(surface.clone())
.with_back_vertex(PartialVertex {
surface_form: bottom.front().surface_form().clone().into(),
..Default::default()
})
.with_front_vertex(PartialVertex {
surface_form: PartialSurfaceVertex {
position: Some([1., 1.].into()),
..Default::default()
}
.into(),
..Default::default()
})
.update_as_line_segment()
.build(&objects)?
.insert(&objects)?;
let top = HalfEdge::partial()
.with_surface(surface.clone())
.with_back_vertex(PartialVertex {
surface_form: PartialSurfaceVertex {
position: Some([0., 1.].into()),
..Default::default()
}
.into(),
..Default::default()
})
.with_front_vertex(PartialVertex {
surface_form: side_up.front().surface_form().clone().into(),
..Default::default()
})
.update_as_line_segment()
.build(&objects)?
.insert(&objects)?
.reverse(&objects)?;
let side_down = HalfEdge::partial()
.with_surface(surface)
.with_back_vertex(PartialVertex {
surface_form: bottom.back().surface_form().clone().into(),
..Default::default()
})
.with_front_vertex(PartialVertex {
surface_form: top.front().surface_form().clone().into(),
..Default::default()
})
.update_as_line_segment()
.build(&objects)?
.insert(&objects)?
.reverse(&objects)?;
let cycle = objects
.cycles
.insert(Cycle::new([bottom, side_up, top, side_down]))?;
let cycle = objects
.cycles
.insert(Cycle::new([bottom, side_up, top, side_down]))?;
Face::partial()
.with_exterior(cycle)
.build(&objects)?
.insert(&objects)?
};
Face::partial()
.with_exterior(cycle)
.build(&objects)?
.insert(&objects)?
};
assert_eq!(face, expected_face);
Ok(())

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -96,9 +96,14 @@ impl PartialCycle {
*half_edge = half_edge.clone().merge_with(
PartialHalfEdge::default().with_vertices([
PartialVertex::default().with_surface_form(back_vertex),
PartialVertex::default()
.with_surface_form(front_vertex.clone()),
PartialVertex {
surface_form: back_vertex,
..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();
*half_edge = half_edge.clone().merge_with(
PartialHalfEdge::default().with_back_vertex(
PartialVertex::default().with_surface_form(back_vertex),
),
PartialHalfEdge::default().with_back_vertex(PartialVertex {
surface_form: back_vertex,
..Default::default()
}),
);
}

View File

@ -54,7 +54,7 @@ impl PartialHalfEdge {
});
self.vertices = self.vertices.map(|vertex| {
vertex.update_partial(|vertex| {
vertex.update_partial(|mut vertex| {
let surface_form = vertex.surface_form.clone().update_partial(
|mut surface_vertex| {
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 {
/// 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
///
/// # Panics