From f212de3904b525948e7854887ad1e87c544c1660 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 20 Jul 2022 13:46:49 +0200 Subject: [PATCH 01/11] Update doc comments --- crates/fj-kernel/src/objects/edge.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/objects/edge.rs b/crates/fj-kernel/src/objects/edge.rs index 2431160ef..b963ca6f6 100644 --- a/crates/fj-kernel/src/objects/edge.rs +++ b/crates/fj-kernel/src/objects/edge.rs @@ -76,12 +76,20 @@ impl Edge { } } - /// Access this edge's curve + /// Access the curve that defines the edge's geometry + /// + /// The edge can be a segment of the curve that is bounded by two vertices, + /// or if the curve is continuous (i.e. connects to itself), the edge could + /// be defined by the whole curve, and have no bounding vertices. pub fn curve(&self) -> Curve<3> { self.curve.global() } - /// Access this edge's vertices + /// Access the vertices that bound the edge on the curve + /// + /// An edge has either two bounding vertices or none. The latter is possible + /// if the edge's curve is continuous (i.e. connects to itself), and defines + /// the whole edge. pub fn vertices(&self) -> Option<[Vertex; 2]> { self.vertices.0 } From 751471b4ac9aa46941c8921387542769dde66ae4 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 20 Jul 2022 13:49:11 +0200 Subject: [PATCH 02/11] Return full curve from `Edge::curve` --- .../fj-kernel/src/algorithms/approx/cycles.rs | 2 +- crates/fj-kernel/src/iter.rs | 17 +++++++++-------- crates/fj-kernel/src/objects/edge.rs | 6 +++--- crates/fj-kernel/src/validation/coherence.rs | 3 ++- crates/fj-operations/src/difference_2d.rs | 4 ++-- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/cycles.rs b/crates/fj-kernel/src/algorithms/approx/cycles.rs index 5a43a4e01..3100abaa4 100644 --- a/crates/fj-kernel/src/algorithms/approx/cycles.rs +++ b/crates/fj-kernel/src/algorithms/approx/cycles.rs @@ -21,7 +21,7 @@ impl CycleApprox { for edge in &cycle.edges { let mut edge_points = Vec::new(); - approx_curve(&edge.curve(), tolerance, &mut edge_points); + approx_curve(&edge.curve().global(), tolerance, &mut edge_points); approx_edge(edge.vertices, &mut edge_points); points.extend(edge_points.into_iter().map(|point| { diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index 44695fc99..f61b8405e 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -165,7 +165,7 @@ impl ObjectIters for Cycle { impl ObjectIters for Edge { fn curve_iter(&self) -> Iter> { - let mut iter = Iter::empty().with(self.curve().curve_iter()); + let mut iter = Iter::empty().with(self.curve().global().curve_iter()); for vertex in self.vertices().into_iter().flatten() { iter = iter.with(vertex.curve_iter()); @@ -175,7 +175,7 @@ impl ObjectIters for Edge { } fn cycle_iter(&self) -> Iter { - let mut iter = Iter::empty().with(self.curve().cycle_iter()); + let mut iter = Iter::empty().with(self.curve().global().cycle_iter()); for vertex in self.vertices().into_iter().flatten() { iter = iter.with(vertex.cycle_iter()); @@ -189,7 +189,7 @@ impl ObjectIters for Edge { } fn face_iter(&self) -> Iter { - let mut iter = Iter::empty().with(self.curve().face_iter()); + let mut iter = Iter::empty().with(self.curve().global().face_iter()); for vertex in self.vertices().into_iter().flatten() { iter = iter.with(vertex.face_iter()); @@ -199,7 +199,8 @@ impl ObjectIters for Edge { } fn global_vertex_iter(&self) -> Iter { - let mut iter = Iter::empty().with(self.curve().global_vertex_iter()); + let mut iter = + Iter::empty().with(self.curve().global().global_vertex_iter()); for vertex in self.vertices().into_iter().flatten() { iter = iter.with(vertex.global_vertex_iter()); @@ -209,7 +210,7 @@ impl ObjectIters for Edge { } fn sketch_iter(&self) -> Iter { - let mut iter = Iter::empty().with(self.curve().sketch_iter()); + let mut iter = Iter::empty().with(self.curve().global().sketch_iter()); for vertex in self.vertices().into_iter().flatten() { iter = iter.with(vertex.sketch_iter()); @@ -219,7 +220,7 @@ impl ObjectIters for Edge { } fn solid_iter(&self) -> Iter { - let mut iter = Iter::empty().with(self.curve().solid_iter()); + let mut iter = Iter::empty().with(self.curve().global().solid_iter()); for vertex in self.vertices().into_iter().flatten() { iter = iter.with(vertex.solid_iter()); @@ -229,7 +230,7 @@ impl ObjectIters for Edge { } fn surface_iter(&self) -> Iter { - let mut iter = Iter::empty().with(self.curve().surface_iter()); + let mut iter = Iter::empty().with(self.curve().global().surface_iter()); for vertex in self.vertices().into_iter().flatten() { iter = iter.with(vertex.surface_iter()); @@ -239,7 +240,7 @@ impl ObjectIters for Edge { } fn vertex_iter(&self) -> Iter { - let mut iter = Iter::empty().with(self.curve().vertex_iter()); + let mut iter = Iter::empty().with(self.curve().global().vertex_iter()); for vertex in self.vertices().into_iter().flatten() { iter = iter.with(vertex.vertex_iter()); diff --git a/crates/fj-kernel/src/objects/edge.rs b/crates/fj-kernel/src/objects/edge.rs index b963ca6f6..cc6390ede 100644 --- a/crates/fj-kernel/src/objects/edge.rs +++ b/crates/fj-kernel/src/objects/edge.rs @@ -81,8 +81,8 @@ impl Edge { /// The edge can be a segment of the curve that is bounded by two vertices, /// or if the curve is continuous (i.e. connects to itself), the edge could /// be defined by the whole curve, and have no bounding vertices. - pub fn curve(&self) -> Curve<3> { - self.curve.global() + pub fn curve(&self) -> &Local> { + &self.curve } /// Access the vertices that bound the edge on the curve @@ -105,7 +105,7 @@ impl fmt::Display for Edge { None => write!(f, "continuous edge")?, } - write!(f, " on {}", self.curve())?; + write!(f, " on {}", self.curve().global())?; Ok(()) } diff --git a/crates/fj-kernel/src/validation/coherence.rs b/crates/fj-kernel/src/validation/coherence.rs index aef8c6a6a..460f4508f 100644 --- a/crates/fj-kernel/src/validation/coherence.rs +++ b/crates/fj-kernel/src/validation/coherence.rs @@ -18,7 +18,8 @@ pub fn validate_edge( for vertex in edge.vertices.iter() { let local = vertex.position(); - let local_as_global = edge.curve().point_from_curve_coords(local); + let local_as_global = + edge.curve().global().point_from_curve_coords(local); let global = vertex.global().position(); let distance = (local_as_global - global).magnitude(); diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index 5e03e7067..58bce8076 100644 --- a/crates/fj-operations/src/difference_2d.rs +++ b/crates/fj-operations/src/difference_2d.rs @@ -101,9 +101,9 @@ fn add_cycle(cycle: Cycle, reverse: bool) -> Cycle { let curve_canonical = edge.curve(); let curve_canonical = if reverse { - curve_canonical.reverse() + curve_canonical.global().reverse() } else { - curve_canonical + curve_canonical.global() }; let vertices = if reverse { From efebf5d2519637b74a263642c84472b15539d303 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 20 Jul 2022 13:50:05 +0200 Subject: [PATCH 03/11] Refactor --- crates/fj-operations/src/difference_2d.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index 58bce8076..45c9dd910 100644 --- a/crates/fj-operations/src/difference_2d.rs +++ b/crates/fj-operations/src/difference_2d.rs @@ -99,11 +99,10 @@ fn add_cycle(cycle: Cycle, reverse: bool) -> Cycle { curve_local }; - let curve_canonical = edge.curve(); let curve_canonical = if reverse { - curve_canonical.global().reverse() + edge.curve().global().reverse() } else { - curve_canonical.global() + edge.curve().global() }; let vertices = if reverse { From 269bae81bbef6fc262f6b6ffc24d45dfa7b17739 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 20 Jul 2022 13:50:25 +0200 Subject: [PATCH 04/11] Update variable name --- crates/fj-operations/src/difference_2d.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index 45c9dd910..512b702a8 100644 --- a/crates/fj-operations/src/difference_2d.rs +++ b/crates/fj-operations/src/difference_2d.rs @@ -99,7 +99,7 @@ fn add_cycle(cycle: Cycle, reverse: bool) -> Cycle { curve_local }; - let curve_canonical = if reverse { + let curve_global = if reverse { edge.curve().global().reverse() } else { edge.curve().global() @@ -112,7 +112,7 @@ fn add_cycle(cycle: Cycle, reverse: bool) -> Cycle { }; let edge = Edge { - curve: Local::new(curve_local, curve_canonical), + curve: Local::new(curve_local, curve_global), vertices, }; From 982e61f4643bb53c5cc6c65094d622eaf9d03092 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 20 Jul 2022 13:55:39 +0200 Subject: [PATCH 05/11] Add `VerticesOfEdge::get` --- crates/fj-kernel/src/objects/edge.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/fj-kernel/src/objects/edge.rs b/crates/fj-kernel/src/objects/edge.rs index cc6390ede..e326dfd2c 100644 --- a/crates/fj-kernel/src/objects/edge.rs +++ b/crates/fj-kernel/src/objects/edge.rs @@ -144,6 +144,16 @@ impl VerticesOfEdge { false } + /// Access the vertices + pub fn get(&self) -> Option<[&Vertex; 2]> { + self.0.as_ref().map(|vertices| { + // Can be cleaned up once `each_ref` is stable: + // https://doc.rust-lang.org/std/primitive.array.html#method.each_ref + let [a, b] = vertices; + [a, b] + }) + } + /// Access the two vertices /// /// # Panics From 630139290764ae114a421281d6f41720d306de1e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 20 Jul 2022 13:58:33 +0200 Subject: [PATCH 06/11] Return `&VerticesOfEdge` from `Edge::vertices` --- .../src/algorithms/intersection/curve_face.rs | 4 ++-- crates/fj-kernel/src/algorithms/sweep.rs | 2 +- crates/fj-kernel/src/iter.rs | 16 ++++++++-------- crates/fj-kernel/src/objects/edge.rs | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/intersection/curve_face.rs b/crates/fj-kernel/src/algorithms/intersection/curve_face.rs index 201263d18..ccfd37025 100644 --- a/crates/fj-kernel/src/algorithms/intersection/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersection/curve_face.rs @@ -47,8 +47,8 @@ impl CurveFaceIntersectionList { } }; - let vertices = match edge.vertices() { - Some(vertices) => vertices, + let vertices = match edge.vertices().get() { + Some(vertices) => vertices.map(|&vertex| vertex), None => todo!( "Curve-face intersection does not support faces with \ continuous edges" diff --git a/crates/fj-kernel/src/algorithms/sweep.rs b/crates/fj-kernel/src/algorithms/sweep.rs index af832b464..19851c0a8 100644 --- a/crates/fj-kernel/src/algorithms/sweep.rs +++ b/crates/fj-kernel/src/algorithms/sweep.rs @@ -40,7 +40,7 @@ pub fn sweep( for cycle in face.all_cycles() { for edge in cycle.edges { - if let Some(vertices) = edge.vertices() { + if let Some(vertices) = edge.vertices().get() { create_non_continuous_side_face( path, is_sweep_along_negative_direction, diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index f61b8405e..95f7507b6 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -167,7 +167,7 @@ impl ObjectIters for Edge { fn curve_iter(&self) -> Iter> { let mut iter = Iter::empty().with(self.curve().global().curve_iter()); - for vertex in self.vertices().into_iter().flatten() { + for vertex in self.vertices().iter() { iter = iter.with(vertex.curve_iter()); } @@ -177,7 +177,7 @@ impl ObjectIters for Edge { fn cycle_iter(&self) -> Iter { let mut iter = Iter::empty().with(self.curve().global().cycle_iter()); - for vertex in self.vertices().into_iter().flatten() { + for vertex in self.vertices().iter() { iter = iter.with(vertex.cycle_iter()); } @@ -191,7 +191,7 @@ impl ObjectIters for Edge { fn face_iter(&self) -> Iter { let mut iter = Iter::empty().with(self.curve().global().face_iter()); - for vertex in self.vertices().into_iter().flatten() { + for vertex in self.vertices().iter() { iter = iter.with(vertex.face_iter()); } @@ -202,7 +202,7 @@ impl ObjectIters for Edge { let mut iter = Iter::empty().with(self.curve().global().global_vertex_iter()); - for vertex in self.vertices().into_iter().flatten() { + for vertex in self.vertices().iter() { iter = iter.with(vertex.global_vertex_iter()); } @@ -212,7 +212,7 @@ impl ObjectIters for Edge { fn sketch_iter(&self) -> Iter { let mut iter = Iter::empty().with(self.curve().global().sketch_iter()); - for vertex in self.vertices().into_iter().flatten() { + for vertex in self.vertices().iter() { iter = iter.with(vertex.sketch_iter()); } @@ -222,7 +222,7 @@ impl ObjectIters for Edge { fn solid_iter(&self) -> Iter { let mut iter = Iter::empty().with(self.curve().global().solid_iter()); - for vertex in self.vertices().into_iter().flatten() { + for vertex in self.vertices().iter() { iter = iter.with(vertex.solid_iter()); } @@ -232,7 +232,7 @@ impl ObjectIters for Edge { fn surface_iter(&self) -> Iter { let mut iter = Iter::empty().with(self.curve().global().surface_iter()); - for vertex in self.vertices().into_iter().flatten() { + for vertex in self.vertices().iter() { iter = iter.with(vertex.surface_iter()); } @@ -242,7 +242,7 @@ impl ObjectIters for Edge { fn vertex_iter(&self) -> Iter { let mut iter = Iter::empty().with(self.curve().global().vertex_iter()); - for vertex in self.vertices().into_iter().flatten() { + for vertex in self.vertices().iter() { iter = iter.with(vertex.vertex_iter()); } diff --git a/crates/fj-kernel/src/objects/edge.rs b/crates/fj-kernel/src/objects/edge.rs index e326dfd2c..b1aa14f44 100644 --- a/crates/fj-kernel/src/objects/edge.rs +++ b/crates/fj-kernel/src/objects/edge.rs @@ -90,14 +90,14 @@ impl Edge { /// An edge has either two bounding vertices or none. The latter is possible /// if the edge's curve is continuous (i.e. connects to itself), and defines /// the whole edge. - pub fn vertices(&self) -> Option<[Vertex; 2]> { - self.vertices.0 + pub fn vertices(&self) -> &VerticesOfEdge { + &self.vertices } } impl fmt::Display for Edge { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self.vertices() { + match self.vertices().0 { Some(vertices) => { let [a, b] = vertices.map(|vertex| vertex.position()); write!(f, "edge from {:?} to {:?}", a, b)? From 47eaf59037b3b5a8488b40fa1a4d8f501f7979da Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 20 Jul 2022 13:59:58 +0200 Subject: [PATCH 07/11] Update doc comment --- crates/fj-kernel/src/objects/edge.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/objects/edge.rs b/crates/fj-kernel/src/objects/edge.rs index b1aa14f44..e4e3e80b0 100644 --- a/crates/fj-kernel/src/objects/edge.rs +++ b/crates/fj-kernel/src/objects/edge.rs @@ -163,7 +163,7 @@ impl VerticesOfEdge { self.0.expect("Expected edge to have vertices") } - /// Iterate over the vertices, if any + /// Iterate over the vertices pub fn iter(&self) -> impl Iterator { self.0.iter().flatten() } From 94a73f231d8fb40375790c62f06c7a0e160a93cf Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 20 Jul 2022 14:01:52 +0200 Subject: [PATCH 08/11] Make use of `Edge`'s accessor methods --- crates/fj-kernel/src/algorithms/approx/cycles.rs | 4 ++-- crates/fj-kernel/src/algorithms/intersection/curve_face.rs | 2 +- crates/fj-kernel/src/algorithms/reverse.rs | 6 +++--- crates/fj-kernel/src/algorithms/transform.rs | 7 ++++--- crates/fj-kernel/src/validation/coherence.rs | 2 +- crates/fj-operations/src/difference_2d.rs | 6 +++--- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/cycles.rs b/crates/fj-kernel/src/algorithms/approx/cycles.rs index 3100abaa4..6a1726d71 100644 --- a/crates/fj-kernel/src/algorithms/approx/cycles.rs +++ b/crates/fj-kernel/src/algorithms/approx/cycles.rs @@ -22,11 +22,11 @@ impl CycleApprox { for edge in &cycle.edges { let mut edge_points = Vec::new(); approx_curve(&edge.curve().global(), tolerance, &mut edge_points); - approx_edge(edge.vertices, &mut edge_points); + approx_edge(*edge.vertices(), &mut edge_points); points.extend(edge_points.into_iter().map(|point| { let local = - edge.curve.local().point_from_curve_coords(point.local()); + edge.curve().local().point_from_curve_coords(point.local()); Local::new(local, point.global()) })); } diff --git a/crates/fj-kernel/src/algorithms/intersection/curve_face.rs b/crates/fj-kernel/src/algorithms/intersection/curve_face.rs index ccfd37025..77dbb88f9 100644 --- a/crates/fj-kernel/src/algorithms/intersection/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersection/curve_face.rs @@ -40,7 +40,7 @@ impl CurveFaceIntersectionList { edges }) .map(|edge| { - let line = match edge.curve.local() { + let line = match edge.curve().local() { Curve::Line(line) => line, _ => { todo!("Curve-face intersection only supports polygons") diff --git a/crates/fj-kernel/src/algorithms/reverse.rs b/crates/fj-kernel/src/algorithms/reverse.rs index 6f737224b..533005fc9 100644 --- a/crates/fj-kernel/src/algorithms/reverse.rs +++ b/crates/fj-kernel/src/algorithms/reverse.rs @@ -31,7 +31,7 @@ fn reverse_local_coordinates_in_cycle( .iter() .map(|edge| { let curve = { - let local = match edge.curve.local() { + let local = match edge.curve().local() { Curve::Circle(Circle { center, a, b }) => { let center = Point::from([center.u, -center.v]); @@ -49,12 +49,12 @@ fn reverse_local_coordinates_in_cycle( } }; - Local::new(local, edge.curve.global()) + Local::new(local, edge.curve().global()) }; Edge { curve, - vertices: edge.vertices, + vertices: *edge.vertices(), } }) .collect(); diff --git a/crates/fj-kernel/src/algorithms/transform.rs b/crates/fj-kernel/src/algorithms/transform.rs index af3e6f2b3..b9edac8f9 100644 --- a/crates/fj-kernel/src/algorithms/transform.rs +++ b/crates/fj-kernel/src/algorithms/transform.rs @@ -59,11 +59,12 @@ impl TransformObject for Cycle { impl TransformObject for Edge { fn transform(self, transform: &Transform) -> Self { let curve = Local::new( - self.curve.local(), - self.curve.global().transform(transform), + self.curve().local(), + self.curve().global().transform(transform), ); - let vertices = self.vertices.map(|vertex| vertex.transform(transform)); + let vertices = + self.vertices().map(|vertex| vertex.transform(transform)); Self { curve, vertices } } diff --git a/crates/fj-kernel/src/validation/coherence.rs b/crates/fj-kernel/src/validation/coherence.rs index 460f4508f..e7dea66ab 100644 --- a/crates/fj-kernel/src/validation/coherence.rs +++ b/crates/fj-kernel/src/validation/coherence.rs @@ -16,7 +16,7 @@ pub fn validate_edge( let mut edge_vertex_mismatches = Vec::new(); - for vertex in edge.vertices.iter() { + for vertex in edge.vertices().iter() { let local = vertex.position(); let local_as_global = edge.curve().global().point_from_curve_coords(local); diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index 512b702a8..ffcd127fd 100644 --- a/crates/fj-operations/src/difference_2d.rs +++ b/crates/fj-operations/src/difference_2d.rs @@ -92,7 +92,7 @@ impl Shape for fj::Difference2d { fn add_cycle(cycle: Cycle, reverse: bool) -> Cycle { let mut edges = Vec::new(); for edge in cycle.edges { - let curve_local = edge.curve.local(); + let curve_local = edge.curve().local(); let curve_local = if reverse { curve_local.reverse() } else { @@ -106,9 +106,9 @@ fn add_cycle(cycle: Cycle, reverse: bool) -> Cycle { }; let vertices = if reverse { - edge.vertices.reverse() + edge.vertices().reverse() } else { - edge.vertices + *edge.vertices() }; let edge = Edge { From f52be4d287b7b8f3032fed5af3581ca0ed1e6055 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 20 Jul 2022 14:03:02 +0200 Subject: [PATCH 09/11] Add `Edge::new` --- crates/fj-kernel/src/algorithms/reverse.rs | 5 +---- crates/fj-kernel/src/algorithms/sweep.rs | 2 +- crates/fj-kernel/src/algorithms/transform.rs | 2 +- crates/fj-kernel/src/objects/edge.rs | 5 +++++ crates/fj-kernel/src/validation/mod.rs | 2 +- crates/fj-operations/src/difference_2d.rs | 5 +---- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/reverse.rs b/crates/fj-kernel/src/algorithms/reverse.rs index 533005fc9..46ddd27d5 100644 --- a/crates/fj-kernel/src/algorithms/reverse.rs +++ b/crates/fj-kernel/src/algorithms/reverse.rs @@ -52,10 +52,7 @@ fn reverse_local_coordinates_in_cycle( Local::new(local, edge.curve().global()) }; - Edge { - curve, - vertices: *edge.vertices(), - } + Edge::new(curve, *edge.vertices()) }) .collect(); diff --git a/crates/fj-kernel/src/algorithms/sweep.rs b/crates/fj-kernel/src/algorithms/sweep.rs index 19851c0a8..2e0d1c752 100644 --- a/crates/fj-kernel/src/algorithms/sweep.rs +++ b/crates/fj-kernel/src/algorithms/sweep.rs @@ -152,7 +152,7 @@ fn create_non_continuous_side_face( Vertex::new(Point::from([1.]), b.1), ]); - let edge = Edge { curve, vertices }; + let edge = Edge::new(curve, vertices); edges.push(edge); } diff --git a/crates/fj-kernel/src/algorithms/transform.rs b/crates/fj-kernel/src/algorithms/transform.rs index b9edac8f9..6a22e8268 100644 --- a/crates/fj-kernel/src/algorithms/transform.rs +++ b/crates/fj-kernel/src/algorithms/transform.rs @@ -66,7 +66,7 @@ impl TransformObject for Edge { let vertices = self.vertices().map(|vertex| vertex.transform(transform)); - Self { curve, vertices } + Self::new(curve, vertices) } } diff --git a/crates/fj-kernel/src/objects/edge.rs b/crates/fj-kernel/src/objects/edge.rs index e4e3e80b0..5561f2945 100644 --- a/crates/fj-kernel/src/objects/edge.rs +++ b/crates/fj-kernel/src/objects/edge.rs @@ -24,6 +24,11 @@ pub struct Edge { } impl Edge { + /// Create a new instance + pub fn new(curve: Local>, vertices: VerticesOfEdge) -> Self { + Self { curve, vertices } + } + /// Create a circle from the given radius pub fn circle_from_radius(radius: Scalar) -> Self { let curve_local = Curve::Circle(Circle { diff --git a/crates/fj-kernel/src/validation/mod.rs b/crates/fj-kernel/src/validation/mod.rs index be232e360..a0b8a5632 100644 --- a/crates/fj-kernel/src/validation/mod.rs +++ b/crates/fj-kernel/src/validation/mod.rs @@ -155,7 +155,7 @@ mod tests { let b = Vertex::new(Point::from([Scalar::ONE]), b); let vertices = VerticesOfEdge::from_vertices([a, b]); - let edge = Edge { curve, vertices }; + let edge = Edge::new(curve, vertices); let result = validate( edge, diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index ffcd127fd..c27ed4bac 100644 --- a/crates/fj-operations/src/difference_2d.rs +++ b/crates/fj-operations/src/difference_2d.rs @@ -111,10 +111,7 @@ fn add_cycle(cycle: Cycle, reverse: bool) -> Cycle { *edge.vertices() }; - let edge = Edge { - curve: Local::new(curve_local, curve_global), - vertices, - }; + let edge = Edge::new(Local::new(curve_local, curve_global), vertices); edges.push(edge); } From e2bdc7b3f7ebd40a3df6897cf9ef61282983712e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 20 Jul 2022 14:05:34 +0200 Subject: [PATCH 10/11] Refactor --- crates/fj-operations/src/difference_2d.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index c27ed4bac..35e6d6bc2 100644 --- a/crates/fj-operations/src/difference_2d.rs +++ b/crates/fj-operations/src/difference_2d.rs @@ -92,11 +92,10 @@ impl Shape for fj::Difference2d { fn add_cycle(cycle: Cycle, reverse: bool) -> Cycle { let mut edges = Vec::new(); for edge in cycle.edges { - let curve_local = edge.curve().local(); let curve_local = if reverse { - curve_local.reverse() + edge.curve().local().reverse() } else { - curve_local + edge.curve().local() }; let curve_global = if reverse { From f1012f44f6ee0ad7a3b8fc99310e9e8cee76fdd5 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 20 Jul 2022 14:05:39 +0200 Subject: [PATCH 11/11] Make fields of `Edge` private --- crates/fj-kernel/src/objects/edge.rs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/crates/fj-kernel/src/objects/edge.rs b/crates/fj-kernel/src/objects/edge.rs index 5561f2945..1a5d142fd 100644 --- a/crates/fj-kernel/src/objects/edge.rs +++ b/crates/fj-kernel/src/objects/edge.rs @@ -9,18 +9,8 @@ use super::{Curve, GlobalVertex, Surface, Vertex}; /// An edge of a shape #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct Edge { - /// Access the curve that defines the edge's geometry - /// - /// The edge can be a segment of the curve that is bounded by two vertices, - /// or if the curve is continuous (i.e. connects to itself), the edge could - /// be defined by the whole curve, and have no bounding vertices. - pub curve: Local>, - - /// Access the vertices that bound the edge on the curve - /// - /// If there are no such vertices, that means that both the curve and the - /// edge are continuous (i.e. connected to themselves). - pub vertices: VerticesOfEdge, + curve: Local>, + vertices: VerticesOfEdge, } impl Edge {