From 9fdf6ff11ca139cd5c2f479dd3f25d29d2c6c430 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 14 Oct 2022 15:03:37 +0200 Subject: [PATCH 1/8] Update variable names to current nomenclature --- crates/fj-kernel/src/partial/objects/cycle.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index f4df40e7c..2d0bedd8d 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -201,8 +201,8 @@ impl PartialCycle { |(mut half_edges, previous_vertex), half_edge| { let half_edge = half_edge .update_partial(|half_edge| { - let [from, _] = half_edge.vertices.clone(); - let from = from.map(|vertex| { + let [back, _] = half_edge.vertices.clone(); + let back = back.map(|vertex| { vertex.update_partial(|partial| { partial.with_surface_form(previous_vertex) }) @@ -210,7 +210,7 @@ impl PartialCycle { half_edge .with_surface(Some(surface_for_edges.clone())) - .with_back_vertex(from) + .with_back_vertex(back) }) .into_full(objects); From b5dabfb11c8016e6c21f6280a54ac141ace08dda Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 14 Oct 2022 15:21:52 +0200 Subject: [PATCH 2/8] Update variable names to current nomenclature --- crates/fj-kernel/src/partial/objects/edge.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 18f8416cd..9762b0668 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -229,12 +229,13 @@ impl PartialHalfEdge { impl From<&HalfEdge> for PartialHalfEdge { fn from(half_edge: &HalfEdge) -> Self { - let [a, b] = half_edge.vertices().clone().map(Into::into); + let [back_vertex, front_vertex] = + half_edge.vertices().clone().map(Into::into); Self { surface: Some(half_edge.curve().surface().clone()), curve: Some(half_edge.curve().clone().into()), - vertices: [Some(a), Some(b)], + vertices: [Some(back_vertex), Some(front_vertex)], global_form: Some(half_edge.global_form().clone().into()), } } From 740f8a8793c908eb5a61eb7e96e680db3b70f2d0 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 14 Oct 2022 15:30:53 +0200 Subject: [PATCH 3/8] Update variable names to current nomenclature --- crates/fj-kernel/src/partial/objects/edge.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 9762b0668..a9662e200 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -90,8 +90,8 @@ impl PartialHalfEdge { vertices: Option<[impl Into>; 2]>, ) -> Self { let vertices = vertices.map(|vertices| vertices.map(Into::into)); - if let Some([a, b]) = vertices { - self.vertices = [Some(a), Some(b)]; + if let Some([back, front]) = vertices { + self.vertices = [Some(back), Some(front)]; } self } From b4739e0035aaede964ae1281cb4a987efe7b493c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 14 Oct 2022 15:31:57 +0200 Subject: [PATCH 4/8] Update variable names to current nomenclature --- crates/fj-kernel/src/partial/objects/edge.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index a9662e200..a7bcbb84f 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -114,7 +114,7 @@ impl PartialHalfEdge { .with_surface(self.surface.clone()) .as_circle_from_radius(radius); - let [a, b] = { + let [back, front] = { let [a_curve, b_curve] = [Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord])); @@ -136,7 +136,7 @@ impl PartialHalfEdge { }; self.curve = Some(curve.into()); - self.vertices = [Some(a), Some(b)]; + self.vertices = [Some(back), Some(front)]; self } From b990e76433936321abb196d9d81e3192a482553d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 14 Oct 2022 15:33:06 +0200 Subject: [PATCH 5/8] Update variable names to current nomenclature --- crates/fj-kernel/src/partial/objects/edge.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index a7bcbb84f..01456718c 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -186,7 +186,7 @@ impl PartialHalfEdge { .with_surface(Some(surface)) .as_line_from_points(points); - let [a, b] = [(from, 0.), (to, 1.)].map(|(vertex, position)| { + let [back, front] = [(from, 0.), (to, 1.)].map(|(vertex, position)| { vertex.update_partial(|vertex| { vertex .with_position(Some([position])) @@ -195,7 +195,7 @@ impl PartialHalfEdge { }); self.curve = Some(curve.into()); - self.vertices = [Some(a), Some(b)]; + self.vertices = [Some(back), Some(front)]; self } From d9500cc989d931a1386d4853c0c0c6ea857a629a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 18 Oct 2022 16:31:13 +0200 Subject: [PATCH 6/8] Fix `SurfaceVertex` duplication in `ShellBuilder` --- crates/fj-kernel/src/builder/shell.rs | 55 +++++++++++++++++---------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 51ef668bf..200f20fcc 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -183,39 +183,54 @@ impl<'a> ShellBuilder<'a> { .xy_plane() .translate([Z, Z, h], self.objects); - let points = [[-h, -h], [-h, h], [h, h], [h, -h], [-h, -h]]; - let mut top_edges = top_edges; top_edges.reverse(); - let mut vertex_prev = None; + let surface_vertices = { + let mut edges = top_edges.iter(); + + let a = edges.next().unwrap(); + let b = edges.next().unwrap(); + let c = edges.next().unwrap(); + let d = edges.next().unwrap(); + + // Can be cleaned up, once `zip` is stable: + // https://doc.rust-lang.org/std/primitive.array.html#method.zip + let [a, b, c, d] = + [([-h, -h], a), ([-h, h], b), ([h, h], c), ([h, -h], d)] + .map(|(point, edge)| { + let vertex = edge.back(); + + Handle::::partial() + .with_position(Some(point)) + .with_surface(Some(surface.clone())) + .with_global_form(Some( + vertex.global_form().clone(), + )) + .build(self.objects) + }); + + [a.clone(), b, c, d, a] + }; let mut edges = Vec::new(); - for (points, edge) in points.windows(2).zip(top_edges) { + for (surface_vertices, edge) in + surface_vertices.windows(2).zip(top_edges) + { // This can't panic, as we passed `2` to `windows`. Can be // cleaned up, once `array_windows` is stable. - let points = [points[0], points[1]]; + let surface_vertices = + [surface_vertices[0].clone(), surface_vertices[1].clone()]; // Can be cleaned up, once `zip` is stable: // https://doc.rust-lang.org/std/primitive.array.html#method.zip - let [point_a, point_b] = points; let [vertex_a, vertex_b] = edge.vertices().clone(); + let [surface_vertex_a, surface_vertex_b] = surface_vertices; let vertices = [ - (point_a, vertex_a, vertex_prev.clone()), - (point_b, vertex_b, None), + (vertex_a, surface_vertex_a), + (vertex_b, surface_vertex_b), ] - .map(|(point, vertex, surface_form)| { - let surface_form = surface_form.unwrap_or_else(|| { - Handle::::partial() - .with_position(Some(point)) - .with_surface(Some(surface.clone())) - .with_global_form(Some( - vertex.global_form().clone(), - )) - .build(self.objects) - }); - vertex_prev = Some(surface_form.clone()); - + .map(|(vertex, surface_form)| { Vertex::partial() .with_position(Some(vertex.position())) .with_surface_form(Some(surface_form)) From cd8ebedae7568eb5905789151cf25cb61c8c0232 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 18 Oct 2022 16:51:42 +0200 Subject: [PATCH 7/8] Fix object duplication issue in `PartialHalfEdge` --- crates/fj-kernel/src/partial/objects/edge.rs | 16 ++++++++++++++-- crates/fj-operations/src/sketch.rs | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 01456718c..b5c2793e0 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -108,7 +108,17 @@ impl PartialHalfEdge { } /// Update partial half-edge as a circle, from the given radius - pub fn as_circle_from_radius(mut self, radius: impl Into) -> Self { + /// + /// # Implementation Note + /// + /// In principle, only the `build` method should take a reference to + /// [`Objects`]. As of this writing, this method is the only one that + /// deviates from that. I couldn't think of a way to do it better. + pub fn as_circle_from_radius( + mut self, + radius: impl Into, + objects: &Objects, + ) -> Self { let curve = Handle::::partial() .with_global_form(self.extract_global_curve()) .with_surface(self.surface.clone()) @@ -124,7 +134,9 @@ impl PartialHalfEdge { let path = curve.path.expect("Expected path that was just created"); let surface_form = Handle::::partial() .with_position(Some(path.point_from_path_coords(a_curve))) - .with_global_form(Some(global_form)); + .with_surface(self.surface.clone()) + .with_global_form(Some(global_form)) + .build(objects); [a_curve, b_curve].map(|point_curve| { Vertex::partial() diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 814f00952..d9d55f91e 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -28,7 +28,7 @@ impl Shape for fj::Sketch { let half_edge = HalfEdge::partial() .with_surface(Some(surface.clone())) - .as_circle_from_radius(circle.radius()) + .as_circle_from_radius(circle.radius(), objects) .build(objects); let cycle = Cycle::new(surface, [half_edge]); From 7ea5a827c15a8a9532bbeaa18516a077451098aa Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 12 Oct 2022 16:37:26 +0200 Subject: [PATCH 8/8] Increase strictness of cycle validation --- crates/fj-kernel/src/objects/cycle.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/objects/cycle.rs b/crates/fj-kernel/src/objects/cycle.rs index a2a527acc..fbde789c0 100644 --- a/crates/fj-kernel/src/objects/cycle.rs +++ b/crates/fj-kernel/src/objects/cycle.rs @@ -62,8 +62,8 @@ impl Cycle { let [_, last] = last.vertices(); assert_eq!( - first.surface_form(), - last.surface_form(), + first.surface_form().id(), + last.surface_form().id(), "Edges do not form a cycle" ); }