From ed797ebee55ccc6a4f8c6f7dc3ca86b2ff90ac88 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Sep 2023 12:06:44 +0200 Subject: [PATCH 01/22] Rename `UpdateCycle::replace_edge` The new name is a bit more generic. Since I'm about to change the signature of that method, I think it will be more appropriate. --- crates/fj-core/src/operations/join/cycle.rs | 4 ++-- crates/fj-core/src/operations/update/cycle.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fj-core/src/operations/join/cycle.rs b/crates/fj-core/src/operations/join/cycle.rs index 7fbdaad84..40fc922cd 100644 --- a/crates/fj-core/src/operations/join/cycle.rs +++ b/crates/fj-core/src/operations/join/cycle.rs @@ -131,8 +131,8 @@ impl JoinCycle for Cycle { next_edge.replace_start_vertex(vertex_b).insert(services); cycle = cycle - .replace_edge(edge, this_joined) - .replace_edge(next_edge, next_joined) + .update_edge(edge, this_joined) + .update_edge(next_edge, next_joined) } cycle diff --git a/crates/fj-core/src/operations/update/cycle.rs b/crates/fj-core/src/operations/update/cycle.rs index beff12c6c..95369e7a4 100644 --- a/crates/fj-core/src/operations/update/cycle.rs +++ b/crates/fj-core/src/operations/update/cycle.rs @@ -15,7 +15,7 @@ pub trait UpdateCycle { /// /// Panics, unless this operation replaces exactly one edge. #[must_use] - fn replace_edge( + fn update_edge( &self, original: &Handle, replacement: Handle, @@ -40,7 +40,7 @@ impl UpdateCycle for Cycle { Cycle::new(edges) } - fn replace_edge( + fn update_edge( &self, original: &Handle, replacement: Handle, From 4bb4caedc5cbeb1eae286f556b905085abe8ab80 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Sep 2023 12:09:16 +0200 Subject: [PATCH 02/22] Rename argument to prepare for follow-on change --- crates/fj-core/src/operations/update/cycle.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-core/src/operations/update/cycle.rs b/crates/fj-core/src/operations/update/cycle.rs index 95369e7a4..548468f9c 100644 --- a/crates/fj-core/src/operations/update/cycle.rs +++ b/crates/fj-core/src/operations/update/cycle.rs @@ -47,12 +47,12 @@ impl UpdateCycle for Cycle { ) -> Self { let mut num_replacements = 0; - let edges = self.edges().iter().map(|edge| { - if edge.id() == original.id() { + let edges = self.edges().iter().map(|e| { + if e.id() == original.id() { num_replacements += 1; replacement.clone() } else { - edge.clone() + e.clone() } }); From c2acc1678602a6d39aa8d3353561aefdf608129b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Sep 2023 12:09:43 +0200 Subject: [PATCH 03/22] Rename argument to prepare for follow-on change --- crates/fj-core/src/operations/update/cycle.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-core/src/operations/update/cycle.rs b/crates/fj-core/src/operations/update/cycle.rs index 548468f9c..ce35107d3 100644 --- a/crates/fj-core/src/operations/update/cycle.rs +++ b/crates/fj-core/src/operations/update/cycle.rs @@ -17,7 +17,7 @@ pub trait UpdateCycle { #[must_use] fn update_edge( &self, - original: &Handle, + edge: &Handle, replacement: Handle, ) -> Self; @@ -42,13 +42,13 @@ impl UpdateCycle for Cycle { fn update_edge( &self, - original: &Handle, + edge: &Handle, replacement: Handle, ) -> Self { let mut num_replacements = 0; let edges = self.edges().iter().map(|e| { - if e.id() == original.id() { + if e.id() == edge.id() { num_replacements += 1; replacement.clone() } else { From a5c6edcfdcbfd73195d855791934b2c1af614c37 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Sep 2023 12:13:20 +0200 Subject: [PATCH 04/22] Take closure in `UpdateCycle::update_edge` --- crates/fj-core/src/operations/join/cycle.rs | 4 ++-- crates/fj-core/src/operations/update/cycle.rs | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/fj-core/src/operations/join/cycle.rs b/crates/fj-core/src/operations/join/cycle.rs index 40fc922cd..dc1750e78 100644 --- a/crates/fj-core/src/operations/join/cycle.rs +++ b/crates/fj-core/src/operations/join/cycle.rs @@ -131,8 +131,8 @@ impl JoinCycle for Cycle { next_edge.replace_start_vertex(vertex_b).insert(services); cycle = cycle - .update_edge(edge, this_joined) - .update_edge(next_edge, next_joined) + .update_edge(edge, |_| this_joined) + .update_edge(next_edge, |_| next_joined) } cycle diff --git a/crates/fj-core/src/operations/update/cycle.rs b/crates/fj-core/src/operations/update/cycle.rs index ce35107d3..4115d3632 100644 --- a/crates/fj-core/src/operations/update/cycle.rs +++ b/crates/fj-core/src/operations/update/cycle.rs @@ -18,7 +18,7 @@ pub trait UpdateCycle { fn update_edge( &self, edge: &Handle, - replacement: Handle, + update: impl FnOnce(&Handle) -> Handle, ) -> Self; /// Update the edge at the given index @@ -43,14 +43,16 @@ impl UpdateCycle for Cycle { fn update_edge( &self, edge: &Handle, - replacement: Handle, + update: impl FnOnce(&Handle) -> Handle, ) -> Self { + let updated = update(edge); + let mut num_replacements = 0; let edges = self.edges().iter().map(|e| { if e.id() == edge.id() { num_replacements += 1; - replacement.clone() + updated.clone() } else { e.clone() } From fed4724aff39eb9b592fc030490aa6e421b42791 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Sep 2023 12:14:04 +0200 Subject: [PATCH 05/22] Refactor to simplify --- crates/fj-core/src/operations/update/cycle.rs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/crates/fj-core/src/operations/update/cycle.rs b/crates/fj-core/src/operations/update/cycle.rs index 4115d3632..cb5cff92a 100644 --- a/crates/fj-core/src/operations/update/cycle.rs +++ b/crates/fj-core/src/operations/update/cycle.rs @@ -45,27 +45,19 @@ impl UpdateCycle for Cycle { edge: &Handle, update: impl FnOnce(&Handle) -> Handle, ) -> Self { - let updated = update(edge); - - let mut num_replacements = 0; + let mut updated = Some(update(edge)); let edges = self.edges().iter().map(|e| { if e.id() == edge.id() { - num_replacements += 1; - updated.clone() + updated + .take() + .expect("Cycle should not contain same edge twice") } else { e.clone() } }); - let cycle = Cycle::new(edges); - - assert_eq!( - num_replacements, 1, - "Expected operation to replace exactly one edge" - ); - - cycle + Cycle::new(edges) } fn update_nth_edge( From 4632bed9f31e7e6f1e2768bf20e38a5857bad06b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Sep 2023 12:26:23 +0200 Subject: [PATCH 06/22] Inline redundant variable --- crates/fj-core/src/operations/join/cycle.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/fj-core/src/operations/join/cycle.rs b/crates/fj-core/src/operations/join/cycle.rs index dc1750e78..69ef675d2 100644 --- a/crates/fj-core/src/operations/join/cycle.rs +++ b/crates/fj-core/src/operations/join/cycle.rs @@ -123,15 +123,15 @@ impl JoinCycle for Cycle { .after(edge) .expect("Cycle must contain edge; just obtained edge from it"); - let this_joined = edge - .replace_curve(edge_other.curve().clone()) - .replace_start_vertex(vertex_a) - .insert(services); let next_joined = next_edge.replace_start_vertex(vertex_b).insert(services); cycle = cycle - .update_edge(edge, |_| this_joined) + .update_edge(edge, |_| { + edge.replace_curve(edge_other.curve().clone()) + .replace_start_vertex(vertex_a) + .insert(services) + }) .update_edge(next_edge, |_| next_joined) } From f3b477d8e416251c4411da00e5633396cc2b0356 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Sep 2023 12:26:47 +0200 Subject: [PATCH 07/22] Inline redundant variable --- crates/fj-core/src/operations/join/cycle.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/fj-core/src/operations/join/cycle.rs b/crates/fj-core/src/operations/join/cycle.rs index 69ef675d2..73fd860c7 100644 --- a/crates/fj-core/src/operations/join/cycle.rs +++ b/crates/fj-core/src/operations/join/cycle.rs @@ -123,16 +123,15 @@ impl JoinCycle for Cycle { .after(edge) .expect("Cycle must contain edge; just obtained edge from it"); - let next_joined = - next_edge.replace_start_vertex(vertex_b).insert(services); - cycle = cycle .update_edge(edge, |_| { edge.replace_curve(edge_other.curve().clone()) .replace_start_vertex(vertex_a) .insert(services) }) - .update_edge(next_edge, |_| next_joined) + .update_edge(next_edge, |_| { + next_edge.replace_start_vertex(vertex_b).insert(services) + }) } cycle From 664a032ae9941db855520767bdd3e7b18c5f269e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Sep 2023 12:27:28 +0200 Subject: [PATCH 08/22] Refactor to prepare for follow-on change --- crates/fj-core/src/operations/join/cycle.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-core/src/operations/join/cycle.rs b/crates/fj-core/src/operations/join/cycle.rs index 73fd860c7..a3016554a 100644 --- a/crates/fj-core/src/operations/join/cycle.rs +++ b/crates/fj-core/src/operations/join/cycle.rs @@ -124,12 +124,12 @@ impl JoinCycle for Cycle { .expect("Cycle must contain edge; just obtained edge from it"); cycle = cycle - .update_edge(edge, |_| { + .update_edge(edge, |edge| { edge.replace_curve(edge_other.curve().clone()) .replace_start_vertex(vertex_a) .insert(services) }) - .update_edge(next_edge, |_| { + .update_edge(next_edge, |next_edge| { next_edge.replace_start_vertex(vertex_b).insert(services) }) } From 0f9275a0e76b0d7d23f69e19eeb6e2523c2923a1 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Sep 2023 12:30:56 +0200 Subject: [PATCH 09/22] Refactor to avoid `expect` --- crates/fj-core/src/operations/join/cycle.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/fj-core/src/operations/join/cycle.rs b/crates/fj-core/src/operations/join/cycle.rs index a3016554a..4b4907140 100644 --- a/crates/fj-core/src/operations/join/cycle.rs +++ b/crates/fj-core/src/operations/join/cycle.rs @@ -118,10 +118,7 @@ impl JoinCycle for Cycle { .clone(); let vertex_b = edge_other.start_vertex().clone(); - let next_edge = self - .edges() - .after(edge) - .expect("Cycle must contain edge; just obtained edge from it"); + let next_edge = self.edges().nth_circular(index + 1); cycle = cycle .update_edge(edge, |edge| { From 0dcd80d254ec34993739a78e87399761f3194e08 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Sep 2023 12:31:16 +0200 Subject: [PATCH 10/22] Inline redundant variable --- crates/fj-core/src/operations/join/cycle.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/fj-core/src/operations/join/cycle.rs b/crates/fj-core/src/operations/join/cycle.rs index 4b4907140..20f926282 100644 --- a/crates/fj-core/src/operations/join/cycle.rs +++ b/crates/fj-core/src/operations/join/cycle.rs @@ -118,17 +118,20 @@ impl JoinCycle for Cycle { .clone(); let vertex_b = edge_other.start_vertex().clone(); - let next_edge = self.edges().nth_circular(index + 1); - cycle = cycle .update_edge(edge, |edge| { edge.replace_curve(edge_other.curve().clone()) .replace_start_vertex(vertex_a) .insert(services) }) - .update_edge(next_edge, |next_edge| { - next_edge.replace_start_vertex(vertex_b).insert(services) - }) + .update_edge( + self.edges().nth_circular(index + 1), + |next_edge| { + next_edge + .replace_start_vertex(vertex_b) + .insert(services) + }, + ) } cycle From 5e0f73309ae1c46165e981bc1b3cce515f9717ed Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Sep 2023 12:31:30 +0200 Subject: [PATCH 11/22] Simplify argument name --- crates/fj-core/src/operations/join/cycle.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/crates/fj-core/src/operations/join/cycle.rs b/crates/fj-core/src/operations/join/cycle.rs index 20f926282..dd9aab2bb 100644 --- a/crates/fj-core/src/operations/join/cycle.rs +++ b/crates/fj-core/src/operations/join/cycle.rs @@ -124,14 +124,9 @@ impl JoinCycle for Cycle { .replace_start_vertex(vertex_a) .insert(services) }) - .update_edge( - self.edges().nth_circular(index + 1), - |next_edge| { - next_edge - .replace_start_vertex(vertex_b) - .insert(services) - }, - ) + .update_edge(self.edges().nth_circular(index + 1), |edge| { + edge.replace_start_vertex(vertex_b).insert(services) + }) } cycle From 4e7939be1f6925aa8c6128d2a83d634fd70186f1 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Sep 2023 12:31:57 +0200 Subject: [PATCH 12/22] Inline redundant variable --- crates/fj-core/src/operations/join/cycle.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/fj-core/src/operations/join/cycle.rs b/crates/fj-core/src/operations/join/cycle.rs index dd9aab2bb..5eea7e08b 100644 --- a/crates/fj-core/src/operations/join/cycle.rs +++ b/crates/fj-core/src/operations/join/cycle.rs @@ -107,7 +107,6 @@ impl JoinCycle for Cycle { let mut cycle = self.clone(); for (index, index_other) in range.zip(range_other) { - let edge = self.edges().nth_circular(index); let edge_other = other.edges().nth_circular(index_other); let vertex_a = other @@ -119,7 +118,7 @@ impl JoinCycle for Cycle { let vertex_b = edge_other.start_vertex().clone(); cycle = cycle - .update_edge(edge, |edge| { + .update_edge(self.edges().nth_circular(index), |edge| { edge.replace_curve(edge_other.curve().clone()) .replace_start_vertex(vertex_a) .insert(services) From bdf034b487b5ecef70ae362f6abd311d5dc97e3f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Sep 2023 12:33:22 +0200 Subject: [PATCH 13/22] Inline redundant variable --- crates/fj-core/src/operations/join/cycle.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-core/src/operations/join/cycle.rs b/crates/fj-core/src/operations/join/cycle.rs index 5eea7e08b..731a8e63b 100644 --- a/crates/fj-core/src/operations/join/cycle.rs +++ b/crates/fj-core/src/operations/join/cycle.rs @@ -115,7 +115,6 @@ impl JoinCycle for Cycle { .expect("Cycle must contain edge; just obtained edge from it") .start_vertex() .clone(); - let vertex_b = edge_other.start_vertex().clone(); cycle = cycle .update_edge(self.edges().nth_circular(index), |edge| { @@ -124,7 +123,8 @@ impl JoinCycle for Cycle { .insert(services) }) .update_edge(self.edges().nth_circular(index + 1), |edge| { - edge.replace_start_vertex(vertex_b).insert(services) + edge.replace_start_vertex(edge_other.start_vertex().clone()) + .insert(services) }) } From 7b4dd965f9f7a31432a081df4f7d3add6a029137 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Sep 2023 12:34:07 +0200 Subject: [PATCH 14/22] Refactor to avoid `expect` --- crates/fj-core/src/operations/join/cycle.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/fj-core/src/operations/join/cycle.rs b/crates/fj-core/src/operations/join/cycle.rs index 731a8e63b..d5f47b5e8 100644 --- a/crates/fj-core/src/operations/join/cycle.rs +++ b/crates/fj-core/src/operations/join/cycle.rs @@ -111,8 +111,7 @@ impl JoinCycle for Cycle { let vertex_a = other .edges() - .after(edge_other) - .expect("Cycle must contain edge; just obtained edge from it") + .nth_circular(index_other + 1) .start_vertex() .clone(); From b4ba97c9b756294d4cd37768e9a2e488a4ebb2f1 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Sep 2023 12:34:38 +0200 Subject: [PATCH 15/22] Inline redundant variable --- crates/fj-core/src/operations/join/cycle.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/fj-core/src/operations/join/cycle.rs b/crates/fj-core/src/operations/join/cycle.rs index d5f47b5e8..6ede147e2 100644 --- a/crates/fj-core/src/operations/join/cycle.rs +++ b/crates/fj-core/src/operations/join/cycle.rs @@ -109,16 +109,16 @@ impl JoinCycle for Cycle { for (index, index_other) in range.zip(range_other) { let edge_other = other.edges().nth_circular(index_other); - let vertex_a = other - .edges() - .nth_circular(index_other + 1) - .start_vertex() - .clone(); - cycle = cycle .update_edge(self.edges().nth_circular(index), |edge| { edge.replace_curve(edge_other.curve().clone()) - .replace_start_vertex(vertex_a) + .replace_start_vertex( + other + .edges() + .nth_circular(index_other + 1) + .start_vertex() + .clone(), + ) .insert(services) }) .update_edge(self.edges().nth_circular(index + 1), |edge| { From e9d4b88aa8d9549b9228390e3a87cbcc6dddb113 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Sep 2023 12:36:20 +0200 Subject: [PATCH 16/22] Refactor to avoid mutable variable --- crates/fj-core/src/operations/join/cycle.rs | 42 +++++++++++---------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/crates/fj-core/src/operations/join/cycle.rs b/crates/fj-core/src/operations/join/cycle.rs index 6ede147e2..e54da31de 100644 --- a/crates/fj-core/src/operations/join/cycle.rs +++ b/crates/fj-core/src/operations/join/cycle.rs @@ -104,29 +104,31 @@ impl JoinCycle for Cycle { "Ranges have different lengths", ); - let mut cycle = self.clone(); + let cycle = self.clone(); - for (index, index_other) in range.zip(range_other) { - let edge_other = other.edges().nth_circular(index_other); + range + .zip(range_other) + .fold(cycle, |cycle, (index, index_other)| { + let edge_other = other.edges().nth_circular(index_other); - cycle = cycle - .update_edge(self.edges().nth_circular(index), |edge| { - edge.replace_curve(edge_other.curve().clone()) - .replace_start_vertex( - other - .edges() - .nth_circular(index_other + 1) - .start_vertex() - .clone(), + cycle + .update_edge(self.edges().nth_circular(index), |edge| { + edge.replace_curve(edge_other.curve().clone()) + .replace_start_vertex( + other + .edges() + .nth_circular(index_other + 1) + .start_vertex() + .clone(), + ) + .insert(services) + }) + .update_edge(self.edges().nth_circular(index + 1), |edge| { + edge.replace_start_vertex( + edge_other.start_vertex().clone(), ) .insert(services) - }) - .update_edge(self.edges().nth_circular(index + 1), |edge| { - edge.replace_start_vertex(edge_other.start_vertex().clone()) - .insert(services) - }) - } - - cycle + }) + }) } } From 5591db008962828874b2ff84001aa7c40a21eb23 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Sep 2023 12:36:50 +0200 Subject: [PATCH 17/22] Inline redundant variable --- crates/fj-core/src/operations/join/cycle.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/fj-core/src/operations/join/cycle.rs b/crates/fj-core/src/operations/join/cycle.rs index e54da31de..c58aa4d60 100644 --- a/crates/fj-core/src/operations/join/cycle.rs +++ b/crates/fj-core/src/operations/join/cycle.rs @@ -104,11 +104,9 @@ impl JoinCycle for Cycle { "Ranges have different lengths", ); - let cycle = self.clone(); - - range - .zip(range_other) - .fold(cycle, |cycle, (index, index_other)| { + range.zip(range_other).fold( + self.clone(), + |cycle, (index, index_other)| { let edge_other = other.edges().nth_circular(index_other); cycle @@ -129,6 +127,7 @@ impl JoinCycle for Cycle { ) .insert(services) }) - }) + }, + ) } } From 559eed963a37ef89a67d134d51bd388e43f29363 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Sep 2023 12:58:31 +0200 Subject: [PATCH 18/22] Reorder code to prepare for follow-on change --- crates/fj-core/src/operations/build/shell.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/fj-core/src/operations/build/shell.rs b/crates/fj-core/src/operations/build/shell.rs index fddf2e497..0232ab880 100644 --- a/crates/fj-core/src/operations/build/shell.rs +++ b/crates/fj-core/src/operations/build/shell.rs @@ -96,26 +96,26 @@ pub trait BuildShell { edge.reverse_curve_coordinate_systems(services) .insert(services) }) + .update_nth_edge(1, |edge| { + edge.reverse_curve_coordinate_systems(services) + .insert(services) + }) + .update_nth_edge(2, |edge| { + edge.reverse_curve_coordinate_systems(services) + .insert(services) + }) .join_to( abc.face.region().exterior(), 0..=0, 1..=1, services, ) - .update_nth_edge(1, |edge| { - edge.reverse_curve_coordinate_systems(services) - .insert(services) - }) .join_to( bad.face.region().exterior(), 1..=1, 2..=2, services, ) - .update_nth_edge(2, |edge| { - edge.reverse_curve_coordinate_systems(services) - .insert(services) - }) .join_to( dac.face.region().exterior(), 2..=2, From 8da217b3e54d3cea9855c4abc0bba104dbab454e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Sep 2023 12:46:39 +0200 Subject: [PATCH 19/22] Replace uses of `UpdateCycle::update_nth_edge` --- crates/fj-core/src/operations/build/shell.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/fj-core/src/operations/build/shell.rs b/crates/fj-core/src/operations/build/shell.rs index 0232ab880..bc9dd78ff 100644 --- a/crates/fj-core/src/operations/build/shell.rs +++ b/crates/fj-core/src/operations/build/shell.rs @@ -46,7 +46,7 @@ pub trait BuildShell { region .update_exterior(|cycle| { cycle - .update_nth_edge(0, |edge| { + .update_edge(cycle.edges().nth_circular(0), |edge| { edge.reverse_curve_coordinate_systems(services) .insert(services) }) @@ -64,7 +64,7 @@ pub trait BuildShell { region .update_exterior(|cycle| { cycle - .update_nth_edge(1, |edge| { + .update_edge(cycle.edges().nth_circular(1), |edge| { edge.reverse_curve_coordinate_systems(services) .insert(services) }) @@ -74,7 +74,7 @@ pub trait BuildShell { 2..=2, services, ) - .update_nth_edge(0, |edge| { + .update_edge(cycle.edges().nth_circular(0), |edge| { edge.reverse_curve_coordinate_systems(services) .insert(services) }) @@ -92,15 +92,15 @@ pub trait BuildShell { region .update_exterior(|cycle| { cycle - .update_nth_edge(0, |edge| { + .update_edge(cycle.edges().nth_circular(0), |edge| { edge.reverse_curve_coordinate_systems(services) .insert(services) }) - .update_nth_edge(1, |edge| { + .update_edge(cycle.edges().nth_circular(1), |edge| { edge.reverse_curve_coordinate_systems(services) .insert(services) }) - .update_nth_edge(2, |edge| { + .update_edge(cycle.edges().nth_circular(2), |edge| { edge.reverse_curve_coordinate_systems(services) .insert(services) }) From 2f24c44c08e753a57b42f0760efdc987b53893d5 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Sep 2023 13:00:05 +0200 Subject: [PATCH 20/22] Replace uses of `UpdateCycle::update_nth_edge` --- crates/fj-core/src/validate/shell.rs | 34 ++++++++++++++++------------ 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/crates/fj-core/src/validate/shell.rs b/crates/fj-core/src/validate/shell.rs index fa914bc5d..143b35c92 100644 --- a/crates/fj-core/src/validate/shell.rs +++ b/crates/fj-core/src/validate/shell.rs @@ -400,13 +400,16 @@ mod tests { region .update_exterior(|cycle| { cycle - .update_nth_edge(0, |edge| { - edge.replace_path(edge.path().reverse()) - .replace_boundary( - edge.boundary().reverse(), - ) - .insert(&mut services) - }) + .update_edge( + cycle.edges().nth_circular(0), + |edge| { + edge.replace_path(edge.path().reverse()) + .replace_boundary( + edge.boundary().reverse(), + ) + .insert(&mut services) + }, + ) .insert(&mut services) }) .insert(&mut services) @@ -442,13 +445,16 @@ mod tests { region .update_exterior(|cycle| { cycle - .update_nth_edge(0, |edge| { - let curve = - Curve::new().insert(&mut services); - - edge.replace_curve(curve) - .insert(&mut services) - }) + .update_edge( + cycle.edges().nth_circular(0), + |edge| { + let curve = + Curve::new().insert(&mut services); + + edge.replace_curve(curve) + .insert(&mut services) + }, + ) .insert(&mut services) }) .insert(&mut services) From d7957a926de2162e9cf255c856b2a927673fc529 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Sep 2023 13:02:17 +0200 Subject: [PATCH 21/22] Remove redundant trait method --- crates/fj-core/src/operations/update/cycle.rs | 38 ------------------- 1 file changed, 38 deletions(-) diff --git a/crates/fj-core/src/operations/update/cycle.rs b/crates/fj-core/src/operations/update/cycle.rs index cb5cff92a..22c49caca 100644 --- a/crates/fj-core/src/operations/update/cycle.rs +++ b/crates/fj-core/src/operations/update/cycle.rs @@ -20,18 +20,6 @@ pub trait UpdateCycle { edge: &Handle, update: impl FnOnce(&Handle) -> Handle, ) -> Self; - - /// Update the edge at the given index - /// - /// # Panics - /// - /// Panics, unless this operation updates exactly one edge. - #[must_use] - fn update_nth_edge( - &self, - index: usize, - f: impl FnMut(&Handle) -> Handle, - ) -> Self; } impl UpdateCycle for Cycle { @@ -59,30 +47,4 @@ impl UpdateCycle for Cycle { Cycle::new(edges) } - - fn update_nth_edge( - &self, - index: usize, - mut f: impl FnMut(&Handle) -> Handle, - ) -> Self { - let mut num_replacements = 0; - - let edges = self.edges().iter().enumerate().map(|(i, edge)| { - if i == index { - num_replacements += 1; - f(edge) - } else { - edge.clone() - } - }); - - let cycle = Cycle::new(edges); - - assert_eq!( - num_replacements, 1, - "Expected operation to replace exactly one edge" - ); - - cycle - } } From 3a886b48575f0c968a8c1a67d2e7f38ad0594521 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Sep 2023 13:02:38 +0200 Subject: [PATCH 22/22] Update doc comment --- crates/fj-core/src/operations/update/cycle.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/crates/fj-core/src/operations/update/cycle.rs b/crates/fj-core/src/operations/update/cycle.rs index 22c49caca..03567c942 100644 --- a/crates/fj-core/src/operations/update/cycle.rs +++ b/crates/fj-core/src/operations/update/cycle.rs @@ -9,11 +9,7 @@ pub trait UpdateCycle { #[must_use] fn add_edges(&self, edges: impl IntoIterator>) -> Self; - /// Replace the provided edge - /// - /// # Panics - /// - /// Panics, unless this operation replaces exactly one edge. + /// Update the provided edge #[must_use] fn update_edge( &self,