Integrate SurfaceVertex into object storage

This commit is contained in:
Hanno Braun 2022-10-12 14:44:02 +02:00
parent 93cc9f6ffb
commit 415e4f9acf
11 changed files with 31 additions and 26 deletions

View File

@ -68,6 +68,7 @@ impl Sweep for (HalfEdge, Color) {
point_surface, point_surface,
surface.clone(), surface.clone(),
vertex.global_form().clone(), vertex.global_form().clone(),
objects,
); );
Vertex::new( Vertex::new(
@ -141,6 +142,7 @@ impl Sweep for (HalfEdge, Color) {
point_surface, point_surface,
surface.clone(), surface.clone(),
global_form, global_form,
objects,
); );
Vertex::new(vertex.position(), curve.clone(), surface_form) Vertex::new(vertex.position(), curve.clone(), surface_form)
}) })

View File

@ -105,6 +105,7 @@ impl Sweep for (Vertex, Handle<Surface>) {
point_surface, point_surface,
surface.clone(), surface.clone(),
vertex_global, vertex_global,
objects,
) )
}, },
); );

View File

@ -202,6 +202,7 @@ mod tests {
point_surface, point_surface,
surface.clone(), surface.clone(),
vertex_global, vertex_global,
&objects,
) )
}, },
) )

View File

