From 93cc9f6ffbc35b88a8aa2d1dd0349ed845151c2d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 12 Oct 2022 14:38:34 +0200 Subject: [PATCH 1/2] Add `surface_vertices` field to `Objects` --- crates/fj-kernel/src/objects/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/fj-kernel/src/objects/mod.rs b/crates/fj-kernel/src/objects/mod.rs index 7f6ccc080..8774ee9aa 100644 --- a/crates/fj-kernel/src/objects/mod.rs +++ b/crates/fj-kernel/src/objects/mod.rs @@ -121,6 +121,9 @@ pub struct Objects { /// Store for global vertices pub global_vertices: Store, + /// Store for surface vertices + pub surface_vertices: Store, + /// Store for surfaces pub surfaces: Surfaces, } From 415e4f9acf37a117cf78c654b0304a92aa662ef8 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 12 Oct 2022 14:44:02 +0200 Subject: [PATCH 2/2] Integrate `SurfaceVertex` into object storage --- crates/fj-kernel/src/algorithms/sweep/edge.rs | 2 ++ crates/fj-kernel/src/algorithms/sweep/vertex.rs | 1 + crates/fj-kernel/src/algorithms/validate/mod.rs | 1 + crates/fj-kernel/src/builder/shell.rs | 8 ++++---- crates/fj-kernel/src/iter.rs | 2 +- crates/fj-kernel/src/objects/vertex.rs | 13 +++++++------ crates/fj-kernel/src/partial/maybe_partial.rs | 4 ++-- crates/fj-kernel/src/partial/objects/cycle.rs | 6 +++--- crates/fj-kernel/src/partial/objects/edge.rs | 4 ++-- crates/fj-kernel/src/partial/objects/mod.rs | 2 +- crates/fj-kernel/src/partial/objects/vertex.rs | 14 +++++++------- 11 files changed, 31 insertions(+), 26 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index fd4700225..5bbd90650 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -68,6 +68,7 @@ impl Sweep for (HalfEdge, Color) { point_surface, surface.clone(), vertex.global_form().clone(), + objects, ); Vertex::new( @@ -141,6 +142,7 @@ impl Sweep for (HalfEdge, Color) { point_surface, surface.clone(), global_form, + objects, ); Vertex::new(vertex.position(), curve.clone(), surface_form) }) diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index 3e478bf8e..4238bd58a 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -105,6 +105,7 @@ impl Sweep for (Vertex, Handle) { point_surface, surface.clone(), vertex_global, + objects, ) }, ); diff --git a/crates/fj-kernel/src/algorithms/validate/mod.rs b/crates/fj-kernel/src/algorithms/validate/mod.rs index 248bd3a87..7f1de802b 100644 --- a/crates/fj-kernel/src/algorithms/validate/mod.rs +++ b/crates/fj-kernel/src/algorithms/validate/mod.rs @@ -202,6 +202,7 @@ mod tests { point_surface, surface.clone(), vertex_global, + &objects, ) }, ) diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 8ae87cabf..606820b5f 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -85,7 +85,7 @@ impl<'a> ShellBuilder<'a> { let [_, from] = bottom.vertices(); let from = from.surface_form().clone(); - let to = SurfaceVertex::partial() + let to = Handle::::partial() .with_position(Some(from.position() + [Z, edge_length])) .with_surface(Some(surface.clone())); @@ -113,7 +113,7 @@ impl<'a> ShellBuilder<'a> { let [to, _] = bottom.vertices(); let to = to.surface_form().clone(); - let from = SurfaceVertex::partial() + let from = Handle::::partial() .with_position(Some( to.position() + [Z, edge_length], )) @@ -147,7 +147,7 @@ impl<'a> ShellBuilder<'a> { let [to, _] = side_down.vertices(); let from = from.surface_form().clone(); - let to = SurfaceVertex::partial() + let to = Handle::::partial() .with_position(Some( from.position() + [-edge_length, Z], )) @@ -206,7 +206,7 @@ impl<'a> ShellBuilder<'a> { let [vertex_a, vertex_b] = edge.vertices().clone(); let vertices = [(point_a, vertex_a), (point_b, vertex_b)].map( |(point, vertex)| { - let surface_form = SurfaceVertex::partial() + let surface_form = Handle::::partial() .with_position(Some(point)) .with_surface(Some(surface.clone())) .with_global_form(Some( diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index b74e453ef..30440a526 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -590,7 +590,7 @@ mod tests { .build(&objects); let global_vertex = GlobalVertex::from_position([0., 0., 0.], &objects); 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); assert_eq!(1, object.curve_iter().count()); diff --git a/crates/fj-kernel/src/objects/vertex.rs b/crates/fj-kernel/src/objects/vertex.rs index 91a36935a..96f9ba88c 100644 --- a/crates/fj-kernel/src/objects/vertex.rs +++ b/crates/fj-kernel/src/objects/vertex.rs @@ -14,7 +14,7 @@ use super::{Curve, Objects, Surface}; pub struct Vertex { position: Point<1>, curve: Handle, - surface_form: SurfaceVertex, + surface_form: Handle, } impl Vertex { @@ -25,7 +25,7 @@ impl Vertex { pub fn new( position: impl Into>, curve: Handle, - surface_form: SurfaceVertex, + surface_form: Handle, ) -> Self { let position = position.into(); @@ -53,7 +53,7 @@ impl Vertex { } /// Access the surface form of this vertex - pub fn surface_form(&self) -> &SurfaceVertex { + pub fn surface_form(&self) -> &Handle { &self.surface_form } @@ -77,13 +77,14 @@ impl SurfaceVertex { position: impl Into>, surface: Handle, global_form: Handle, - ) -> Self { + objects: &Objects, + ) -> Handle { let position = position.into(); - Self { + objects.surface_vertices.insert(Self { position, surface, global_form, - } + }) } /// Access the position of the vertex on the surface diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index 19a2c31f4..973f0ccb6 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -116,7 +116,7 @@ impl MaybePartial { } } -impl MaybePartial { +impl MaybePartial> { /// Access the position pub fn position(&self) -> Option> { match self { @@ -136,7 +136,7 @@ impl MaybePartial { impl MaybePartial { /// Access the surface form - pub fn surface_form(&self) -> Option> { + pub fn surface_form(&self) -> Option>> { match self { Self::Full(full) => Some(full.surface_form().clone().into()), Self::Partial(partial) => partial.surface_form.clone(), diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index d27d35626..f918b685d 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -42,7 +42,7 @@ impl PartialCycle { /// Update the partial cycle with a polygonal chain from the provided points pub fn with_poly_chain( mut self, - vertices: impl IntoIterator>, + vertices: impl IntoIterator>>, ) -> Self { let iter = self .half_edges @@ -57,7 +57,7 @@ impl PartialCycle { .into_iter() .chain(vertices); - let mut previous: Option> = None; + let mut previous: Option>> = None; for vertex_next in iter { if let Some(vertex_prev) = previous { @@ -116,7 +116,7 @@ impl PartialCycle { points: impl IntoIterator>>, ) -> Self { self.with_poly_chain(points.into_iter().map(|position| { - SurfaceVertex::partial() + Handle::::partial() .with_position(Some(position)) .into() })) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 32688a371..ab8a77be2 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -122,7 +122,7 @@ impl PartialHalfEdge { .from_curve_and_position(curve.clone(), a_curve); let path = curve.path.expect("Expected path that was just created"); - let surface_form = SurfaceVertex::partial() + let surface_form = Handle::::partial() .with_position(Some(path.point_from_path_coords(a_curve))) .with_global_form(Some(global_form)); @@ -148,7 +148,7 @@ impl PartialHalfEdge { ) -> Self { let surface = self.surface.clone(); let vertices = points.map(|point| { - let surface_form = SurfaceVertex::partial() + let surface_form = Handle::::partial() .with_surface(surface.clone()) .with_position(Some(point)); Vertex::partial().with_surface_form(Some(surface_form)) diff --git a/crates/fj-kernel/src/partial/objects/mod.rs b/crates/fj-kernel/src/partial/objects/mod.rs index 043366bbe..d04f50b29 100644 --- a/crates/fj-kernel/src/partial/objects/mod.rs +++ b/crates/fj-kernel/src/partial/objects/mod.rs @@ -47,6 +47,6 @@ impl_traits!( GlobalEdge, PartialGlobalEdge; Handle, PartialGlobalVertex; HalfEdge, PartialHalfEdge; - SurfaceVertex, PartialSurfaceVertex; + Handle, PartialSurfaceVertex; Vertex, PartialVertex; ); diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 0a3513dae..8d3784649 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -25,7 +25,7 @@ pub struct PartialVertex { /// /// Can be provided, if already available, or computed from the position on /// the [`Curve`]. - pub surface_form: Option>, + pub surface_form: Option>>, /// The global form of the [`Vertex`] /// @@ -60,7 +60,7 @@ impl PartialVertex { /// Provide a surface form for the partial vertex pub fn with_surface_form( mut self, - surface_form: Option>>, + surface_form: Option>>>, ) -> Self { if let Some(surface_form) = surface_form { self.surface_form = Some(surface_form.into()); @@ -97,7 +97,7 @@ impl PartialVertex { let surface_form = self .surface_form - .unwrap_or_else(|| SurfaceVertex::partial().into()) + .unwrap_or_else(|| Handle::::partial().into()) .update_partial(|partial| { let position = partial.position.unwrap_or_else(|| { curve.path().point_from_path_coords(position) @@ -185,7 +185,7 @@ impl PartialSurfaceVertex { /// Panics, if no position has been provided. /// /// Panics, if no surface has been provided. - pub fn build(self, objects: &Objects) -> SurfaceVertex { + pub fn build(self, objects: &Objects) -> Handle { let position = self .position .expect("Can't build `SurfaceVertex` without position"); @@ -202,12 +202,12 @@ impl PartialSurfaceVertex { }) .into_full(objects); - SurfaceVertex::new(position, surface, global_form) + SurfaceVertex::new(position, surface, global_form, objects) } } -impl From<&SurfaceVertex> for PartialSurfaceVertex { - fn from(surface_vertex: &SurfaceVertex) -> Self { +impl From<&Handle> for PartialSurfaceVertex { + fn from(surface_vertex: &Handle) -> Self { Self { position: Some(surface_vertex.position()), surface: Some(surface_vertex.surface().clone()),