From b59e6947afafc6d1a4dbb12daccd99adda24025a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 7 Sep 2022 12:00:30 +0200 Subject: [PATCH 1/3] Derive `Debug` for `RangeOnCurve` --- crates/fj-kernel/src/algorithms/approx/curve.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/algorithms/approx/curve.rs b/crates/fj-kernel/src/algorithms/approx/curve.rs index 708bec430..c0e7dafa2 100644 --- a/crates/fj-kernel/src/algorithms/approx/curve.rs +++ b/crates/fj-kernel/src/algorithms/approx/curve.rs @@ -102,7 +102,7 @@ fn number_of_vertices_for_circle( } /// The range on which a curve should be approximated -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] pub struct RangeOnCurve { /// The boundary of the range /// From 34a8ba19caed2de203db1f7de56c7537e332df24 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 7 Sep 2022 17:14:21 +0200 Subject: [PATCH 2/3] Add `Edge::reverse_including_curve` --- .../fj-kernel/src/algorithms/reverse/edge.rs | 5 +--- crates/fj-kernel/src/objects/edge.rs | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/reverse/edge.rs b/crates/fj-kernel/src/algorithms/reverse/edge.rs index 623a67c12..2543c5e43 100644 --- a/crates/fj-kernel/src/algorithms/reverse/edge.rs +++ b/crates/fj-kernel/src/algorithms/reverse/edge.rs @@ -4,9 +4,6 @@ use super::Reverse; impl Reverse for Edge { fn reverse(self) -> Self { - Edge::from_curve_and_vertices( - self.curve().reverse(), - self.vertices().reverse(), - ) + self.reverse_including_curve() } } diff --git a/crates/fj-kernel/src/objects/edge.rs b/crates/fj-kernel/src/objects/edge.rs index 0e92e8f26..dc9ec2a17 100644 --- a/crates/fj-kernel/src/objects/edge.rs +++ b/crates/fj-kernel/src/objects/edge.rs @@ -72,6 +72,34 @@ impl Edge { Self::new(curve, vertices, global) } + /// Reverse the edge, including the curve + /// + /// # Implementation Note + /// + /// It would be much nicer to just reverse the edge normally everywhere, but + /// we can't do that, until #695 is addressed: + /// + pub fn reverse_including_curve(self) -> Self { + let vertices = VerticesOfEdge(self.vertices.get().map(|[a, b]| { + [ + Vertex::new( + -b.position(), + b.curve().reverse(), + *b.surface_form(), + *b.global_form(), + ), + Vertex::new( + -a.position(), + a.curve().reverse(), + *a.surface_form(), + *a.global_form(), + ), + ] + })); + + Self::from_curve_and_vertices(self.curve().reverse(), vertices) + } + /// Access the curve that defines the edge's geometry /// /// The edge can be a segment of the curve that is bounded by two vertices, From 43cad285fdbddec8c10e4e3539ff402a99ea853f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 7 Sep 2022 17:17:39 +0200 Subject: [PATCH 3/3] Simplify `Edge` reversal Keeps the old behavior where that is necessary, because a surface is reversed. --- .../fj-kernel/src/algorithms/reverse/cycle.rs | 2 +- crates/fj-kernel/src/algorithms/reverse/edge.rs | 2 +- crates/fj-kernel/src/algorithms/sweep/edge.rs | 2 +- crates/fj-kernel/src/objects/edge.rs | 17 +---------------- 4 files changed, 4 insertions(+), 19 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/reverse/cycle.rs b/crates/fj-kernel/src/algorithms/reverse/cycle.rs index 7ec00c5bc..45e67bc30 100644 --- a/crates/fj-kernel/src/algorithms/reverse/cycle.rs +++ b/crates/fj-kernel/src/algorithms/reverse/cycle.rs @@ -8,7 +8,7 @@ impl Reverse for Cycle { let mut edges = self .into_edges() - .map(|edge| edge.reverse()) + .map(|edge| edge.reverse_including_curve()) .collect::>(); edges.reverse(); diff --git a/crates/fj-kernel/src/algorithms/reverse/edge.rs b/crates/fj-kernel/src/algorithms/reverse/edge.rs index 2543c5e43..b64d59753 100644 --- a/crates/fj-kernel/src/algorithms/reverse/edge.rs +++ b/crates/fj-kernel/src/algorithms/reverse/edge.rs @@ -4,6 +4,6 @@ use super::Reverse; impl Reverse for Edge { fn reverse(self) -> Self { - self.reverse_including_curve() + Edge::from_curve_and_vertices(*self.curve(), self.vertices().reverse()) } } diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index bb63a6064..46f6d6148 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -44,7 +44,7 @@ fn create_non_continuous_side_face( color: Color, ) -> Face { let edge = if path.is_negative_direction() { - edge.reverse() + edge.reverse_including_curve() } else { *edge }; diff --git a/crates/fj-kernel/src/objects/edge.rs b/crates/fj-kernel/src/objects/edge.rs index dc9ec2a17..d1cb7bbf3 100644 --- a/crates/fj-kernel/src/objects/edge.rs +++ b/crates/fj-kernel/src/objects/edge.rs @@ -239,22 +239,7 @@ impl VerticesOfEdge { /// /// Makes sure that the local coordinates are still correct. pub fn reverse(self) -> Self { - Self(self.0.map(|[a, b]| { - [ - Vertex::new( - -b.position(), - b.curve().reverse(), - *b.surface_form(), - *b.global_form(), - ), - Vertex::new( - -a.position(), - a.curve().reverse(), - *a.surface_form(), - *a.global_form(), - ), - ] - })) + Self(self.0.map(|[a, b]| [b, a])) } /// Convert this instance into its global variant