@ -85,7 +85,7 @@ impl<'a> ShellBuilder<'a> {
let [_, from] = bottom.vertices(); let [_, from] = bottom.vertices();
let from = from.surface_form().clone(); let from = from.surface_form().clone();
let to = SurfaceVertex::partial() let to = Handle::<SurfaceVertex>::partial()
.with_position(Some(from.position() + [Z, edge_length])) .with_position(Some(from.position() + [Z, edge_length]))
.with_surface(Some(surface.clone())); .with_surface(Some(surface.clone()));
@ -113,7 +113,7 @@ impl<'a> ShellBuilder<'a> {
let [to, _] = bottom.vertices(); let [to, _] = bottom.vertices();
let to = to.surface_form().clone(); let to = to.surface_form().clone();
let from = SurfaceVertex::partial() let from = Handle::<SurfaceVertex>::partial()
.with_position(Some( .with_position(Some(
to.position() + [Z, edge_length], to.position() + [Z, edge_length],
)) ))
@ -147,7 +147,7 @@ impl<'a> ShellBuilder<'a> {
let [to, _] = side_down.vertices(); let [to, _] = side_down.vertices();
let from = from.surface_form().clone(); let from = from.surface_form().clone();
let to = SurfaceVertex::partial() let to = Handle::<SurfaceVertex>::partial()
.with_position(Some( .with_position(Some(
from.position() + [-edge_length, Z], from.position() + [-edge_length, Z],
)) ))
@ -206,7 +206,7 @@ impl<'a> ShellBuilder<'a> {
let [vertex_a, vertex_b] = edge.vertices().clone(); let [vertex_a, vertex_b] = edge.vertices().clone();
let vertices = [(point_a, vertex_a), (point_b, vertex_b)].map( let vertices = [(point_a, vertex_a), (point_b, vertex_b)].map(
|(point, vertex)| { |(point, vertex)| {
let surface_form = SurfaceVertex::partial() let surface_form = Handle::<SurfaceVertex>::partial()
.with_position(Some(point)) .with_position(Some(point))
.with_surface(Some(surface.clone())) .with_surface(Some(surface.clone()))
.with_global_form(Some( .with_global_form(Some(

View File

@ -590,7 +590,7 @@ mod tests {
.build(&objects); .build(&objects);
let global_vertex = GlobalVertex::from_position([0., 0., 0.], &objects); let global_vertex = GlobalVertex::from_position([0., 0., 0.], &objects);
let surface_vertex = let surface_vertex =
SurfaceVertex::new([0., 0.], surface, global_vertex); SurfaceVertex::new([0., 0.], surface, global_vertex, &objects);
let object = Vertex::new([0.], curve, surface_vertex); let object = Vertex::new([0.], curve, surface_vertex);
assert_eq!(1, object.curve_iter().count()); assert_eq!(1, object.curve_iter().count());

View File

@ -14,7 +14,7 @@ use super::{Curve, Objects, Surface};
pub struct Vertex { pub struct Vertex {
position: Point<1>, position: Point<1>,
curve: Handle<Curve>, curve: Handle<Curve>,
surface_form: SurfaceVertex, surface_form: Handle<SurfaceVertex>,
} }
impl Vertex { impl Vertex {
@ -25,7 +25,7 @@ impl Vertex {
pub fn new( pub fn new(
position: impl Into<Point<1>>, position: impl Into<Point<1>>,
curve: Handle<Curve>, curve: Handle<Curve>,
surface_form: SurfaceVertex, surface_form: Handle<SurfaceVertex>,
) -> Self { ) -> Self {
let position = position.into(); let position = position.into();
@ -53,7 +53,7 @@ impl Vertex {
} }
/// Access the surface form of this vertex /// Access the surface form of this vertex
pub fn surface_form(&self) -> &SurfaceVertex { pub fn surface_form(&self) -> &Handle<SurfaceVertex> {
&self.surface_form &self.surface_form
} }
@ -77,13 +77,14 @@ impl SurfaceVertex {
position: impl Into<Point<2>>, position: impl Into<Point<2>>,
surface: Handle<Surface>, surface: Handle<Surface>,
global_form: Handle<GlobalVertex>, global_form: Handle<GlobalVertex>,
) -> Self { objects: &Objects,
) -> Handle<Self> {
let position = position.into(); let position = position.into();
Self { objects.surface_vertices.insert(Self {
position, position,
surface, surface,
global_form, global_form,
} })
} }
/// Access the position of the vertex on the surface /// Access the position of the vertex on the surface

View File

@ -116,7 +116,7 @@ impl MaybePartial<HalfEdge> {
} }
} }
impl MaybePartial<SurfaceVertex> { impl MaybePartial<Handle<SurfaceVertex>> {
/// Access the position /// Access the position
pub fn position(&self) -> Option<Point<2>> { pub fn position(&self) -> Option<Point<2>> {
match self { match self {
@ -136,7 +136,7 @@ impl MaybePartial<SurfaceVertex> {
impl MaybePartial<Vertex> { impl MaybePartial<Vertex> {
/// Access the surface form /// Access the surface form
pub fn surface_form(&self) -> Option<MaybePartial<SurfaceVertex>> { pub fn surface_form(&self) -> Option<MaybePartial<Handle<SurfaceVertex>>> {
match self { match self {
Self::Full(full) => Some(full.surface_form().clone().into()), Self::Full(full) => Some(full.surface_form().clone().into()),
Self::Partial(partial) => partial.surface_form.clone(), Self::Partial(partial) => partial.surface_form.clone(),

View File

@ -42,7 +42,7 @@ impl PartialCycle {
/// Update the partial cycle with a polygonal chain from the provided points /// Update the partial cycle with a polygonal chain from the provided points
pub fn with_poly_chain( pub fn with_poly_chain(
mut self, mut self,
vertices: impl IntoIterator<Item = MaybePartial<SurfaceVertex>>, vertices: impl IntoIterator<Item = MaybePartial<Handle<SurfaceVertex>>>,
) -> Self { ) -> Self {
let iter = self let iter = self
.half_edges .half_edges
@ -57,7 +57,7 @@ impl PartialCycle {
.into_iter() .into_iter()
.chain(vertices); .chain(vertices);
let mut previous: Option<MaybePartial<SurfaceVertex>> = None; let mut previous: Option<MaybePartial<Handle<SurfaceVertex>>> = None;
for vertex_next in iter { for vertex_next in iter {
if let Some(vertex_prev) = previous { if let Some(vertex_prev) = previous {
@ -116,7 +116,7 @@ impl PartialCycle {
points: impl IntoIterator<Item = impl Into<Point<2>>>, points: impl IntoIterator<Item = impl Into<Point<2>>>,
) -> Self { ) -> Self {
self.with_poly_chain(points.into_iter().map(|position| { self.with_poly_chain(points.into_iter().map(|position| {
SurfaceVertex::partial() Handle::<SurfaceVertex>::partial()
.with_position(Some(position)) .with_position(Some(position))
.into() .into()
})) }))

View File

@ -122,7 +122,7 @@ impl PartialHalfEdge {
.from_curve_and_position(curve.clone(), a_curve); .from_curve_and_position(curve.clone(), a_curve);
let path = curve.path.expect("Expected path that was just created"); let path = curve.path.expect("Expected path that was just created");
let surface_form = SurfaceVertex::partial() let surface_form = Handle::<SurfaceVertex>::partial()
.with_position(Some(path.point_from_path_coords(a_curve))) .with_position(Some(path.point_from_path_coords(a_curve)))
.with_global_form(Some(global_form)); .with_global_form(Some(global_form));
@ -148,7 +148,7 @@ impl PartialHalfEdge {
) -> Self { ) -> Self {
let surface = self.surface.clone(); let surface = self.surface.clone();
let vertices = points.map(|point| { let vertices = points.map(|point| {
let surface_form = SurfaceVertex::partial() let surface_form = Handle::<SurfaceVertex>::partial()
.with_surface(surface.clone()) .with_surface(surface.clone())
.with_position(Some(point)); .with_position(Some(point));
Vertex::partial().with_surface_form(Some(surface_form)) Vertex::partial().with_surface_form(Some(surface_form))

View File

@ -47,6 +47,6 @@ impl_traits!(
GlobalEdge, PartialGlobalEdge; GlobalEdge, PartialGlobalEdge;
Handle<GlobalVertex>, PartialGlobalVertex; Handle<GlobalVertex>, PartialGlobalVertex;
HalfEdge, PartialHalfEdge; HalfEdge, PartialHalfEdge;
SurfaceVertex, PartialSurfaceVertex; Handle<SurfaceVertex>, PartialSurfaceVertex;
Vertex, PartialVertex; Vertex, PartialVertex;
); );

View File

@ -25,7 +25,7 @@ pub struct PartialVertex {
/// ///
/// Can be provided, if already available, or computed from the position on /// Can be provided, if already available, or computed from the position on
/// the [`Curve`]. /// the [`Curve`].
pub surface_form: Option<MaybePartial<SurfaceVertex>>, pub surface_form: Option<MaybePartial<Handle<SurfaceVertex>>>,
/// The global form of the [`Vertex`] /// The global form of the [`Vertex`]
/// ///
@ -60,7 +60,7 @@ impl PartialVertex {
/// Provide a surface form for the partial vertex /// Provide a surface form for the partial vertex
pub fn with_surface_form( pub fn with_surface_form(
mut self, mut self,
surface_form: Option<impl Into<MaybePartial<SurfaceVertex>>>, surface_form: Option<impl Into<MaybePartial<Handle<SurfaceVertex>>>>,
) -> Self { ) -> Self {
if let Some(surface_form) = surface_form { if let Some(surface_form) = surface_form {
self.surface_form = Some(surface_form.into()); self.surface_form = Some(surface_form.into());
@ -97,7 +97,7 @@ impl PartialVertex {
let surface_form = self let surface_form = self
.surface_form .surface_form
.unwrap_or_else(|| SurfaceVertex::partial().into()) .unwrap_or_else(|| Handle::<SurfaceVertex>::partial().into())
.update_partial(|partial| { .update_partial(|partial| {
let position = partial.position.unwrap_or_else(|| { let position = partial.position.unwrap_or_else(|| {
curve.path().point_from_path_coords(position) curve.path().point_from_path_coords(position)
@ -185,7 +185,7 @@ impl PartialSurfaceVertex {
/// Panics, if no position has been provided. /// Panics, if no position has been provided.
/// ///
/// Panics, if no surface has been provided. /// Panics, if no surface has been provided.
pub fn build(self, objects: &Objects) -> SurfaceVertex { pub fn build(self, objects: &Objects) -> Handle<SurfaceVertex> {
let position = self let position = self
.position .position
.expect("Can't build `SurfaceVertex` without position"); .expect("Can't build `SurfaceVertex` without position");
@ -202,12 +202,12 @@ impl PartialSurfaceVertex {
}) })
.into_full(objects); .into_full(objects);
SurfaceVertex::new(position, surface, global_form) SurfaceVertex::new(position, surface, global_form, objects)
} }
} }
impl From<&SurfaceVertex> for PartialSurfaceVertex { impl From<&Handle<SurfaceVertex>> for PartialSurfaceVertex {
fn from(surface_vertex: &SurfaceVertex) -> Self { fn from(surface_vertex: &Handle<SurfaceVertex>) -> Self {
Self { Self {
position: Some(surface_vertex.position()), position: Some(surface_vertex.position()),
surface: Some(surface_vertex.surface().clone()), surface: Some(surface_vertex.surface().clone()),