From aa73f40f6ca005825f996745f175f77db1f053a8 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 8 Dec 2022 14:35:45 +0100 Subject: [PATCH 01/12] Add `partial2::PartialEdge::curve` --- crates/fj-kernel/src/partial2/objects/edge.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/fj-kernel/src/partial2/objects/edge.rs b/crates/fj-kernel/src/partial2/objects/edge.rs index be089448d..494ae909a 100644 --- a/crates/fj-kernel/src/partial2/objects/edge.rs +++ b/crates/fj-kernel/src/partial2/objects/edge.rs @@ -56,6 +56,12 @@ impl PartialHalfEdge { global_form, } } + + /// Access the curve the partial edge is defined on + pub fn curve(&self) -> Partial { + let [vertex, _] = &self.vertices; + vertex.read().curve.clone() + } } impl PartialObject for PartialHalfEdge { From 04a84a08181b4962e0aa59d57c0f97e9f10a4945 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 8 Dec 2022 15:02:51 +0100 Subject: [PATCH 02/12] Replace `PartialEdge` --- .../src/algorithms/intersect/curve_edge.rs | 6 +- crates/fj-kernel/src/algorithms/sweep/edge.rs | 6 +- crates/fj-kernel/src/algorithms/sweep/face.rs | 6 +- .../fj-kernel/src/algorithms/sweep/vertex.rs | 5 +- crates/fj-kernel/src/builder/cycle.rs | 35 +- crates/fj-kernel/src/builder/edge.rs | 3 +- crates/fj-kernel/src/builder/shell.rs | 328 ++++++++++-------- crates/fj-kernel/src/iter.rs | 7 +- crates/fj-kernel/src/objects/full/edge.rs | 5 +- crates/fj-kernel/src/partial/mod.rs | 2 +- crates/fj-kernel/src/partial/objects/cycle.rs | 16 +- crates/fj-kernel/src/partial/objects/edge.rs | 94 ----- crates/fj-kernel/src/partial/objects/mod.rs | 9 +- crates/fj-kernel/src/validate/cycle.rs | 33 +- crates/fj-kernel/src/validate/edge.rs | 5 +- crates/fj-operations/src/sketch.rs | 6 +- 16 files changed, 251 insertions(+), 315 deletions(-) delete mode 100644 crates/fj-kernel/src/partial/objects/edge.rs diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs index 80fe5905c..7218107fd 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs @@ -80,8 +80,10 @@ mod tests { use crate::{ builder::{CurveBuilder, HalfEdgeBuilder}, objects::Vertex, - partial::PartialHalfEdge, - partial2::{Partial, PartialCurve, PartialGlobalEdge, PartialObject}, + partial2::{ + Partial, PartialCurve, PartialGlobalEdge, PartialHalfEdge, + PartialObject, + }, services::Services, }; diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index b0328664e..602223e1d 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -194,10 +194,10 @@ mod tests { builder::HalfEdgeBuilder, insert::Insert, objects::{Cycle, Face, Vertex}, - partial::{HasPartial, PartialHalfEdge}, + partial::HasPartial, partial2::{ - Partial, PartialCurve, PartialGlobalEdge, PartialSurfaceVertex, - PartialVertex, + Partial, PartialCurve, PartialGlobalEdge, PartialHalfEdge, + PartialObject, PartialSurfaceVertex, PartialVertex, }, services::Services, }; diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 4df8213fb..b2390bb08 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -92,8 +92,10 @@ mod tests { builder::{FaceBuilder, HalfEdgeBuilder}, insert::Insert, objects::{Face, Sketch, Vertex}, - partial::{HasPartial, PartialHalfEdge}, - partial2::{Partial, PartialGlobalEdge}, + partial::HasPartial, + partial2::{ + Partial, PartialGlobalEdge, PartialHalfEdge, PartialObject, + }, services::Services, }; diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index 6219ea8e9..cfc3d1297 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -167,10 +167,9 @@ mod tests { builder::{CurveBuilder, HalfEdgeBuilder}, insert::Insert, objects::Vertex, - partial::PartialHalfEdge, partial2::{ - Partial, PartialCurve, PartialGlobalEdge, PartialObject, - PartialSurfaceVertex, PartialVertex, + Partial, PartialCurve, PartialGlobalEdge, PartialHalfEdge, + PartialObject, PartialSurfaceVertex, PartialVertex, }, services::Services, }; diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 52be104d6..7f25c2c5c 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -3,10 +3,10 @@ use fj_math::Point; use crate::{ objects::{Curve, Surface, SurfaceVertex, Vertex}, - partial::{PartialCycle, PartialHalfEdge}, + partial::PartialCycle, partial2::{ - Partial, PartialCurve, PartialGlobalEdge, PartialSurfaceVertex, - PartialVertex, + Partial, PartialCurve, PartialGlobalEdge, PartialHalfEdge, + PartialSurfaceVertex, PartialVertex, }, storage::Handle, }; @@ -43,7 +43,7 @@ impl CycleBuilder for PartialCycle { let mut previous: Option> = self.half_edges().last().map(|half_edge| { - let [_, last] = half_edge.vertices(); + let [_, last] = &half_edge.read().vertices; let last = last.read(); last.surface_form.clone() }); @@ -89,13 +89,13 @@ impl CycleBuilder for PartialCycle { vertex.read().surface_form.read().global_form.clone() }); - half_edges.push(PartialHalfEdge { + half_edges.push(Partial::from_partial(PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: curve.read().global_form.clone(), vertices: global_vertices, }), - }); + })); continue; } @@ -124,8 +124,9 @@ impl CycleBuilder for PartialCycle { let first = self.half_edges().next(); let last = self.half_edges().last(); - let vertices = [first, last] - .map(|option| option.map(|half_edge| half_edge.vertices())); + let vertices = [first, last].map(|option| { + option.map(|half_edge| half_edge.read().vertices.clone()) + }); let [Some([first, _]), Some([_, last])] = vertices else { return self; @@ -150,14 +151,16 @@ impl CycleBuilder for PartialCycle { vertex.read().surface_form.read().global_form.clone() }); - let half_edge = PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve, - vertices: global_vertices, - }), - } - .update_as_line_segment(); + let half_edge = Partial::from_partial( + PartialHalfEdge { + vertices, + global_form: Partial::from_partial(PartialGlobalEdge { + curve, + vertices: global_vertices, + }), + } + .update_as_line_segment(), + ); self.with_half_edges(Some(half_edge)) } diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index b1d635da8..156ac2c7a 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -3,8 +3,7 @@ use fj_math::{Point, Scalar}; use crate::{ objects::{Curve, Surface, Vertex}, - partial::PartialHalfEdge, - partial2::{Partial, PartialGlobalEdge}, + partial2::{Partial, PartialGlobalEdge, PartialHalfEdge}, storage::Handle, }; diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 0172ccd71..3921122c1 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -8,11 +8,11 @@ use crate::{ algorithms::transform::TransformObject, builder::{FaceBuilder, HalfEdgeBuilder, SurfaceBuilder}, insert::Insert, - objects::{Cycle, Face, FaceSet, Objects, Shell, Vertex}, - partial::{HasPartial, PartialHalfEdge}, + objects::{Cycle, Face, FaceSet, HalfEdge, Objects, Shell, Vertex}, + partial::HasPartial, partial2::{ - Partial, PartialCurve, PartialGlobalEdge, PartialObject, - PartialSurface, PartialSurfaceVertex, PartialVertex, + Partial, PartialCurve, PartialGlobalEdge, PartialHalfEdge, + PartialObject, PartialSurface, PartialSurfaceVertex, PartialVertex, }, services::Service, storage::Handle, @@ -89,39 +89,41 @@ impl ShellBuilder { .read() .clone(); - PartialHalfEdge { - vertices: global_edge.vertices.clone().map( - |global_vertex| { - Partial::from_partial(PartialVertex { - curve: Partial::from_partial( - PartialCurve { - global_form: global_edge - .curve - .clone(), - ..Default::default() - }, - ), - surface_form: Partial::from_partial( - PartialSurfaceVertex { - global_form: global_vertex, - ..Default::default() - }, - ), - ..Default::default() - }) - }, + Partial::from_partial( + PartialHalfEdge { + vertices: global_edge.vertices.clone().map( + |global_vertex| { + Partial::from_partial(PartialVertex { + curve: Partial::from_partial( + PartialCurve { + global_form: global_edge + .curve + .clone(), + ..Default::default() + }, + ), + surface_form: Partial::from_partial( + PartialSurfaceVertex { + global_form: global_vertex, + ..Default::default() + }, + ), + ..Default::default() + }) + }, + ), + global_form: Partial::from_partial( + PartialGlobalEdge { + curve: global_edge.curve, + vertices: global_edge.vertices, + }, + ), + } + .update_as_line_segment_from_points( + Partial::from_full_entry_point(surface.clone()), + [[Z, Z], [edge_length, Z]], ), - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_edge.curve, - vertices: global_edge.vertices, - }), - } - .update_as_line_segment_from_points( - Partial::from_full_entry_point(surface.clone()), - [[Z, Z], [edge_length, Z]], ) - .build(objects) - .insert(objects) }) .collect::>(); @@ -129,12 +131,14 @@ impl ShellBuilder { .clone() .into_iter() .zip(&surfaces) - .map(|(bottom, surface)| { - let [_, from] = bottom.vertices(); + .map(|(bottom, surface): (Partial, _)| { + let [_, from] = &bottom.read().vertices; - let from = from.surface_form().clone(); + let from = from.read().surface_form.clone(); let to = PartialSurfaceVertex { - position: Some(from.position() + [Z, edge_length]), + position: Some( + from.read().position.unwrap() + [Z, edge_length], + ), surface: Partial::from_full_entry_point( surface.clone(), ), @@ -144,12 +148,10 @@ impl ShellBuilder { let vertices = [ PartialVertex { curve: Partial::from_partial(PartialCurve { - surface: Partial::from_full_entry_point( - from.surface().clone(), - ), + surface: from.read().surface.clone(), ..Default::default() }), - surface_form: Partial::from_full_entry_point(from), + surface_form: from.clone(), ..Default::default() }, PartialVertex { @@ -177,16 +179,18 @@ impl ShellBuilder { .clone() }); - PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }), - } - .update_as_line_segment() - .build(objects) - .insert(objects) + Partial::from_partial( + PartialHalfEdge { + vertices, + global_form: Partial::from_partial( + PartialGlobalEdge { + curve: global_curve, + vertices: global_vertices, + }, + ), + } + .update_as_line_segment(), + ) }) .collect::>(); @@ -199,75 +203,90 @@ impl ShellBuilder { .into_iter() .zip(sides_up_prev) .zip(&surfaces) - .map(|((bottom, side_up_prev), surface)| { - let [_, from] = side_up_prev.vertices(); - let [to, _] = bottom.vertices(); - - let to = to.surface_form().clone(); - let from = PartialSurfaceVertex { - position: Some(to.position() + [Z, edge_length]), - surface: Partial::from_full_entry_point( - surface.clone(), - ), - global_form: Partial::from_full_entry_point( - from.global_form().clone(), - ), - }; - - let curve = PartialCurve { - global_form: Partial::from_full_entry_point( - side_up_prev.curve().global_form().clone(), - ), - ..Default::default() - }; - - let vertices = [ - PartialVertex { - curve: Partial::from_partial(PartialCurve { - surface: from.surface.clone(), - ..curve.clone() - }), - surface_form: Partial::from_partial(from), - ..Default::default() - }, - PartialVertex { - curve: Partial::from_partial(PartialCurve { - surface: Partial::from_full_entry_point( - to.surface().clone(), - ), - ..curve.clone() - }), - surface_form: Partial::from_full_entry_point( - to, + .map( + |((bottom, side_up_prev), surface): ( + (_, Partial), + _, + )| { + let [_, from] = + side_up_prev.read().vertices.clone(); + let [to, _] = bottom.read().vertices.clone(); + + let to = to.read().surface_form.clone(); + let from = PartialSurfaceVertex { + position: Some( + to.read().position.unwrap() + + [Z, edge_length], ), - ..Default::default() - }, - ] - .map(Partial::::from_partial); - - let global_vertices = - vertices.each_ref_ext().map(|vertex| { - vertex + surface: Partial::from_full_entry_point( + surface.clone(), + ), + global_form: from .read() .surface_form .read() .global_form - .clone() - }); + .clone(), + }; - PartialHalfEdge { - vertices, - global_form: Partial::from_partial( - PartialGlobalEdge { - vertices: global_vertices, - curve: curve.global_form, + let curve = PartialCurve { + global_form: side_up_prev + .read() + .curve() + .read() + .global_form + .clone(), + ..Default::default() + }; + + let vertices = [ + PartialVertex { + curve: Partial::from_partial( + PartialCurve { + surface: from.surface.clone(), + ..curve.clone() + }, + ), + surface_form: Partial::from_partial(from), + ..Default::default() }, - ), - } - .update_as_line_segment() - .build(objects) - .insert(objects) - }) + PartialVertex { + curve: Partial::from_partial( + PartialCurve { + surface: to.read().surface.clone(), + ..curve.clone() + }, + ), + surface_form: to.clone(), + ..Default::default() + }, + ] + .map(Partial::::from_partial); + + let global_vertices = + vertices.each_ref_ext().map(|vertex| { + vertex + .read() + .surface_form + .read() + .global_form + .clone() + }); + + Partial::from_partial( + PartialHalfEdge { + vertices, + global_form: Partial::from_partial( + PartialGlobalEdge { + vertices: global_vertices, + curve: curve.global_form, + }, + ), + } + .update_as_line_segment(), + ) + }, + ) .collect::>() }; @@ -275,31 +294,27 @@ impl ShellBuilder { .clone() .into_iter() .zip(sides_down.clone()) - .map(|(side_up, side_down)| { - let [_, from] = side_up.vertices(); - let [to, _] = side_down.vertices(); + .map(|(side_up, side_down): (_, Partial)| { + let [_, from] = side_up.read().vertices.clone(); + let [to, _] = side_down.read().vertices.clone(); - let from = from.surface_form().clone(); - let to = to.surface_form().clone(); + let from = from.read().surface_form.clone(); + let to = to.read().surface_form.clone(); let from = PartialVertex { curve: Partial::from_partial(PartialCurve { - surface: Partial::from_full_entry_point( - from.surface().clone(), - ), + surface: from.read().surface.clone(), ..Default::default() }), - surface_form: Partial::from_full_entry_point(from), + surface_form: from.clone(), ..Default::default() }; let to = PartialVertex { curve: Partial::from_partial(PartialCurve { - surface: Partial::from_full_entry_point( - to.surface().clone(), - ), + surface: to.read().surface.clone(), ..Default::default() }), - surface_form: Partial::from_full_entry_point(to), + surface_form: to.clone(), ..Default::default() }; @@ -319,16 +334,18 @@ impl ShellBuilder { .clone() }); - PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }), - } - .update_as_line_segment() - .build(objects) - .insert(objects) + Partial::from_partial( + PartialHalfEdge { + vertices, + global_form: Partial::from_partial( + PartialGlobalEdge { + curve: global_curve, + vertices: global_vertices, + }, + ), + } + .update_as_line_segment(), + ) }) .collect::>(); @@ -371,16 +388,20 @@ impl ShellBuilder { .zip(half_edges) .collect::<[_; 4]>() .map(|(point, edge)| { - let vertex = edge.back(); + let [vertex, _] = edge.read().vertices.clone(); + let global_vertex = vertex + .read() + .surface_form + .read() + .global_form + .clone(); PartialSurfaceVertex { position: Some(point.into()), surface: Partial::from_full_entry_point( surface.clone(), ), - global_form: Partial::from_full_entry_point( - vertex.global_form().clone(), - ), + global_form: global_vertex, } .build(objects) .insert(objects) @@ -395,26 +416,27 @@ impl ShellBuilder { .array_windows_ext() .zip(top_edges) { - let global_edge = - Partial::from_full_entry_point(edge.global_form().clone()) - .read() - .clone(); + let global_edge = edge.read().global_form.clone(); let vertices = edge - .vertices() + .read() + .vertices .each_ref_ext() .into_iter_fixed() .zip(surface_vertices.clone()) .collect::<[_; 2]>() .map(|(vertex, surface_form)| PartialVertex { - position: Some(vertex.position()), + position: vertex.read().position, curve: Partial::from_partial(PartialCurve { surface: Partial::from_full_entry_point( surface_form.surface().clone(), ), - global_form: Partial::from_full_entry_point( - vertex.curve().global_form().clone(), - ), + global_form: vertex + .read() + .curve + .read() + .global_form + .clone(), ..Default::default() }), surface_form: Partial::from_full_entry_point( @@ -426,8 +448,8 @@ impl ShellBuilder { PartialHalfEdge { vertices: vertices.map(Partial::from_partial), global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_edge.curve, - vertices: global_edge.vertices, + curve: global_edge.read().curve.clone(), + vertices: global_edge.read().vertices.clone(), }), } .update_as_line_segment() diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index ed457cbb4..d8778478b 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -370,8 +370,11 @@ mod tests { Cycle, Face, GlobalCurve, GlobalVertex, Objects, Shell, Sketch, Solid, SurfaceVertex, Vertex, }, - partial::{HasPartial, PartialHalfEdge}, - partial2::{Partial, PartialCurve, PartialGlobalEdge, PartialObject}, + partial::HasPartial, + partial2::{ + Partial, PartialCurve, PartialGlobalEdge, PartialHalfEdge, + PartialObject, + }, services::Services, }; diff --git a/crates/fj-kernel/src/objects/full/edge.rs b/crates/fj-kernel/src/objects/full/edge.rs index d7e640dd8..47ba064f3 100644 --- a/crates/fj-kernel/src/objects/full/edge.rs +++ b/crates/fj-kernel/src/objects/full/edge.rs @@ -171,8 +171,9 @@ mod tests { use crate::{ builder::HalfEdgeBuilder, objects::Vertex, - partial::PartialHalfEdge, - partial2::{Partial, PartialGlobalEdge}, + partial2::{ + Partial, PartialGlobalEdge, PartialHalfEdge, PartialObject, + }, services::Services, }; diff --git a/crates/fj-kernel/src/partial/mod.rs b/crates/fj-kernel/src/partial/mod.rs index a623b36ba..01b6ea829 100644 --- a/crates/fj-kernel/src/partial/mod.rs +++ b/crates/fj-kernel/src/partial/mod.rs @@ -43,7 +43,7 @@ mod traits; pub use self::{ maybe_partial::MaybePartial, merge::{MergeWith, Mergeable}, - objects::{cycle::PartialCycle, edge::PartialHalfEdge, face::PartialFace}, + objects::{cycle::PartialCycle, face::PartialFace}, replace::Replace, traits::{HasPartial, Partial}, }; diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index 9b0441e86..8eb9dff28 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -10,12 +10,12 @@ use crate::{ /// See [`crate::partial`] for more information. #[derive(Clone, Debug, Default)] pub struct PartialCycle { - half_edges: Vec>, + half_edges: Vec>, } impl PartialCycle { /// Access the half-edges that make up the [`Cycle`] - pub fn half_edges(&self) -> impl Iterator> { + pub fn half_edges(&self) -> impl Iterator> { self.half_edges.clone().into_iter() } @@ -23,7 +23,7 @@ impl PartialCycle { pub fn surface(&self) -> Option> { self.half_edges .first() - .map(|half_edge| half_edge.curve().read().surface.clone()) + .map(|half_edge| half_edge.read().curve().read().surface.clone()) } /// Add the provided half-edges to the partial cycle @@ -36,7 +36,7 @@ impl PartialCycle { /// Panics, if the surfaces can't be merged. pub fn with_half_edges( mut self, - half_edges: impl IntoIterator>>, + half_edges: impl IntoIterator>, ) -> Self { let half_edges = half_edges.into_iter().map(Into::into); @@ -51,7 +51,7 @@ impl PartialCycle { pub fn build(self, objects: &mut Service) -> Cycle { let mut half_edges = Vec::new(); for half_edge in self.half_edges { - let half_edge = half_edge.into_full(objects); + let half_edge = half_edge.build(objects); half_edges.push(half_edge); } @@ -72,7 +72,11 @@ impl MergeWith for PartialCycle { impl From<&Cycle> for PartialCycle { fn from(cycle: &Cycle) -> Self { Self { - half_edges: cycle.half_edges().cloned().map(Into::into).collect(), + half_edges: cycle + .half_edges() + .cloned() + .map(Partial::from_full_entry_point) + .collect(), } } } diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs deleted file mode 100644 index c0bb12ed8..000000000 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ /dev/null @@ -1,94 +0,0 @@ -use crate::{ - objects::{Curve, GlobalEdge, HalfEdge, Objects, Vertex}, - partial::{MaybePartial, MergeWith}, - partial2::Partial, - services::Service, -}; - -/// A partial [`HalfEdge`] -/// -/// See [`crate::partial`] for more information. -#[derive(Clone, Debug, Default)] -pub struct PartialHalfEdge { - /// The vertices that bound the [`HalfEdge`] in the curve - pub vertices: [Partial; 2], - - /// The global form of the [`HalfEdge`] - pub global_form: Partial, -} - -impl PartialHalfEdge { - /// Access the partial half-edge's curve - pub fn curve(&self) -> Partial { - let [a, _] = &self.vertices; - a.read().curve.clone() - } - - /// Build a full [`HalfEdge`] from the partial half-edge - pub fn build(self, objects: &mut Service) -> HalfEdge { - let vertices = self.vertices.map(|vertex| vertex.build(objects)); - let global_form = self.global_form.build(objects); - - HalfEdge::new(vertices, global_form) - } -} - -impl MergeWith for PartialHalfEdge { - fn merge_with(self, _: impl Into) -> Self { - Self { - vertices: self.vertices, - global_form: self.global_form, - } - } -} - -impl From<&HalfEdge> for PartialHalfEdge { - fn from(half_edge: &HalfEdge) -> Self { - let [back_vertex, front_vertex] = half_edge - .vertices() - .clone() - .map(Partial::from_full_entry_point); - - Self { - vertices: [back_vertex, front_vertex], - global_form: Partial::from_full_entry_point( - half_edge.global_form().clone(), - ), - } - } -} - -impl MaybePartial { - /// Access the curve - pub fn curve(&self) -> Partial { - match self { - Self::Full(full) => { - Partial::from_full_entry_point(full.curve().clone()) - } - Self::Partial(partial) => partial.curve(), - } - } - - /// Access the front vertex - pub fn front(&self) -> Partial { - match self { - Self::Full(full) => { - Partial::from_full_entry_point(full.front().clone()) - } - Self::Partial(partial) => { - let [_, front] = &partial.vertices; - front.clone() - } - } - } - - /// Access the vertices - pub fn vertices(&self) -> [Partial; 2] { - match self { - Self::Full(full) => { - full.vertices().clone().map(Partial::from_full_entry_point) - } - Self::Partial(partial) => partial.vertices.clone(), - } - } -} diff --git a/crates/fj-kernel/src/partial/objects/mod.rs b/crates/fj-kernel/src/partial/objects/mod.rs index 9a372e62b..797a08151 100644 --- a/crates/fj-kernel/src/partial/objects/mod.rs +++ b/crates/fj-kernel/src/partial/objects/mod.rs @@ -1,16 +1,12 @@ pub mod cycle; -pub mod edge; pub mod face; use crate::{ - objects::{Cycle, Face, HalfEdge, Objects}, + objects::{Cycle, Face, Objects}, services::Service, }; -use super::{ - HasPartial, MaybePartial, Partial, PartialCycle, PartialFace, - PartialHalfEdge, -}; +use super::{HasPartial, MaybePartial, Partial, PartialCycle, PartialFace}; macro_rules! impl_traits { ($($full:ty, $partial:ty;)*) => { @@ -39,5 +35,4 @@ macro_rules! impl_traits { impl_traits!( Cycle, PartialCycle; Face, PartialFace; - HalfEdge, PartialHalfEdge; ); diff --git a/crates/fj-kernel/src/validate/cycle.rs b/crates/fj-kernel/src/validate/cycle.rs index afcd1f375..7e9c239d2 100644 --- a/crates/fj-kernel/src/validate/cycle.rs +++ b/crates/fj-kernel/src/validate/cycle.rs @@ -66,9 +66,8 @@ impl CycleValidationError { #[cfg(test)] mod tests { use crate::{ - builder::CycleBuilder, insert::Insert, objects::Cycle, - partial::HasPartial, partial2::Partial, services::Services, - validate::Validate, + builder::CycleBuilder, objects::Cycle, partial::HasPartial, + partial2::Partial, services::Services, validate::Validate, }; #[test] @@ -85,23 +84,25 @@ mod tests { let invalid = { let mut half_edges = valid .half_edges() - .map(|half_edge| half_edge.to_partial()) + .map(|half_edge| { + Partial::from_full_entry_point(half_edge.clone()) + }) .collect::>(); // Sever connection between the last and first half-edge in the // cycle. - let first_half_edge = half_edges.first_mut().unwrap(); - let [first_vertex, _] = &mut first_half_edge.vertices; - let surface_vertex = Partial::from_partial( - first_vertex.read().surface_form.read().clone(), - ); - first_vertex.write().surface_form = surface_vertex; - - let half_edges = half_edges.into_iter().map(|half_edge| { - half_edge - .build(&mut services.objects) - .insert(&mut services.objects) - }); + { + let first_half_edge = half_edges.first_mut().unwrap(); + let [first_vertex, _] = &mut first_half_edge.write().vertices; + let surface_vertex = Partial::from_partial( + first_vertex.read().surface_form.read().clone(), + ); + first_vertex.write().surface_form = surface_vertex; + } + + let half_edges = half_edges + .into_iter() + .map(|half_edge| half_edge.build(&mut services.objects)); Cycle::new(half_edges) }; diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index 019eeee1a..94d312d2e 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -206,10 +206,9 @@ mod tests { builder::HalfEdgeBuilder, insert::Insert, objects::{GlobalCurve, HalfEdge, Vertex}, - partial::PartialHalfEdge, partial2::{ - Partial, PartialGlobalEdge, PartialObject, PartialSurfaceVertex, - PartialVertex, + Partial, PartialGlobalEdge, PartialHalfEdge, PartialObject, + PartialSurfaceVertex, PartialVertex, }, services::Services, validate::Validate, diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 1c14c94fc..aeccd8f59 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -5,10 +5,10 @@ use fj_kernel::{ builder::{FaceBuilder, HalfEdgeBuilder}, insert::Insert, objects::{Cycle, Face, Objects, Sketch, Vertex}, - partial::{HasPartial, PartialHalfEdge}, + partial::HasPartial, partial2::{ - Partial, PartialCurve, PartialGlobalEdge, PartialSurfaceVertex, - PartialVertex, + Partial, PartialCurve, PartialGlobalEdge, PartialHalfEdge, + PartialObject, PartialSurfaceVertex, PartialVertex, }, services::Service, }; From afb311054c83f75465fd4fb6f2d6d5223e7536b2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 12:50:38 +0100 Subject: [PATCH 03/12] Make struct field public --- crates/fj-kernel/src/builder/cycle.rs | 6 +++--- crates/fj-kernel/src/partial/objects/cycle.rs | 8 ++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 7f25c2c5c..640255b83 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -42,7 +42,7 @@ impl CycleBuilder for PartialCycle { let vertices = vertices.into_iter(); let mut previous: Option> = - self.half_edges().last().map(|half_edge| { + self.half_edges.last().map(|half_edge| { let [_, last] = &half_edge.read().vertices; let last = last.read(); last.surface_form.clone() @@ -121,8 +121,8 @@ impl CycleBuilder for PartialCycle { } fn close_with_line_segment(self) -> Self { - let first = self.half_edges().next(); - let last = self.half_edges().last(); + let first = self.half_edges.first(); + let last = self.half_edges.last(); let vertices = [first, last].map(|option| { option.map(|half_edge| half_edge.read().vertices.clone()) diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index 8eb9dff28..5c6e1dd72 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -10,15 +10,11 @@ use crate::{ /// See [`crate::partial`] for more information. #[derive(Clone, Debug, Default)] pub struct PartialCycle { - half_edges: Vec>, + /// The half-edges that make up the [`Cycle`] + pub half_edges: Vec>, } impl PartialCycle { - /// Access the half-edges that make up the [`Cycle`] - pub fn half_edges(&self) -> impl Iterator> { - self.half_edges.clone().into_iter() - } - /// Access the surface that the [`Cycle`]'s [`HalfEdge`]s are defined in pub fn surface(&self) -> Option> { self.half_edges From 04d92db9dbffe765780d7fc48bdf6359e45b5621 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 12:53:04 +0100 Subject: [PATCH 04/12] Remove `PartialCycle::with_half_edges` Its responsibilities have shrunk over time, and it's no longer very useful. --- crates/fj-kernel/src/builder/cycle.rs | 10 +++++---- crates/fj-kernel/src/builder/shell.rs | 7 +++---- crates/fj-kernel/src/partial/objects/cycle.rs | 21 ------------------- 3 files changed, 9 insertions(+), 29 deletions(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 640255b83..a4acce32c 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -36,7 +36,7 @@ pub trait CycleBuilder { impl CycleBuilder for PartialCycle { fn with_poly_chain( - self, + mut self, vertices: impl IntoIterator, ) -> Self { let vertices = vertices.into_iter(); @@ -103,7 +103,8 @@ impl CycleBuilder for PartialCycle { previous = Some(vertex_next); } - self.with_half_edges(half_edges) + self.half_edges.extend(half_edges); + self } fn with_poly_chain_from_points( @@ -120,7 +121,7 @@ impl CycleBuilder for PartialCycle { })) } - fn close_with_line_segment(self) -> Self { + fn close_with_line_segment(mut self) -> Self { let first = self.half_edges.first(); let last = self.half_edges.last(); @@ -162,6 +163,7 @@ impl CycleBuilder for PartialCycle { .update_as_line_segment(), ); - self.with_half_edges(Some(half_edge)) + self.half_edges.push(half_edge); + self } } diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 3921122c1..0df337354 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -355,10 +355,9 @@ impl ShellBuilder { .zip(tops.clone()) .zip(sides_down) .map(|(((bottom, side_up), top), side_down)| { - let cycle = Cycle::partial() - .with_half_edges([bottom, side_up, top, side_down]) - .build(objects) - .insert(objects); + let mut cycle = Cycle::partial(); + cycle.half_edges.extend([bottom, side_up, top, side_down]); + let cycle = cycle.build(objects).insert(objects); Face::partial() .with_exterior(cycle) diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index 5c6e1dd72..ea7e96cba 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -22,27 +22,6 @@ impl PartialCycle { .map(|half_edge| half_edge.read().curve().read().surface.clone()) } - /// Add the provided half-edges to the partial cycle - /// - /// This will merge all the surfaces of the added half-edges. All added - /// half-edges will end up with the same merged surface. - /// - /// # Panics - /// - /// Panics, if the surfaces can't be merged. - pub fn with_half_edges( - mut self, - half_edges: impl IntoIterator>, - ) -> Self { - let half_edges = half_edges.into_iter().map(Into::into); - - for half_edge in half_edges { - self.half_edges.push(half_edge); - } - - self - } - /// Build a full [`Cycle`] from the partial cycle pub fn build(self, objects: &mut Service) -> Cycle { let mut half_edges = Vec::new(); From 37cf553ddcb55c98670af99dd31795e4954dca2b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 13:02:56 +0100 Subject: [PATCH 05/12] Add `PartialCycle::surface` --- .../fj-kernel/src/algorithms/reverse/face.rs | 12 +++- crates/fj-kernel/src/algorithms/sweep/edge.rs | 5 +- crates/fj-kernel/src/builder/cycle.rs | 5 +- crates/fj-kernel/src/partial/mod.rs | 2 +- crates/fj-kernel/src/partial/objects/cycle.rs | 69 ------------------- crates/fj-kernel/src/partial/objects/face.rs | 13 ++-- crates/fj-kernel/src/partial/objects/mod.rs | 4 +- .../fj-kernel/src/partial2/objects/cycle.rs | 9 ++- 8 files changed, 30 insertions(+), 89 deletions(-) delete mode 100644 crates/fj-kernel/src/partial/objects/cycle.rs diff --git a/crates/fj-kernel/src/algorithms/reverse/face.rs b/crates/fj-kernel/src/algorithms/reverse/face.rs index 9672ebca8..09313d51b 100644 --- a/crates/fj-kernel/src/algorithms/reverse/face.rs +++ b/crates/fj-kernel/src/algorithms/reverse/face.rs @@ -2,6 +2,7 @@ use crate::{ insert::Insert, objects::{Face, Objects}, partial::HasPartial, + partial2::{FullToPartialCache, Partial}, services::Service, storage::Handle, }; @@ -10,10 +11,17 @@ use super::Reverse; impl Reverse for Handle { fn reverse(self, objects: &mut Service) -> Self { - let exterior = self.exterior().clone().reverse(objects); + let mut cache = FullToPartialCache::default(); + + let exterior = Partial::from_full( + self.exterior().clone().reverse(objects), + &mut cache, + ); let interiors = self .interiors() - .map(|cycle| cycle.clone().reverse(objects)) + .map(|cycle| { + Partial::from_full(cycle.clone().reverse(objects), &mut cache) + }) .collect::>(); Face::partial() diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 602223e1d..10be01c3c 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -11,6 +11,7 @@ use crate::{ Vertex, }, partial::HasPartial, + partial2::Partial, services::Service, storage::Handle, }; @@ -175,7 +176,7 @@ impl Sweep for (Handle, Color) { }; Face::partial() - .with_exterior(cycle) + .with_exterior(Partial::from_full_entry_point(cycle)) .with_color(color) .build(objects) .insert(objects) @@ -419,7 +420,7 @@ mod tests { .insert(&mut services.objects); Face::partial() - .with_exterior(cycle) + .with_exterior(Partial::from_full_entry_point(cycle)) .build(&mut services.objects) .insert(&mut services.objects) }; diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index a4acce32c..130a54885 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -3,10 +3,9 @@ use fj_math::Point; use crate::{ objects::{Curve, Surface, SurfaceVertex, Vertex}, - partial::PartialCycle, partial2::{ - Partial, PartialCurve, PartialGlobalEdge, PartialHalfEdge, - PartialSurfaceVertex, PartialVertex, + Partial, PartialCurve, PartialCycle, PartialGlobalEdge, + PartialHalfEdge, PartialSurfaceVertex, PartialVertex, }, storage::Handle, }; diff --git a/crates/fj-kernel/src/partial/mod.rs b/crates/fj-kernel/src/partial/mod.rs index 01b6ea829..d5714cb81 100644 --- a/crates/fj-kernel/src/partial/mod.rs +++ b/crates/fj-kernel/src/partial/mod.rs @@ -43,7 +43,7 @@ mod traits; pub use self::{ maybe_partial::MaybePartial, merge::{MergeWith, Mergeable}, - objects::{cycle::PartialCycle, face::PartialFace}, + objects::face::PartialFace, replace::Replace, traits::{HasPartial, Partial}, }; diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs deleted file mode 100644 index ea7e96cba..000000000 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ /dev/null @@ -1,69 +0,0 @@ -use crate::{ - objects::{Cycle, HalfEdge, Objects, Surface}, - partial::{MaybePartial, MergeWith}, - partial2::Partial, - services::Service, -}; - -/// A partial [`Cycle`] -/// -/// See [`crate::partial`] for more information. -#[derive(Clone, Debug, Default)] -pub struct PartialCycle { - /// The half-edges that make up the [`Cycle`] - pub half_edges: Vec>, -} - -impl PartialCycle { - /// Access the surface that the [`Cycle`]'s [`HalfEdge`]s are defined in - pub fn surface(&self) -> Option> { - self.half_edges - .first() - .map(|half_edge| half_edge.read().curve().read().surface.clone()) - } - - /// Build a full [`Cycle`] from the partial cycle - pub fn build(self, objects: &mut Service) -> Cycle { - let mut half_edges = Vec::new(); - for half_edge in self.half_edges { - let half_edge = half_edge.build(objects); - half_edges.push(half_edge); - } - - Cycle::new(half_edges) - } -} - -impl MergeWith for PartialCycle { - fn merge_with(self, other: impl Into) -> Self { - let other = other.into(); - - Self { - half_edges: self.half_edges.merge_with(other.half_edges), - } - } -} - -impl From<&Cycle> for PartialCycle { - fn from(cycle: &Cycle) -> Self { - Self { - half_edges: cycle - .half_edges() - .cloned() - .map(Partial::from_full_entry_point) - .collect(), - } - } -} - -impl MaybePartial { - /// Access the surface - pub fn surface(&self) -> Option> { - match self { - Self::Full(full) => { - Some(Partial::from_full_entry_point(full.surface().clone())) - } - Self::Partial(partial) => partial.surface(), - } - } -} diff --git a/crates/fj-kernel/src/partial/objects/face.rs b/crates/fj-kernel/src/partial/objects/face.rs index 7d81eb242..0513e52a0 100644 --- a/crates/fj-kernel/src/partial/objects/face.rs +++ b/crates/fj-kernel/src/partial/objects/face.rs @@ -12,8 +12,8 @@ use crate::{ /// See [`crate::partial`] for more information. #[derive(Clone, Debug, Default)] pub struct PartialFace { - exterior: MaybePartial, - interiors: Vec>, + exterior: Partial, + interiors: Vec>, color: Option, } @@ -24,7 +24,7 @@ impl PartialFace { } /// Access the [`Face`]'s exterior cycle - pub fn exterior(&self) -> MaybePartial { + pub fn exterior(&self) -> Partial { self.exterior.clone() } @@ -39,10 +39,7 @@ impl PartialFace { } /// Build the [`Face`] with the provided exterior - pub fn with_exterior( - mut self, - exterior: impl Into>, - ) -> Self { + pub fn with_exterior(mut self, exterior: Partial) -> Self { self.exterior = exterior.into(); self } @@ -50,7 +47,7 @@ impl PartialFace { /// Build the [`Face`] with the provided interior polygons pub fn with_interiors( mut self, - interiors: impl IntoIterator>>, + interiors: impl IntoIterator>, ) -> Self { let interiors = interiors.into_iter().map(Into::into); self.interiors.extend(interiors); diff --git a/crates/fj-kernel/src/partial/objects/mod.rs b/crates/fj-kernel/src/partial/objects/mod.rs index 797a08151..142585ddf 100644 --- a/crates/fj-kernel/src/partial/objects/mod.rs +++ b/crates/fj-kernel/src/partial/objects/mod.rs @@ -1,4 +1,3 @@ -pub mod cycle; pub mod face; use crate::{ @@ -6,7 +5,7 @@ use crate::{ services::Service, }; -use super::{HasPartial, MaybePartial, Partial, PartialCycle, PartialFace}; +use super::{HasPartial, MaybePartial, Partial, PartialFace}; macro_rules! impl_traits { ($($full:ty, $partial:ty;)*) => { @@ -33,6 +32,5 @@ macro_rules! impl_traits { } impl_traits!( - Cycle, PartialCycle; Face, PartialFace; ); diff --git a/crates/fj-kernel/src/partial2/objects/cycle.rs b/crates/fj-kernel/src/partial2/objects/cycle.rs index e3b9a5de8..f6cab75e4 100644 --- a/crates/fj-kernel/src/partial2/objects/cycle.rs +++ b/crates/fj-kernel/src/partial2/objects/cycle.rs @@ -1,5 +1,5 @@ use crate::{ - objects::{Cycle, HalfEdge, Objects}, + objects::{Cycle, HalfEdge, Objects, Surface}, partial2::{FullToPartialCache, Partial, PartialObject}, services::Service, }; @@ -16,6 +16,13 @@ impl PartialCycle { pub fn new(half_edges: Vec>) -> Self { Self { half_edges } } + + /// Access the surface of the [`Cycle`] + pub fn surface(&self) -> Option> { + self.half_edges + .first() + .map(|half_edge| half_edge.read().curve().read().surface.clone()) + } } impl PartialObject for PartialCycle { From e5c31987301d3d4c75258c3c14151a0631abaff5 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 13:09:34 +0100 Subject: [PATCH 06/12] Replace `PartialCycle` --- crates/fj-kernel/src/builder/face.rs | 19 ++++++++++------- crates/fj-kernel/src/builder/shell.rs | 22 +++++++++----------- crates/fj-kernel/src/iter.rs | 10 ++++----- crates/fj-kernel/src/partial/objects/face.rs | 22 ++++++++++++-------- crates/fj-kernel/src/partial/objects/mod.rs | 2 +- crates/fj-kernel/src/validate/cycle.rs | 9 +++++--- crates/fj-kernel/src/validate/face.rs | 5 +++-- crates/fj-operations/src/difference_2d.rs | 11 +++++++--- crates/fj-operations/src/sketch.rs | 16 +++++++------- 9 files changed, 65 insertions(+), 51 deletions(-) diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index e3f1c7065..fb9cd1898 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -1,8 +1,9 @@ use fj_math::Point; use crate::{ - objects::{Cycle, Surface}, - partial::{HasPartial, PartialFace}, + objects::Surface, + partial::PartialFace, + partial2::{Partial, PartialCycle}, storage::Handle, }; @@ -31,11 +32,11 @@ impl FaceBuilder for PartialFace { surface: Handle, points: impl IntoIterator>>, ) -> Self { - self.with_exterior( - Cycle::partial() + self.with_exterior(Partial::from_partial( + PartialCycle::default() .with_poly_chain_from_points(surface, points) .close_with_line_segment(), - ) + )) } fn with_interior_polygon_from_points( @@ -43,8 +44,10 @@ impl FaceBuilder for PartialFace { surface: Handle, points: impl IntoIterator>>, ) -> Self { - self.with_interiors([Cycle::partial() - .with_poly_chain_from_points(surface, points) - .close_with_line_segment()]) + self.with_interiors([Partial::from_partial( + PartialCycle::default() + .with_poly_chain_from_points(surface, points) + .close_with_line_segment(), + )]) } } diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 0df337354..382ce1e0b 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -8,11 +8,12 @@ use crate::{ algorithms::transform::TransformObject, builder::{FaceBuilder, HalfEdgeBuilder, SurfaceBuilder}, insert::Insert, - objects::{Cycle, Face, FaceSet, HalfEdge, Objects, Shell, Vertex}, + objects::{Face, FaceSet, HalfEdge, Objects, Shell, Vertex}, partial::HasPartial, partial2::{ - Partial, PartialCurve, PartialGlobalEdge, PartialHalfEdge, - PartialObject, PartialSurface, PartialSurfaceVertex, PartialVertex, + Partial, PartialCurve, PartialCycle, PartialGlobalEdge, + PartialHalfEdge, PartialObject, PartialSurface, PartialSurfaceVertex, + PartialVertex, }, services::Service, storage::Handle, @@ -355,12 +356,11 @@ impl ShellBuilder { .zip(tops.clone()) .zip(sides_down) .map(|(((bottom, side_up), top), side_down)| { - let mut cycle = Cycle::partial(); + let mut cycle = PartialCycle::default(); cycle.half_edges.extend([bottom, side_up, top, side_down]); - let cycle = cycle.build(objects).insert(objects); Face::partial() - .with_exterior(cycle) + .with_exterior(Partial::from_partial(cycle)) .build(objects) .insert(objects) }) @@ -443,7 +443,7 @@ impl ShellBuilder { ), }); - edges.push( + edges.push(Partial::from_partial( PartialHalfEdge { vertices: vertices.map(Partial::from_partial), global_form: Partial::from_partial(PartialGlobalEdge { @@ -451,14 +451,12 @@ impl ShellBuilder { vertices: global_edge.read().vertices.clone(), }), } - .update_as_line_segment() - .build(objects) - .insert(objects), - ); + .update_as_line_segment(), + )); } Face::partial() - .with_exterior(Cycle::new(edges).insert(objects)) + .with_exterior(Partial::from_partial(PartialCycle::new(edges))) .build(objects) .insert(objects) }; diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index d8778478b..1e19923b6 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -367,13 +367,13 @@ mod tests { builder::{CurveBuilder, CycleBuilder, FaceBuilder, HalfEdgeBuilder}, insert::Insert, objects::{ - Cycle, Face, GlobalCurve, GlobalVertex, Objects, Shell, Sketch, - Solid, SurfaceVertex, Vertex, + Face, GlobalCurve, GlobalVertex, Objects, Shell, Sketch, Solid, + SurfaceVertex, Vertex, }, partial::HasPartial, partial2::{ - Partial, PartialCurve, PartialGlobalEdge, PartialHalfEdge, - PartialObject, + Partial, PartialCurve, PartialCycle, PartialGlobalEdge, + PartialHalfEdge, PartialObject, }, services::Services, }; @@ -412,7 +412,7 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xy_plane(); - let object = Cycle::partial() + let object = PartialCycle::default() .with_poly_chain_from_points( surface, [[0., 0.], [1., 0.], [0., 1.]], diff --git a/crates/fj-kernel/src/partial/objects/face.rs b/crates/fj-kernel/src/partial/objects/face.rs index 0513e52a0..8ad6dddc7 100644 --- a/crates/fj-kernel/src/partial/objects/face.rs +++ b/crates/fj-kernel/src/partial/objects/face.rs @@ -2,7 +2,7 @@ use fj_interop::mesh::Color; use crate::{ objects::{Cycle, Face, Objects, Surface}, - partial::{MaybePartial, MergeWith, Mergeable}, + partial::{MergeWith, Mergeable}, partial2::Partial, services::Service, }; @@ -20,7 +20,7 @@ pub struct PartialFace { impl PartialFace { /// Access th surface that the [`Face`] is defined in pub fn surface(&self) -> Option> { - self.exterior.surface() + self.exterior.read().surface() } /// Access the [`Face`]'s exterior cycle @@ -29,7 +29,7 @@ impl PartialFace { } /// Access the [`Face`]'s interior cycles - pub fn interiors(&self) -> impl Iterator> + '_ { + pub fn interiors(&self) -> impl Iterator> + '_ { self.interiors.iter().cloned() } @@ -40,7 +40,7 @@ impl PartialFace { /// Build the [`Face`] with the provided exterior pub fn with_exterior(mut self, exterior: Partial) -> Self { - self.exterior = exterior.into(); + self.exterior = exterior; self } @@ -62,11 +62,11 @@ impl PartialFace { /// Construct a polygon from a list of points pub fn build(self, objects: &mut Service) -> Face { - let exterior = self.exterior.into_full(objects); + let exterior = self.exterior.build(objects); let interiors = self .interiors .into_iter() - .map(|cycle| cycle.into_full(objects)) + .map(|cycle| cycle.build(objects)) .collect::>(); let color = self.color.unwrap_or_default(); @@ -79,7 +79,7 @@ impl MergeWith for PartialFace { let other = other.into(); Self { - exterior: self.exterior.merge_with(other.exterior), + exterior: self.exterior, interiors: Mergeable(self.interiors) .merge_with(Mergeable(other.interiors)) .0, @@ -91,8 +91,12 @@ impl MergeWith for PartialFace { impl From<&Face> for PartialFace { fn from(face: &Face) -> Self { Self { - exterior: face.exterior().clone().into(), - interiors: face.interiors().cloned().map(Into::into).collect(), + exterior: Partial::from_full_entry_point(face.exterior().clone()), + interiors: face + .interiors() + .cloned() + .map(Partial::from_full_entry_point) + .collect(), color: Some(face.color()), } } diff --git a/crates/fj-kernel/src/partial/objects/mod.rs b/crates/fj-kernel/src/partial/objects/mod.rs index 142585ddf..030a3ecfe 100644 --- a/crates/fj-kernel/src/partial/objects/mod.rs +++ b/crates/fj-kernel/src/partial/objects/mod.rs @@ -1,7 +1,7 @@ pub mod face; use crate::{ - objects::{Cycle, Face, Objects}, + objects::{Face, Objects}, services::Service, }; diff --git a/crates/fj-kernel/src/validate/cycle.rs b/crates/fj-kernel/src/validate/cycle.rs index 7e9c239d2..a79e4edd6 100644 --- a/crates/fj-kernel/src/validate/cycle.rs +++ b/crates/fj-kernel/src/validate/cycle.rs @@ -66,15 +66,18 @@ impl CycleValidationError { #[cfg(test)] mod tests { use crate::{ - builder::CycleBuilder, objects::Cycle, partial::HasPartial, - partial2::Partial, services::Services, validate::Validate, + builder::CycleBuilder, + objects::Cycle, + partial2::{Partial, PartialCycle, PartialObject}, + services::Services, + validate::Validate, }; #[test] fn cycle_half_edge_connections() { let mut services = Services::new(); - let valid = Cycle::partial() + let valid = PartialCycle::default() .with_poly_chain_from_points( services.objects.surfaces.xy_plane(), [[0., 0.], [1., 0.], [0., 1.]], diff --git a/crates/fj-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index 67208e1ea..6f7b54cb0 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -107,8 +107,9 @@ mod tests { algorithms::reverse::Reverse, builder::{CycleBuilder, FaceBuilder}, insert::Insert, - objects::{Cycle, Face}, + objects::Face, partial::HasPartial, + partial2::{PartialCycle, PartialObject}, services::Services, validate::Validate, }; @@ -130,7 +131,7 @@ mod tests { ) .build(&mut services.objects); let invalid = { - let interiors = [Cycle::partial() + let interiors = [PartialCycle::default() .with_poly_chain_from_points( services.objects.surfaces.xz_plane(), [[1., 1.], [1., 2.], [2., 1.]], diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index 41e43a8af..9152c4abf 100644 --- a/crates/fj-operations/src/difference_2d.rs +++ b/crates/fj-operations/src/difference_2d.rs @@ -7,6 +7,7 @@ use fj_kernel::{ iter::ObjectIters, objects::{Face, Objects, Sketch}, partial::HasPartial, + partial2::Partial, services::Service, }; use fj_math::Aabb; @@ -48,7 +49,9 @@ impl Shape for fj::Difference2d { exteriors.push(face.exterior().clone()); for cycle in face.interiors() { - interiors.push(cycle.clone().reverse(objects)); + interiors.push(Partial::from_full_entry_point( + cycle.clone().reverse(objects), + )); } } @@ -59,7 +62,9 @@ impl Shape for fj::Difference2d { "Trying to subtract faces with different surfaces.", ); - interiors.push(face.exterior().clone().reverse(objects)); + interiors.push(Partial::from_full_entry_point( + face.exterior().clone().reverse(objects), + )); } // Faces only support one exterior, while the code here comes from @@ -81,7 +86,7 @@ impl Shape for fj::Difference2d { faces.push( Face::partial() - .with_exterior(exterior) + .with_exterior(Partial::from_full_entry_point(exterior)) .with_interiors(interiors) .with_color(Color(self.color())) .build(objects) diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index aeccd8f59..485e4bdc4 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -4,11 +4,11 @@ use fj_interop::{debug::DebugInfo, ext::ArrayExt, mesh::Color}; use fj_kernel::{ builder::{FaceBuilder, HalfEdgeBuilder}, insert::Insert, - objects::{Cycle, Face, Objects, Sketch, Vertex}, + objects::{Face, Objects, Sketch, Vertex}, partial::HasPartial, partial2::{ - Partial, PartialCurve, PartialGlobalEdge, PartialHalfEdge, - PartialObject, PartialSurfaceVertex, PartialVertex, + Partial, PartialCurve, PartialCycle, PartialGlobalEdge, + PartialHalfEdge, PartialSurfaceVertex, PartialVertex, }, services::Service, }; @@ -67,12 +67,12 @@ impl Shape for fj::Sketch { vertices: global_vertices, }), }; - half_edge - .update_as_circle_from_radius(circle.radius()) - .build(objects) - .insert(objects) + Partial::from_partial( + half_edge.update_as_circle_from_radius(circle.radius()), + ) }; - let cycle = Cycle::new([half_edge]).insert(objects); + let cycle = + Partial::from_partial(PartialCycle::new(vec![half_edge])); Face::partial() .with_exterior(cycle) From 3711e9b5c586d19b286de259bc4f6db880014fd1 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 13:56:18 +0100 Subject: [PATCH 07/12] Make fields of `PartialFace` public --- crates/fj-kernel/src/partial/objects/face.rs | 26 ++++++-------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/face.rs b/crates/fj-kernel/src/partial/objects/face.rs index 8ad6dddc7..ea3de2e29 100644 --- a/crates/fj-kernel/src/partial/objects/face.rs +++ b/crates/fj-kernel/src/partial/objects/face.rs @@ -12,9 +12,14 @@ use crate::{ /// See [`crate::partial`] for more information. #[derive(Clone, Debug, Default)] pub struct PartialFace { - exterior: Partial, - interiors: Vec>, - color: Option, + /// The [`Face`]'s exterior cycle + pub exterior: Partial, + + /// The [`Face`]'s interior cycles + pub interiors: Vec>, + + /// The color of the [`Face`] + pub color: Option, } impl PartialFace { @@ -23,21 +28,6 @@ impl PartialFace { self.exterior.read().surface() } - /// Access the [`Face`]'s exterior cycle - pub fn exterior(&self) -> Partial { - self.exterior.clone() - } - - /// Access the [`Face`]'s interior cycles - pub fn interiors(&self) -> impl Iterator> + '_ { - self.interiors.iter().cloned() - } - - /// Access the color of the [`Face`] - pub fn color(&self) -> Option { - self.color - } - /// Build the [`Face`] with the provided exterior pub fn with_exterior(mut self, exterior: Partial) -> Self { self.exterior = exterior; From 4cbdac521fb1e4ad652854f3abc4629ea064c12d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 14:01:58 +0100 Subject: [PATCH 08/12] Simplify `PartialFace` --- .../fj-kernel/src/algorithms/reverse/face.rs | 12 +++++----- crates/fj-kernel/src/algorithms/sweep/edge.rs | 17 +++++++------- crates/fj-kernel/src/builder/face.rs | 14 +++++++----- crates/fj-kernel/src/builder/shell.rs | 16 +++++++------- crates/fj-kernel/src/partial/objects/face.rs | 22 ------------------- crates/fj-operations/src/difference_2d.rs | 14 +++++------- crates/fj-operations/src/sketch.rs | 20 ++++++++--------- 7 files changed, 47 insertions(+), 68 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/reverse/face.rs b/crates/fj-kernel/src/algorithms/reverse/face.rs index 09313d51b..c1debb263 100644 --- a/crates/fj-kernel/src/algorithms/reverse/face.rs +++ b/crates/fj-kernel/src/algorithms/reverse/face.rs @@ -24,11 +24,11 @@ impl Reverse for Handle { }) .collect::>(); - Face::partial() - .with_exterior(exterior) - .with_interiors(interiors) - .with_color(self.color()) - .build(objects) - .insert(objects) + let mut face = Face::partial(); + face.exterior = exterior; + face.interiors = interiors; + face.color = Some(self.color()); + + face.build(objects).insert(objects) } } diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 10be01c3c..8be9c97fd 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -175,11 +175,11 @@ impl Sweep for (Handle, Color) { Cycle::new(edges).insert(objects) }; - Face::partial() - .with_exterior(Partial::from_full_entry_point(cycle)) - .with_color(color) - .build(objects) - .insert(objects) + let mut face = Face::partial(); + face.exterior = Partial::from_full_entry_point(cycle); + face.color = Some(color); + + face.build(objects).insert(objects) } } @@ -419,9 +419,10 @@ mod tests { let cycle = Cycle::new([bottom, side_up, top, side_down]) .insert(&mut services.objects); - Face::partial() - .with_exterior(Partial::from_full_entry_point(cycle)) - .build(&mut services.objects) + let mut face = Face::partial(); + face.exterior = Partial::from_full_entry_point(cycle); + + face.build(&mut services.objects) .insert(&mut services.objects) }; diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index fb9cd1898..cd178acf3 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -28,26 +28,28 @@ pub trait FaceBuilder { impl FaceBuilder for PartialFace { fn with_exterior_polygon_from_points( - self, + mut self, surface: Handle, points: impl IntoIterator>>, ) -> Self { - self.with_exterior(Partial::from_partial( + self.exterior = Partial::from_partial( PartialCycle::default() .with_poly_chain_from_points(surface, points) .close_with_line_segment(), - )) + ); + self } fn with_interior_polygon_from_points( - self, + mut self, surface: Handle, points: impl IntoIterator>>, ) -> Self { - self.with_interiors([Partial::from_partial( + self.interiors = vec![Partial::from_partial( PartialCycle::default() .with_poly_chain_from_points(surface, points) .close_with_line_segment(), - )]) + )]; + self } } diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 382ce1e0b..3a0fd03c3 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -359,10 +359,10 @@ impl ShellBuilder { let mut cycle = PartialCycle::default(); cycle.half_edges.extend([bottom, side_up, top, side_down]); - Face::partial() - .with_exterior(Partial::from_partial(cycle)) - .build(objects) - .insert(objects) + let mut face = Face::partial(); + face.exterior = Partial::from_partial(cycle); + + face.build(objects).insert(objects) }) .collect::>(); @@ -455,10 +455,10 @@ impl ShellBuilder { )); } - Face::partial() - .with_exterior(Partial::from_partial(PartialCycle::new(edges))) - .build(objects) - .insert(objects) + let mut face = Face::partial(); + face.exterior = Partial::from_partial(PartialCycle::new(edges)); + + face.build(objects).insert(objects) }; self.faces.extend([bottom]); diff --git a/crates/fj-kernel/src/partial/objects/face.rs b/crates/fj-kernel/src/partial/objects/face.rs index ea3de2e29..cb62d1328 100644 --- a/crates/fj-kernel/src/partial/objects/face.rs +++ b/crates/fj-kernel/src/partial/objects/face.rs @@ -28,28 +28,6 @@ impl PartialFace { self.exterior.read().surface() } - /// Build the [`Face`] with the provided exterior - pub fn with_exterior(mut self, exterior: Partial) -> Self { - self.exterior = exterior; - self - } - - /// Build the [`Face`] with the provided interior polygons - pub fn with_interiors( - mut self, - interiors: impl IntoIterator>, - ) -> Self { - let interiors = interiors.into_iter().map(Into::into); - self.interiors.extend(interiors); - self - } - - /// Build the [`Face`] with the provided color - pub fn with_color(mut self, color: Color) -> Self { - self.color = Some(color); - self - } - /// Construct a polygon from a list of points pub fn build(self, objects: &mut Service) -> Face { let exterior = self.exterior.build(objects); diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index 9152c4abf..7be43652c 100644 --- a/crates/fj-operations/src/difference_2d.rs +++ b/crates/fj-operations/src/difference_2d.rs @@ -84,14 +84,12 @@ impl Shape for fj::Difference2d { "Can't construct face with multiple exteriors" ); - faces.push( - Face::partial() - .with_exterior(Partial::from_full_entry_point(exterior)) - .with_interiors(interiors) - .with_color(Color(self.color())) - .build(objects) - .insert(objects), - ); + let mut face = Face::partial(); + face.exterior = Partial::from_full_entry_point(exterior); + face.interiors = interiors; + face.color = Some(Color(self.color())); + + faces.push(face.build(objects).insert(objects)); } let difference = Sketch::builder().with_faces(faces).build(objects); diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 485e4bdc4..28623d3fb 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -74,11 +74,11 @@ impl Shape for fj::Sketch { let cycle = Partial::from_partial(PartialCycle::new(vec![half_edge])); - Face::partial() - .with_exterior(cycle) - .with_color(Color(self.color())) - .build(objects) - .insert(objects) + let mut face = Face::partial(); + face.exterior = cycle; + face.color = Some(Color(self.color())); + + face.build(objects).insert(objects) } fj::Chain::PolyChain(poly_chain) => { let points = poly_chain @@ -87,11 +87,11 @@ impl Shape for fj::Sketch { .map(|fj::SketchSegment::LineTo { point }| point) .map(Point::from); - Face::partial() - .with_exterior_polygon_from_points(surface, points) - .with_color(Color(self.color())) - .build(objects) - .insert(objects) + let mut face = Face::partial() + .with_exterior_polygon_from_points(surface, points); + face.color = Some(Color(self.color())); + + face.build(objects).insert(objects) } }; From c66832504da15110330e99eb9cd22f18fa0934c6 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 14:13:42 +0100 Subject: [PATCH 09/12] Replace `PartialFace` --- .../src/algorithms/intersect/curve_face.rs | 6 +- .../src/algorithms/intersect/face_face.rs | 8 +-- .../src/algorithms/intersect/face_point.rs | 19 +++-- .../src/algorithms/intersect/ray_face.rs | 17 +++-- .../fj-kernel/src/algorithms/reverse/face.rs | 13 ++-- crates/fj-kernel/src/algorithms/sweep/edge.rs | 27 +++---- crates/fj-kernel/src/algorithms/sweep/face.rs | 14 ++-- .../src/algorithms/triangulate/mod.rs | 8 +-- crates/fj-kernel/src/builder/face.rs | 3 +- crates/fj-kernel/src/builder/shell.rs | 19 ++--- crates/fj-kernel/src/builder/sketch.rs | 4 +- crates/fj-kernel/src/iter.rs | 11 ++- crates/fj-kernel/src/partial/mod.rs | 2 - crates/fj-kernel/src/partial/objects/face.rs | 71 ------------------- crates/fj-kernel/src/partial/objects/mod.rs | 36 ---------- crates/fj-kernel/src/validate/face.rs | 7 +- crates/fj-operations/src/difference_2d.rs | 15 ++-- crates/fj-operations/src/sketch.rs | 18 ++--- 18 files changed, 90 insertions(+), 208 deletions(-) delete mode 100644 crates/fj-kernel/src/partial/objects/face.rs delete mode 100644 crates/fj-kernel/src/partial/objects/mod.rs diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index 547b5441e..139e12dba 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -151,9 +151,7 @@ where mod tests { use crate::{ builder::{CurveBuilder, FaceBuilder}, - objects::Face, - partial::HasPartial, - partial2::{Partial, PartialCurve, PartialObject}, + partial2::{Partial, PartialCurve, PartialFace, PartialObject}, services::Services, }; @@ -187,7 +185,7 @@ mod tests { [ 1., -1.], ]; - let face = Face::partial() + let face = PartialFace::default() .with_exterior_polygon_from_points(surface.clone(), exterior) .with_interior_polygon_from_points(surface, interior) .build(&mut services.objects); diff --git a/crates/fj-kernel/src/algorithms/intersect/face_face.rs b/crates/fj-kernel/src/algorithms/intersect/face_face.rs index 16ed60176..306226ac1 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_face.rs @@ -71,9 +71,7 @@ mod tests { algorithms::intersect::CurveFaceIntersection, builder::{CurveBuilder, FaceBuilder}, insert::Insert, - objects::Face, - partial::HasPartial, - partial2::{Partial, PartialCurve, PartialObject}, + partial2::{Partial, PartialCurve, PartialFace, PartialObject}, services::Services, }; @@ -95,7 +93,7 @@ mod tests { services.objects.surfaces.xz_plane(), ] .map(|surface| { - Face::partial() + PartialFace::default() .with_exterior_polygon_from_points(surface, points) .build(&mut services.objects) }); @@ -122,7 +120,7 @@ mod tests { services.objects.surfaces.xz_plane(), ]; let [a, b] = surfaces.clone().map(|surface| { - Face::partial() + PartialFace::default() .with_exterior_polygon_from_points(surface, points) .build(&mut services.objects) }); diff --git a/crates/fj-kernel/src/algorithms/intersect/face_point.rs b/crates/fj-kernel/src/algorithms/intersect/face_point.rs index 021f18ae4..79a1d72cc 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_point.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_point.rs @@ -139,8 +139,7 @@ mod tests { builder::FaceBuilder, insert::Insert, iter::ObjectIters, - objects::Face, - partial::HasPartial, + partial2::{PartialFace, PartialObject}, services::Services, }; @@ -149,7 +148,7 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xy_plane(); - let face = Face::partial() + let face = PartialFace::default() .with_exterior_polygon_from_points( surface, [[0., 0.], [1., 1.], [0., 2.]], @@ -167,7 +166,7 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xy_plane(); - let face = Face::partial() + let face = PartialFace::default() .with_exterior_polygon_from_points( surface, [[0., 0.], [2., 1.], [0., 2.]], @@ -188,7 +187,7 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xy_plane(); - let face = Face::partial() + let face = PartialFace::default() .with_exterior_polygon_from_points( surface, [[4., 2.], [0., 4.], [0., 0.]], @@ -209,7 +208,7 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xy_plane(); - let face = Face::partial() + let face = PartialFace::default() .with_exterior_polygon_from_points( surface, [[0., 0.], [2., 1.], [3., 0.], [3., 4.]], @@ -230,7 +229,7 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xy_plane(); - let face = Face::partial() + let face = PartialFace::default() .with_exterior_polygon_from_points( surface, [[0., 0.], [2., 1.], [3., 1.], [0., 2.]], @@ -251,7 +250,7 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xy_plane(); - let face = Face::partial() + let face = PartialFace::default() .with_exterior_polygon_from_points( surface, [[0., 0.], [2., 1.], [3., 1.], [4., 0.], [4., 5.]], @@ -272,7 +271,7 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xy_plane(); - let face = Face::partial() + let face = PartialFace::default() .with_exterior_polygon_from_points( surface, [[0., 0.], [2., 0.], [0., 1.]], @@ -302,7 +301,7 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xy_plane(); - let face = Face::partial() + let face = PartialFace::default() .with_exterior_polygon_from_points( surface, [[0., 0.], [1., 0.], [0., 1.]], diff --git a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs index bcb140734..fbfdb496f 100644 --- a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs @@ -155,8 +155,7 @@ mod tests { builder::FaceBuilder, insert::Insert, iter::ObjectIters, - objects::Face, - partial::HasPartial, + partial2::{PartialFace, PartialObject}, services::Services, }; @@ -167,7 +166,7 @@ mod tests { let ray = HorizontalRayToTheRight::from([0., 0., 0.]); let surface = services.objects.surfaces.yz_plane(); - let face = Face::partial() + let face = PartialFace::default() .with_exterior_polygon_from_points( surface, [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], @@ -186,7 +185,7 @@ mod tests { let ray = HorizontalRayToTheRight::from([0., 0., 0.]); let surface = services.objects.surfaces.yz_plane(); - let face = Face::partial() + let face = PartialFace::default() .with_exterior_polygon_from_points( surface, [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], @@ -208,7 +207,7 @@ mod tests { let ray = HorizontalRayToTheRight::from([0., 0., 0.]); let surface = services.objects.surfaces.yz_plane(); - let face = Face::partial() + let face = PartialFace::default() .with_exterior_polygon_from_points( surface, [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], @@ -227,7 +226,7 @@ mod tests { let ray = HorizontalRayToTheRight::from([0., 0., 0.]); let surface = services.objects.surfaces.yz_plane(); - let face = Face::partial() + let face = PartialFace::default() .with_exterior_polygon_from_points( surface, [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], @@ -257,7 +256,7 @@ mod tests { let ray = HorizontalRayToTheRight::from([0., 0., 0.]); let surface = services.objects.surfaces.yz_plane(); - let face = Face::partial() + let face = PartialFace::default() .with_exterior_polygon_from_points( surface, [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], @@ -285,7 +284,7 @@ mod tests { let ray = HorizontalRayToTheRight::from([0., 0., 0.]); let surface = services.objects.surfaces.xy_plane(); - let face = Face::partial() + let face = PartialFace::default() .with_exterior_polygon_from_points( surface, [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], @@ -306,7 +305,7 @@ mod tests { let ray = HorizontalRayToTheRight::from([0., 0., 0.]); let surface = services.objects.surfaces.xy_plane(); - let face = Face::partial() + let face = PartialFace::default() .with_exterior_polygon_from_points( surface, [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], diff --git a/crates/fj-kernel/src/algorithms/reverse/face.rs b/crates/fj-kernel/src/algorithms/reverse/face.rs index c1debb263..3cc6a0375 100644 --- a/crates/fj-kernel/src/algorithms/reverse/face.rs +++ b/crates/fj-kernel/src/algorithms/reverse/face.rs @@ -1,8 +1,7 @@ use crate::{ insert::Insert, objects::{Face, Objects}, - partial::HasPartial, - partial2::{FullToPartialCache, Partial}, + partial2::{FullToPartialCache, Partial, PartialFace, PartialObject}, services::Service, storage::Handle, }; @@ -24,11 +23,11 @@ impl Reverse for Handle { }) .collect::>(); - let mut face = Face::partial(); - face.exterior = exterior; - face.interiors = interiors; - face.color = Some(self.color()); - + let face = PartialFace { + exterior, + interiors, + color: Some(self.color()), + }; face.build(objects).insert(objects) } } diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 8be9c97fd..83ef1c103 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -10,8 +10,7 @@ use crate::{ Curve, Cycle, Face, GlobalEdge, HalfEdge, Objects, SurfaceVertex, Vertex, }, - partial::HasPartial, - partial2::Partial, + partial2::{Partial, PartialFace, PartialObject}, services::Service, storage::Handle, }; @@ -175,10 +174,11 @@ impl Sweep for (Handle, Color) { Cycle::new(edges).insert(objects) }; - let mut face = Face::partial(); - face.exterior = Partial::from_full_entry_point(cycle); - face.color = Some(color); - + let face = PartialFace { + exterior: Partial::from_full_entry_point(cycle), + color: Some(color), + ..Default::default() + }; face.build(objects).insert(objects) } } @@ -194,11 +194,11 @@ mod tests { algorithms::{reverse::Reverse, sweep::Sweep}, builder::HalfEdgeBuilder, insert::Insert, - objects::{Cycle, Face, Vertex}, - partial::HasPartial, + objects::{Cycle, Vertex}, partial2::{ - Partial, PartialCurve, PartialGlobalEdge, PartialHalfEdge, - PartialObject, PartialSurfaceVertex, PartialVertex, + Partial, PartialCurve, PartialFace, PartialGlobalEdge, + PartialHalfEdge, PartialObject, PartialSurfaceVertex, + PartialVertex, }, services::Services, }; @@ -419,9 +419,10 @@ mod tests { let cycle = Cycle::new([bottom, side_up, top, side_down]) .insert(&mut services.objects); - let mut face = Face::partial(); - face.exterior = Partial::from_full_entry_point(cycle); - + let face = PartialFace { + exterior: Partial::from_full_entry_point(cycle), + ..Default::default() + }; face.build(&mut services.objects) .insert(&mut services.objects) }; diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index b2390bb08..914945f62 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -91,10 +91,10 @@ mod tests { algorithms::{reverse::Reverse, transform::TransformObject}, builder::{FaceBuilder, HalfEdgeBuilder}, insert::Insert, - objects::{Face, Sketch, Vertex}, - partial::HasPartial, + objects::{Sketch, Vertex}, partial2::{ - Partial, PartialGlobalEdge, PartialHalfEdge, PartialObject, + Partial, PartialFace, PartialGlobalEdge, PartialHalfEdge, + PartialObject, }, services::Services, }; @@ -120,12 +120,12 @@ mod tests { .build(&mut services.objects) .sweep(UP, &mut services.objects); - let bottom = Face::partial() + let bottom = PartialFace::default() .with_exterior_polygon_from_points(surface.clone(), TRIANGLE) .build(&mut services.objects) .insert(&mut services.objects) .reverse(&mut services.objects); - let top = Face::partial() + let top = PartialFace::default() .with_exterior_polygon_from_points( surface.translate(UP, &mut services.objects), TRIANGLE, @@ -188,7 +188,7 @@ mod tests { .build(&mut services.objects) .sweep(DOWN, &mut services.objects); - let bottom = Face::partial() + let bottom = PartialFace::default() .with_exterior_polygon_from_points( surface.clone().translate(DOWN, &mut services.objects), TRIANGLE, @@ -196,7 +196,7 @@ mod tests { .build(&mut services.objects) .insert(&mut services.objects) .reverse(&mut services.objects); - let top = Face::partial() + let top = PartialFace::default() .with_exterior_polygon_from_points(surface, TRIANGLE) .build(&mut services.objects) .insert(&mut services.objects); diff --git a/crates/fj-kernel/src/algorithms/triangulate/mod.rs b/crates/fj-kernel/src/algorithms/triangulate/mod.rs index 3e83522f9..391dd310c 100644 --- a/crates/fj-kernel/src/algorithms/triangulate/mod.rs +++ b/crates/fj-kernel/src/algorithms/triangulate/mod.rs @@ -80,7 +80,7 @@ mod tests { builder::FaceBuilder, insert::Insert, objects::Face, - partial::HasPartial, + partial2::{PartialFace, PartialObject}, services::Services, storage::Handle, }; @@ -97,7 +97,7 @@ mod tests { let d = [0., 1.]; let surface = services.objects.surfaces.xy_plane(); - let face = Face::partial() + let face = PartialFace::default() .with_exterior_polygon_from_points(surface, [a, b, c, d]) .build(&mut services.objects) .insert(&mut services.objects); @@ -132,7 +132,7 @@ mod tests { let h = [3., 1.]; let surface = services.objects.surfaces.xy_plane(); - let face = Face::partial() + let face = PartialFace::default() .with_exterior_polygon_from_points(surface.clone(), [a, b, c, d]) .with_interior_polygon_from_points(surface.clone(), [e, f, g, h]) .build(&mut services.objects) @@ -190,7 +190,7 @@ mod tests { let e = [0.0, 1.0]; let surface = services.objects.surfaces.xy_plane(); - let face = Face::partial() + let face = PartialFace::default() .with_exterior_polygon_from_points(surface.clone(), [a, b, c, d, e]) .build(&mut services.objects) .insert(&mut services.objects); diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index cd178acf3..1bda6225f 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -2,8 +2,7 @@ use fj_math::Point; use crate::{ objects::Surface, - partial::PartialFace, - partial2::{Partial, PartialCycle}, + partial2::{Partial, PartialCycle, PartialFace}, storage::Handle, }; diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 3a0fd03c3..517a2b41d 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -9,9 +9,8 @@ use crate::{ builder::{FaceBuilder, HalfEdgeBuilder, SurfaceBuilder}, insert::Insert, objects::{Face, FaceSet, HalfEdge, Objects, Shell, Vertex}, - partial::HasPartial, partial2::{ - Partial, PartialCurve, PartialCycle, PartialGlobalEdge, + Partial, PartialCurve, PartialCycle, PartialFace, PartialGlobalEdge, PartialHalfEdge, PartialObject, PartialSurface, PartialSurfaceVertex, PartialVertex, }, @@ -53,7 +52,7 @@ impl ShellBuilder { let surface = objects.surfaces.xy_plane().translate([Z, Z, -h], objects); - Face::partial() + PartialFace::default() .with_exterior_polygon_from_points( surface, [[-h, -h], [h, -h], [h, h], [-h, h]], @@ -359,9 +358,10 @@ impl ShellBuilder { let mut cycle = PartialCycle::default(); cycle.half_edges.extend([bottom, side_up, top, side_down]); - let mut face = Face::partial(); - face.exterior = Partial::from_partial(cycle); - + let face = PartialFace { + exterior: Partial::from_partial(cycle), + ..Default::default() + }; face.build(objects).insert(objects) }) .collect::>(); @@ -455,9 +455,10 @@ impl ShellBuilder { )); } - let mut face = Face::partial(); - face.exterior = Partial::from_partial(PartialCycle::new(edges)); - + let face = PartialFace { + exterior: Partial::from_partial(PartialCycle::new(edges)), + ..Default::default() + }; face.build(objects).insert(objects) }; diff --git a/crates/fj-kernel/src/builder/sketch.rs b/crates/fj-kernel/src/builder/sketch.rs index f80593ddf..68088b58d 100644 --- a/crates/fj-kernel/src/builder/sketch.rs +++ b/crates/fj-kernel/src/builder/sketch.rs @@ -3,7 +3,7 @@ use fj_math::Point; use crate::{ insert::Insert, objects::{Face, FaceSet, Objects, Sketch, Surface}, - partial::HasPartial, + partial2::{PartialFace, PartialObject}, services::Service, storage::Handle, }; @@ -35,7 +35,7 @@ impl SketchBuilder { points: impl IntoIterator>>, objects: &mut Service, ) -> Self { - self.faces.extend([Face::partial() + self.faces.extend([PartialFace::default() .with_exterior_polygon_from_points(surface, points) .build(objects) .insert(objects)]); diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index 1e19923b6..133a61cd7 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -367,13 +367,12 @@ mod tests { builder::{CurveBuilder, CycleBuilder, FaceBuilder, HalfEdgeBuilder}, insert::Insert, objects::{ - Face, GlobalCurve, GlobalVertex, Objects, Shell, Sketch, Solid, + GlobalCurve, GlobalVertex, Objects, Shell, Sketch, Solid, SurfaceVertex, Vertex, }, - partial::HasPartial, partial2::{ - Partial, PartialCurve, PartialCycle, PartialGlobalEdge, - PartialHalfEdge, PartialObject, + Partial, PartialCurve, PartialCycle, PartialFace, + PartialGlobalEdge, PartialHalfEdge, PartialObject, }, services::Services, }; @@ -439,7 +438,7 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xy_plane(); - let object = Face::partial() + let object = PartialFace::default() .with_exterior_polygon_from_points( surface, [[0., 0.], [1., 0.], [0., 1.]], @@ -571,7 +570,7 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xy_plane(); - let face = Face::partial() + let face = PartialFace::default() .with_exterior_polygon_from_points( surface, [[0., 0.], [1., 0.], [0., 1.]], diff --git a/crates/fj-kernel/src/partial/mod.rs b/crates/fj-kernel/src/partial/mod.rs index d5714cb81..8b298d028 100644 --- a/crates/fj-kernel/src/partial/mod.rs +++ b/crates/fj-kernel/src/partial/mod.rs @@ -36,14 +36,12 @@ mod maybe_partial; mod merge; -mod objects; mod replace; mod traits; pub use self::{ maybe_partial::MaybePartial, merge::{MergeWith, Mergeable}, - objects::face::PartialFace, replace::Replace, traits::{HasPartial, Partial}, }; diff --git a/crates/fj-kernel/src/partial/objects/face.rs b/crates/fj-kernel/src/partial/objects/face.rs deleted file mode 100644 index cb62d1328..000000000 --- a/crates/fj-kernel/src/partial/objects/face.rs +++ /dev/null @@ -1,71 +0,0 @@ -use fj_interop::mesh::Color; - -use crate::{ - objects::{Cycle, Face, Objects, Surface}, - partial::{MergeWith, Mergeable}, - partial2::Partial, - services::Service, -}; - -/// A partial [`Face`] -/// -/// See [`crate::partial`] for more information. -#[derive(Clone, Debug, Default)] -pub struct PartialFace { - /// The [`Face`]'s exterior cycle - pub exterior: Partial, - - /// The [`Face`]'s interior cycles - pub interiors: Vec>, - - /// The color of the [`Face`] - pub color: Option, -} - -impl PartialFace { - /// Access th surface that the [`Face`] is defined in - pub fn surface(&self) -> Option> { - self.exterior.read().surface() - } - - /// Construct a polygon from a list of points - pub fn build(self, objects: &mut Service) -> Face { - let exterior = self.exterior.build(objects); - let interiors = self - .interiors - .into_iter() - .map(|cycle| cycle.build(objects)) - .collect::>(); - let color = self.color.unwrap_or_default(); - - Face::new(exterior, interiors, color) - } -} - -impl MergeWith for PartialFace { - fn merge_with(self, other: impl Into) -> Self { - let other = other.into(); - - Self { - exterior: self.exterior, - interiors: Mergeable(self.interiors) - .merge_with(Mergeable(other.interiors)) - .0, - color: self.color.merge_with(other.color), - } - } -} - -impl From<&Face> for PartialFace { - fn from(face: &Face) -> Self { - Self { - exterior: Partial::from_full_entry_point(face.exterior().clone()), - interiors: face - .interiors() - .cloned() - .map(Partial::from_full_entry_point) - .collect(), - color: Some(face.color()), - } - } -} diff --git a/crates/fj-kernel/src/partial/objects/mod.rs b/crates/fj-kernel/src/partial/objects/mod.rs deleted file mode 100644 index 030a3ecfe..000000000 --- a/crates/fj-kernel/src/partial/objects/mod.rs +++ /dev/null @@ -1,36 +0,0 @@ -pub mod face; - -use crate::{ - objects::{Face, Objects}, - services::Service, -}; - -use super::{HasPartial, MaybePartial, Partial, PartialFace}; - -macro_rules! impl_traits { - ($($full:ty, $partial:ty;)*) => { - $( - impl HasPartial for $full { - type Partial = $partial; - } - - impl Partial for $partial { - type Full = $full; - - fn build(self, objects: &mut Service) -> Self::Full { - self.build(objects) - } - } - - impl From<$partial> for MaybePartial<$full> { - fn from(partial: $partial) -> Self { - Self::Partial(partial) - } - } - )* - }; -} - -impl_traits!( - Face, PartialFace; -); diff --git a/crates/fj-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index 6f7b54cb0..d24c94c39 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -108,8 +108,7 @@ mod tests { builder::{CycleBuilder, FaceBuilder}, insert::Insert, objects::Face, - partial::HasPartial, - partial2::{PartialCycle, PartialObject}, + partial2::{PartialCycle, PartialFace, PartialObject}, services::Services, validate::Validate, }; @@ -120,7 +119,7 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); - let valid = Face::partial() + let valid = PartialFace::default() .with_exterior_polygon_from_points( surface.clone(), [[0., 0.], [3., 0.], [0., 3.]], @@ -153,7 +152,7 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); - let valid = Face::partial() + let valid = PartialFace::default() .with_exterior_polygon_from_points( surface.clone(), [[0., 0.], [3., 0.], [0., 3.]], diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index 7be43652c..030cc2bfe 100644 --- a/crates/fj-operations/src/difference_2d.rs +++ b/crates/fj-operations/src/difference_2d.rs @@ -5,9 +5,8 @@ use fj_kernel::{ algorithms::reverse::Reverse, insert::Insert, iter::ObjectIters, - objects::{Face, Objects, Sketch}, - partial::HasPartial, - partial2::Partial, + objects::{Objects, Sketch}, + partial2::{Partial, PartialFace, PartialObject}, services::Service, }; use fj_math::Aabb; @@ -84,11 +83,11 @@ impl Shape for fj::Difference2d { "Can't construct face with multiple exteriors" ); - let mut face = Face::partial(); - face.exterior = Partial::from_full_entry_point(exterior); - face.interiors = interiors; - face.color = Some(Color(self.color())); - + let face = PartialFace { + exterior: Partial::from_full_entry_point(exterior), + interiors, + color: Some(Color(self.color())), + }; faces.push(face.build(objects).insert(objects)); } diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 28623d3fb..64d9a8e83 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -4,11 +4,10 @@ use fj_interop::{debug::DebugInfo, ext::ArrayExt, mesh::Color}; use fj_kernel::{ builder::{FaceBuilder, HalfEdgeBuilder}, insert::Insert, - objects::{Face, Objects, Sketch, Vertex}, - partial::HasPartial, + objects::{Objects, Sketch, Vertex}, partial2::{ - Partial, PartialCurve, PartialCycle, PartialGlobalEdge, - PartialHalfEdge, PartialSurfaceVertex, PartialVertex, + Partial, PartialCurve, PartialCycle, PartialFace, PartialGlobalEdge, + PartialHalfEdge, PartialObject, PartialSurfaceVertex, PartialVertex, }, services::Service, }; @@ -74,10 +73,11 @@ impl Shape for fj::Sketch { let cycle = Partial::from_partial(PartialCycle::new(vec![half_edge])); - let mut face = Face::partial(); - face.exterior = cycle; - face.color = Some(Color(self.color())); - + let face = PartialFace { + exterior: cycle, + color: Some(Color(self.color())), + ..Default::default() + }; face.build(objects).insert(objects) } fj::Chain::PolyChain(poly_chain) => { @@ -87,7 +87,7 @@ impl Shape for fj::Sketch { .map(|fj::SketchSegment::LineTo { point }| point) .map(Point::from); - let mut face = Face::partial() + let mut face = PartialFace::default() .with_exterior_polygon_from_points(surface, points); face.color = Some(Color(self.color())); From 6c270ae058795807cf068e61c7e058e98bfd74f4 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 14:14:17 +0100 Subject: [PATCH 10/12] Remove infrastructure for old partial object API --- crates/fj-kernel/src/lib.rs | 1 - crates/fj-kernel/src/partial/maybe_partial.rs | 152 ------------------ crates/fj-kernel/src/partial/merge.rs | 107 ------------ crates/fj-kernel/src/partial/mod.rs | 47 ------ crates/fj-kernel/src/partial/replace.rs | 20 --- crates/fj-kernel/src/partial/traits.rs | 67 -------- 6 files changed, 394 deletions(-) delete mode 100644 crates/fj-kernel/src/partial/maybe_partial.rs delete mode 100644 crates/fj-kernel/src/partial/merge.rs delete mode 100644 crates/fj-kernel/src/partial/mod.rs delete mode 100644 crates/fj-kernel/src/partial/replace.rs delete mode 100644 crates/fj-kernel/src/partial/traits.rs diff --git a/crates/fj-kernel/src/lib.rs b/crates/fj-kernel/src/lib.rs index 3f0642370..88259291f 100644 --- a/crates/fj-kernel/src/lib.rs +++ b/crates/fj-kernel/src/lib.rs @@ -99,7 +99,6 @@ pub mod get; pub mod insert; pub mod iter; pub mod objects; -pub mod partial; pub mod partial2; pub mod services; pub mod storage; diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs deleted file mode 100644 index 6cbfcedb6..000000000 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ /dev/null @@ -1,152 +0,0 @@ -use crate::{ - get::Get, - insert::Insert, - objects::Objects, - services::Service, - storage::Handle, - validate::{Validate, ValidationError}, -}; - -use super::{HasPartial, MergeWith, Partial, Replace}; - -/// Can be used everywhere either a partial or full objects are accepted -/// -/// Some convenience methods are available for specific instances of -/// `MaybePartial` (like, `MaybePartial`, or `MaybePartial`). -/// -/// # Implementation Note -/// -/// The set of available convenience methods is far from complete. Please feel -/// free to just add more, if you need them. -#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] -pub enum MaybePartial { - /// A full object - Full(Handle), - - /// A partial object - Partial(T::Partial), -} - -impl MaybePartial { - /// Indicate whether this is a full object - pub fn is_full(&self) -> bool { - if let Self::Full(_) = self { - return true; - } - - false - } - - /// Indicate whether this is a partial object - pub fn is_partial(&self) -> bool { - if let Self::Partial(_) = self { - return true; - } - - false - } - - /// If this is a partial object, update it - /// - /// This is useful whenever a partial object can infer something about its - /// parts from other parts, and wants to update what was inferred, in case - /// it *can* be updated. - pub fn update_partial( - self, - f: impl FnOnce(T::Partial) -> T::Partial, - ) -> Self { - match self { - Self::Partial(partial) => Self::Partial(f(partial)), - _ => self, - } - } - - /// Return or build a full object - /// - /// If this already is a full object, it is returned. If this is a partial - /// object, the full object is built from it, using [`Partial::build`]. - pub fn into_full(self, objects: &mut Service) -> Handle - where - T: Insert, - ValidationError: From<::Error>, - { - match self { - Self::Partial(partial) => partial.build(objects).insert(objects), - Self::Full(full) => full, - } - } - - /// Return or convert a partial object - /// - /// If this already is a partial object, is is returned. If this is a full - /// object, it is converted into a partial object using - /// [`HasPartial::to_partial`]. - pub fn into_partial(self) -> T::Partial { - match self { - Self::Partial(partial) => partial, - Self::Full(full) => full.to_partial(), - } - } -} - -impl Default for MaybePartial -where - T: HasPartial, - T::Partial: Default, -{ - fn default() -> Self { - Self::Partial(T::Partial::default()) - } -} - -impl MergeWith for MaybePartial -where - T: HasPartial, - T::Partial: MergeWith, -{ - fn merge_with(self, other: impl Into) -> Self { - match (self, other.into()) { - (Self::Full(a), Self::Full(b)) => Self::Full(a.merge_with(b)), - (Self::Full(full), Self::Partial(_)) - | (Self::Partial(_), Self::Full(full)) => Self::Full(full), - (Self::Partial(a), Self::Partial(b)) => { - Self::Partial(a.merge_with(b)) - } - } - } -} - -impl Replace for MaybePartial -where - T: HasPartial + Get, - T::Partial: Replace, -{ - fn replace(&mut self, object: Handle) -> &mut Self { - match self { - Self::Full(full) => { - if full.get().id() != object.id() { - let mut partial = full.to_partial(); - partial.replace(object); - *self = Self::Partial(partial); - } - } - Self::Partial(partial) => { - partial.replace(object); - } - } - - self - } -} - -impl From> for MaybePartial -where - T: HasPartial, -{ - fn from(full: Handle) -> Self { - Self::Full(full) - } -} - -// Unfortunately, we can't add a blanket implementation from `T::Partial` for -// `MaybePartial`, as that would conflict. diff --git a/crates/fj-kernel/src/partial/merge.rs b/crates/fj-kernel/src/partial/merge.rs deleted file mode 100644 index f41a59812..000000000 --- a/crates/fj-kernel/src/partial/merge.rs +++ /dev/null @@ -1,107 +0,0 @@ -use iter_fixed::IntoIteratorFixed; - -use crate::storage::Handle; - -/// Trait for merging partial objects -/// -/// Implemented for all partial objects themselves, and also some related types -/// that partial objects usually contain. -pub trait MergeWith: Sized { - /// Merge this object with another - /// - /// # Panics - /// - /// Merging two objects that cannot be merged is considered a programmer - /// error and will result in a panic. - fn merge_with(self, other: impl Into) -> Self; -} - -/// Wrapper struct that indicates that the contents can be merged -/// -/// Used in connection with [`MergeWith`] to select one implementation over -/// another. -pub struct Mergeable(pub T); - -impl MergeWith for [T; N] -where - T: MergeWith, -{ - fn merge_with(self, other: impl Into) -> Self { - self.into_iter_fixed() - .zip(other.into()) - .collect::<[_; N]>() - .map(|(a, b)| a.merge_with(b)) - } -} - -impl MergeWith for Option -where - T: PartialEq, -{ - fn merge_with(self, other: impl Into) -> Self { - let other = other.into(); - - if self == other { - return self; - } - - // We know that `self != other`, or we wouldn't have made it here. - assert!( - self.is_none() || other.is_none(), - "Can't merge two `Option`s that are both `Some`" - ); - - self.xor(other) - } -} - -// We wouldn't need to use `Mergeable` here, if we had `specialization`: -// https://doc.rust-lang.org/nightly/unstable-book/language-features/specialization.html -// -// Or maybe `min_specialization`: -// https://doc.rust-lang.org/nightly/unstable-book/language-features/min-specialization.html -impl MergeWith for Mergeable> -where - T: MergeWith, -{ - fn merge_with(self, other: impl Into) -> Self { - let merged = match (self.0, other.into().0) { - (Some(a), Some(b)) => Some(a.merge_with(b)), - (a, b) => a.xor(b), - }; - - Self(merged) - } -} - -impl MergeWith for Vec { - fn merge_with(self, other: impl Into) -> Self { - let other = other.into(); - - match (self.is_empty(), other.is_empty()) { - (true, true) => { - panic!("Can't merge `PartialHalfEdge`, if both have half-edges") - } - (true, false) => other, - (false, true) => self, - (false, false) => self, // doesn't matter which we use - } - } -} - -impl MergeWith for Mergeable> { - fn merge_with(mut self, other: impl Into) -> Self { - self.0.extend(other.into().0); - self - } -} - -impl MergeWith for Handle { - fn merge_with(self, other: impl Into) -> Self { - if self.id() == other.into().id() { - return self; - } - - panic!("Can't merge two distinct objects") - } -} diff --git a/crates/fj-kernel/src/partial/mod.rs b/crates/fj-kernel/src/partial/mod.rs deleted file mode 100644 index 8b298d028..000000000 --- a/crates/fj-kernel/src/partial/mod.rs +++ /dev/null @@ -1,47 +0,0 @@ -//! API for dealing with partially defined objects -//! -//! This module contains types that represent objects that only have some of -//! their data and referenced objects defined. This is useful in the following -//! situations: -//! -//! - Sometimes parts of an object can be inferred. For example, when building a -//! half-edge that is a line segment, it is enough to provide only two partial -//! vertices with only their surface coordinates defined. The rest can be -//! inferred. -//! - Sometimes you need to build an object, but parts of it already exist. For -//! example, a new half-edge might share a vertex with an existing half-edge. -//! In such a case you can use the partial object to provide the existing -//! vertex, then provide or infer other parts as appropriate. -//! - When transforming an object, parts of it might already be transformed. For -//! example, when transforming a half-edge, each of its vertices references -//! the same curve as the half-edge does. The partial object API can be used -//! to avoid transforming the same object multiple times. -//! -//! This module contains two groups of types: -//! -//! - Structs that represent partial objects. For example [`PartialHalfEdge`] is -//! the partial variant of [`HalfEdge`]. -//! - Infrastructure for abstracting over partial objects. See [`Partial`], -//! [`HasPartial`], and [`MaybePartial`]. -//! -//! [`HalfEdge`]: crate::objects::HalfEdge -//! -//! # Implementation Note -//! -//! This API grew out of the [builder API][crate::builder] and is still -//! incomplete. Eventually, it should replace the builder API completely -//! ([#1147]). -//! -//! [#1147]: https://github.com/hannobraun/Fornjot/issues/1147 - -mod maybe_partial; -mod merge; -mod replace; -mod traits; - -pub use self::{ - maybe_partial::MaybePartial, - merge::{MergeWith, Mergeable}, - replace::Replace, - traits::{HasPartial, Partial}, -}; diff --git a/crates/fj-kernel/src/partial/replace.rs b/crates/fj-kernel/src/partial/replace.rs deleted file mode 100644 index 180729979..000000000 --- a/crates/fj-kernel/src/partial/replace.rs +++ /dev/null @@ -1,20 +0,0 @@ -use crate::storage::Handle; - -/// Recursively replace a (partial) object referenced by another partial object -pub trait Replace { - /// Recursively replace the referenced object - fn replace(&mut self, object: Handle) -> &mut Self; -} - -impl Replace for [R; N] -where - R: Replace, -{ - fn replace(&mut self, object: Handle) -> &mut Self { - for item in self.iter_mut() { - item.replace(object.clone()); - } - - self - } -} diff --git a/crates/fj-kernel/src/partial/traits.rs b/crates/fj-kernel/src/partial/traits.rs deleted file mode 100644 index 920b13aab..000000000 --- a/crates/fj-kernel/src/partial/traits.rs +++ /dev/null @@ -1,67 +0,0 @@ -use crate::{objects::Objects, services::Service}; - -/// Implemented for objects that a partial object type exists for -pub trait HasPartial { - /// The type representing the partial variant of this object - type Partial: Partial; - - /// Create an empty partial variant of this object - /// - /// This function exists just for convenience, and will just return a - /// [`Default`] version of the partial object. - fn partial() -> Self::Partial { - Self::Partial::default() - } - - /// Convert this object into its partial variant - /// - /// All fields of the partial variant are set from this object. This is - /// useful when creating a new object that needs to share parts of an - /// existing one. - fn to_partial(&self) -> Self::Partial { - self.into() - } -} - -/// Implemented for partial objects -/// -/// The API for partial objects follows a specific style: -/// -/// - Partial objects are structs with fields that mirror the fields of the full -/// object structs, but all fields are optional. -/// - Partial object structs have `with_*` methods to provide values for each of -/// their fields. -/// - Values provided to `with_*` are usually wrapped in an `Option`, and only a -/// `Some(...)` value has any effect. This is a trade-off that makes most use -/// cases slightly more verbose, while significantly simplifying more complex -/// use cases. -/// - Partial object structs may have other methods with prefixes like `as_*`, -/// `from_*`, or similar, if one or more of their fields can be initialized by -/// providing alternative data. -/// - Partial object structs have a `build` method to build a full object. -/// - All `with_*`, `as_*`, and `build` methods can be chained, to provide a -/// convenient API. -/// -/// # Implementation Note -/// -/// It would be nicer to require an [`Into`] bound instead of [`From`] (see -/// documentation of those types for more information). Unfortunately, this -/// doesn't seem to be possible without a `where` clause on `HasPartial`, which -/// significantly reduces the convenience of using that trait, as the `where` -/// clause needs to be repeated everywhere `HasPartial` is specialized as a -/// bound. -pub trait Partial: Default + for<'a> From<&'a Self::Full> { - /// The type representing the full variant of this object - type Full; - - /// Build a full object from this partial one - /// - /// Implementations of this method will typically try to infer any missing - /// parts of the partial object, but this is not possible in all cases. In - /// such cases, implementations of this method may panic. - /// - /// Calling `build` on a partial object that can't infer its missing parts - /// is considered a programmer error, hence why this method doesn't return a - /// [`Result`]. - fn build(self, objects: &mut Service) -> Self::Full; -} From 0b6ba146bf0a71c67c11464d2d6773eca99a6387 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 14:16:20 +0100 Subject: [PATCH 11/12] Remove unused code --- crates/fj-kernel/src/get.rs | 15 ------- crates/fj-kernel/src/lib.rs | 1 - crates/fj-kernel/src/objects/full/curve.rs | 13 ------ crates/fj-kernel/src/objects/full/edge.rs | 19 --------- crates/fj-kernel/src/objects/full/vertex.rs | 45 +-------------------- 5 files changed, 1 insertion(+), 92 deletions(-) delete mode 100644 crates/fj-kernel/src/get.rs diff --git a/crates/fj-kernel/src/get.rs b/crates/fj-kernel/src/get.rs deleted file mode 100644 index 43b41c2b0..000000000 --- a/crates/fj-kernel/src/get.rs +++ /dev/null @@ -1,15 +0,0 @@ -//! Infrastructure for abstracting over accessing referenced objects - -use crate::storage::Handle; - -/// Access a single referenced object -/// -/// Object types implement this trait for the objects they reference. It can be -/// used by other generic infrastructure to abstract over object access. -/// -/// This trait is specifically intended to access single objects, like *the* -/// curve that a vertex references, not *a* half-edge that a cycle references. -pub trait Get { - /// Access the referenced object - fn get(&self) -> Handle; -} diff --git a/crates/fj-kernel/src/lib.rs b/crates/fj-kernel/src/lib.rs index 88259291f..529c2acf5 100644 --- a/crates/fj-kernel/src/lib.rs +++ b/crates/fj-kernel/src/lib.rs @@ -95,7 +95,6 @@ pub mod algorithms; pub mod builder; pub mod geometry; -pub mod get; pub mod insert; pub mod iter; pub mod objects; diff --git a/crates/fj-kernel/src/objects/full/curve.rs b/crates/fj-kernel/src/objects/full/curve.rs index 2b71f9f2f..2db17d3fc 100644 --- a/crates/fj-kernel/src/objects/full/curve.rs +++ b/crates/fj-kernel/src/objects/full/curve.rs @@ -1,6 +1,5 @@ use crate::{ geometry::path::SurfacePath, - get::Get, objects::Surface, storage::{Handle, HandleWrapper}, }; @@ -43,18 +42,6 @@ impl Curve { } } -impl Get for Curve { - fn get(&self) -> Handle { - self.surface().clone() - } -} - -impl Get for Curve { - fn get(&self) -> Handle { - self.global_form().clone() - } -} - /// A curve, defined in global (3D) coordinates #[derive(Clone, Copy, Debug)] pub struct GlobalCurve; diff --git a/crates/fj-kernel/src/objects/full/edge.rs b/crates/fj-kernel/src/objects/full/edge.rs index 47ba064f3..bd86cdf96 100644 --- a/crates/fj-kernel/src/objects/full/edge.rs +++ b/crates/fj-kernel/src/objects/full/edge.rs @@ -1,7 +1,6 @@ use std::fmt; use crate::{ - get::Get, objects::{Curve, GlobalCurve, GlobalVertex, Surface, Vertex}, storage::{Handle, HandleWrapper}, }; @@ -59,18 +58,6 @@ impl HalfEdge { } } -impl Get for HalfEdge { - fn get(&self) -> Handle { - self.global_form().clone() - } -} - -impl Get for HalfEdge { - fn get(&self) -> Handle { - self.global_form().curve().clone() - } -} - impl fmt::Display for HalfEdge { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let [a, b] = self.vertices().clone().map(|vertex| vertex.position()); @@ -125,12 +112,6 @@ impl GlobalEdge { } } -impl Get for GlobalEdge { - fn get(&self) -> Handle { - self.curve().clone() - } -} - /// The vertices of a [`GlobalEdge`] /// /// Since [`GlobalEdge`] is the single global representation of an edge in diff --git a/crates/fj-kernel/src/objects/full/vertex.rs b/crates/fj-kernel/src/objects/full/vertex.rs index 3c812e8e9..35c005cca 100644 --- a/crates/fj-kernel/src/objects/full/vertex.rs +++ b/crates/fj-kernel/src/objects/full/vertex.rs @@ -1,8 +1,7 @@ use fj_math::Point; use crate::{ - get::Get, - objects::{Curve, GlobalCurve, Surface}, + objects::{Curve, Surface}, storage::Handle, }; @@ -55,36 +54,6 @@ impl Vertex { } } -impl Get for Vertex { - fn get(&self) -> Handle { - self.curve().clone() - } -} - -impl Get for Vertex { - fn get(&self) -> Handle { - self.surface_form().clone() - } -} - -impl Get for Vertex { - fn get(&self) -> Handle { - self.curve().surface().clone() - } -} - -impl Get for Vertex { - fn get(&self) -> Handle { - self.curve().global_form().clone() - } -} - -impl Get for Vertex { - fn get(&self) -> Handle { - self.surface_form().global_form().clone() - } -} - /// A vertex, defined in surface (2D) coordinates #[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct SurfaceVertex { @@ -124,18 +93,6 @@ impl SurfaceVertex { } } -impl Get for SurfaceVertex { - fn get(&self) -> Handle { - self.surface().clone() - } -} - -impl Get for SurfaceVertex { - fn get(&self) -> Handle { - self.global_form().clone() - } -} - /// A vertex, defined in global (3D) coordinates /// /// This struct exists to distinguish between vertices and points at the type From 8ecbabea314de40c8337b47f6421732db06f31db Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 14:19:22 +0100 Subject: [PATCH 12/12] Rename `partial2` module to `partial` --- crates/fj-kernel/src/algorithms/approx/curve.rs | 2 +- crates/fj-kernel/src/algorithms/intersect/curve_edge.rs | 2 +- crates/fj-kernel/src/algorithms/intersect/curve_face.rs | 2 +- crates/fj-kernel/src/algorithms/intersect/face_face.rs | 2 +- crates/fj-kernel/src/algorithms/intersect/face_point.rs | 2 +- crates/fj-kernel/src/algorithms/intersect/ray_face.rs | 2 +- crates/fj-kernel/src/algorithms/intersect/surface_surface.rs | 2 +- crates/fj-kernel/src/algorithms/reverse/face.rs | 2 +- crates/fj-kernel/src/algorithms/sweep/curve.rs | 2 +- crates/fj-kernel/src/algorithms/sweep/edge.rs | 4 ++-- crates/fj-kernel/src/algorithms/sweep/face.rs | 2 +- crates/fj-kernel/src/algorithms/sweep/vertex.rs | 2 +- crates/fj-kernel/src/algorithms/triangulate/mod.rs | 2 +- crates/fj-kernel/src/builder/curve.rs | 2 +- crates/fj-kernel/src/builder/cycle.rs | 2 +- crates/fj-kernel/src/builder/edge.rs | 2 +- crates/fj-kernel/src/builder/face.rs | 2 +- crates/fj-kernel/src/builder/shell.rs | 2 +- crates/fj-kernel/src/builder/sketch.rs | 2 +- crates/fj-kernel/src/builder/surface.rs | 2 +- crates/fj-kernel/src/builder/vertex.rs | 2 +- crates/fj-kernel/src/iter.rs | 2 +- crates/fj-kernel/src/lib.rs | 2 +- crates/fj-kernel/src/objects/full/edge.rs | 4 +--- crates/fj-kernel/src/{partial2 => partial}/mod.rs | 0 crates/fj-kernel/src/{partial2 => partial}/objects/curve.rs | 2 +- crates/fj-kernel/src/{partial2 => partial}/objects/cycle.rs | 2 +- crates/fj-kernel/src/{partial2 => partial}/objects/edge.rs | 2 +- crates/fj-kernel/src/{partial2 => partial}/objects/face.rs | 2 +- crates/fj-kernel/src/{partial2 => partial}/objects/mod.rs | 0 crates/fj-kernel/src/{partial2 => partial}/objects/shell.rs | 2 +- crates/fj-kernel/src/{partial2 => partial}/objects/sketch.rs | 2 +- crates/fj-kernel/src/{partial2 => partial}/objects/solid.rs | 2 +- crates/fj-kernel/src/{partial2 => partial}/objects/surface.rs | 2 +- crates/fj-kernel/src/{partial2 => partial}/objects/vertex.rs | 2 +- crates/fj-kernel/src/{partial2 => partial}/traits.rs | 0 crates/fj-kernel/src/{partial2 => partial}/wrapper.rs | 2 +- crates/fj-kernel/src/validate/cycle.rs | 2 +- crates/fj-kernel/src/validate/edge.rs | 2 +- crates/fj-kernel/src/validate/face.rs | 2 +- crates/fj-kernel/src/validate/vertex.rs | 2 +- crates/fj-operations/src/difference_2d.rs | 2 +- crates/fj-operations/src/sketch.rs | 2 +- 43 files changed, 41 insertions(+), 43 deletions(-) rename crates/fj-kernel/src/{partial2 => partial}/mod.rs (100%) rename crates/fj-kernel/src/{partial2 => partial}/objects/curve.rs (97%) rename crates/fj-kernel/src/{partial2 => partial}/objects/cycle.rs (95%) rename crates/fj-kernel/src/{partial2 => partial}/objects/edge.rs (98%) rename crates/fj-kernel/src/{partial2 => partial}/objects/face.rs (96%) rename crates/fj-kernel/src/{partial2 => partial}/objects/mod.rs (100%) rename crates/fj-kernel/src/{partial2 => partial}/objects/shell.rs (94%) rename crates/fj-kernel/src/{partial2 => partial}/objects/sketch.rs (94%) rename crates/fj-kernel/src/{partial2 => partial}/objects/solid.rs (94%) rename crates/fj-kernel/src/{partial2 => partial}/objects/surface.rs (94%) rename crates/fj-kernel/src/{partial2 => partial}/objects/vertex.rs (98%) rename crates/fj-kernel/src/{partial2 => partial}/traits.rs (100%) rename crates/fj-kernel/src/{partial2 => partial}/wrapper.rs (99%) diff --git a/crates/fj-kernel/src/algorithms/approx/curve.rs b/crates/fj-kernel/src/algorithms/approx/curve.rs index fc6e15e19..eb32b1010 100644 --- a/crates/fj-kernel/src/algorithms/approx/curve.rs +++ b/crates/fj-kernel/src/algorithms/approx/curve.rs @@ -203,7 +203,7 @@ mod tests { builder::{CurveBuilder, SurfaceBuilder}, geometry::path::GlobalPath, insert::Insert, - partial2::{Partial, PartialCurve, PartialObject, PartialSurface}, + partial::{Partial, PartialCurve, PartialObject, PartialSurface}, services::Services, }; diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs index 7218107fd..d59f5ae66 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs @@ -80,7 +80,7 @@ mod tests { use crate::{ builder::{CurveBuilder, HalfEdgeBuilder}, objects::Vertex, - partial2::{ + partial::{ Partial, PartialCurve, PartialGlobalEdge, PartialHalfEdge, PartialObject, }, diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index 139e12dba..a702b6035 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -151,7 +151,7 @@ where mod tests { use crate::{ builder::{CurveBuilder, FaceBuilder}, - partial2::{Partial, PartialCurve, PartialFace, PartialObject}, + partial::{Partial, PartialCurve, PartialFace, PartialObject}, services::Services, }; diff --git a/crates/fj-kernel/src/algorithms/intersect/face_face.rs b/crates/fj-kernel/src/algorithms/intersect/face_face.rs index 306226ac1..247eb0b1b 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_face.rs @@ -71,7 +71,7 @@ mod tests { algorithms::intersect::CurveFaceIntersection, builder::{CurveBuilder, FaceBuilder}, insert::Insert, - partial2::{Partial, PartialCurve, PartialFace, PartialObject}, + partial::{Partial, PartialCurve, PartialFace, PartialObject}, services::Services, }; diff --git a/crates/fj-kernel/src/algorithms/intersect/face_point.rs b/crates/fj-kernel/src/algorithms/intersect/face_point.rs index 79a1d72cc..9b91005b8 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_point.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_point.rs @@ -139,7 +139,7 @@ mod tests { builder::FaceBuilder, insert::Insert, iter::ObjectIters, - partial2::{PartialFace, PartialObject}, + partial::{PartialFace, PartialObject}, services::Services, }; diff --git a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs index fbfdb496f..3c4ef18e0 100644 --- a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs @@ -155,7 +155,7 @@ mod tests { builder::FaceBuilder, insert::Insert, iter::ObjectIters, - partial2::{PartialFace, PartialObject}, + partial::{PartialFace, PartialObject}, services::Services, }; diff --git a/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs b/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs index 41c39e5e4..8b03efdbc 100644 --- a/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs +++ b/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs @@ -92,7 +92,7 @@ mod tests { algorithms::transform::TransformObject, builder::CurveBuilder, insert::Insert, - partial2::{Partial, PartialCurve, PartialObject}, + partial::{Partial, PartialCurve, PartialObject}, services::Services, }; diff --git a/crates/fj-kernel/src/algorithms/reverse/face.rs b/crates/fj-kernel/src/algorithms/reverse/face.rs index 3cc6a0375..caed07c55 100644 --- a/crates/fj-kernel/src/algorithms/reverse/face.rs +++ b/crates/fj-kernel/src/algorithms/reverse/face.rs @@ -1,7 +1,7 @@ use crate::{ insert::Insert, objects::{Face, Objects}, - partial2::{FullToPartialCache, Partial, PartialFace, PartialObject}, + partial::{FullToPartialCache, Partial, PartialFace, PartialObject}, services::Service, storage::Handle, }; diff --git a/crates/fj-kernel/src/algorithms/sweep/curve.rs b/crates/fj-kernel/src/algorithms/sweep/curve.rs index 7a5b0e437..3a4ba6cba 100644 --- a/crates/fj-kernel/src/algorithms/sweep/curve.rs +++ b/crates/fj-kernel/src/algorithms/sweep/curve.rs @@ -5,7 +5,7 @@ use crate::{ geometry::path::{GlobalPath, SurfacePath}, insert::Insert, objects::{Curve, Objects, Surface}, - partial2::{PartialObject, PartialSurface}, + partial::{PartialObject, PartialSurface}, services::Service, storage::Handle, }; diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 83ef1c103..7ef4f6f63 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -10,7 +10,7 @@ use crate::{ Curve, Cycle, Face, GlobalEdge, HalfEdge, Objects, SurfaceVertex, Vertex, }, - partial2::{Partial, PartialFace, PartialObject}, + partial::{Partial, PartialFace, PartialObject}, services::Service, storage::Handle, }; @@ -195,7 +195,7 @@ mod tests { builder::HalfEdgeBuilder, insert::Insert, objects::{Cycle, Vertex}, - partial2::{ + partial::{ Partial, PartialCurve, PartialFace, PartialGlobalEdge, PartialHalfEdge, PartialObject, PartialSurfaceVertex, PartialVertex, diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 914945f62..688a24d37 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -92,7 +92,7 @@ mod tests { builder::{FaceBuilder, HalfEdgeBuilder}, insert::Insert, objects::{Sketch, Vertex}, - partial2::{ + partial::{ Partial, PartialFace, PartialGlobalEdge, PartialHalfEdge, PartialObject, }, diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index cfc3d1297..ae67900a2 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -167,7 +167,7 @@ mod tests { builder::{CurveBuilder, HalfEdgeBuilder}, insert::Insert, objects::Vertex, - partial2::{ + partial::{ Partial, PartialCurve, PartialGlobalEdge, PartialHalfEdge, PartialObject, PartialSurfaceVertex, PartialVertex, }, diff --git a/crates/fj-kernel/src/algorithms/triangulate/mod.rs b/crates/fj-kernel/src/algorithms/triangulate/mod.rs index 391dd310c..3805207ee 100644 --- a/crates/fj-kernel/src/algorithms/triangulate/mod.rs +++ b/crates/fj-kernel/src/algorithms/triangulate/mod.rs @@ -80,7 +80,7 @@ mod tests { builder::FaceBuilder, insert::Insert, objects::Face, - partial2::{PartialFace, PartialObject}, + partial::{PartialFace, PartialObject}, services::Services, storage::Handle, }; diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index e4154888f..85d71a63c 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -1,6 +1,6 @@ use fj_math::{Point, Scalar, Vector}; -use crate::{geometry::path::SurfacePath, partial2::PartialCurve}; +use crate::{geometry::path::SurfacePath, partial::PartialCurve}; /// Builder API for [`PartialCurve`] pub trait CurveBuilder { diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 130a54885..c43a83c91 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -3,7 +3,7 @@ use fj_math::Point; use crate::{ objects::{Curve, Surface, SurfaceVertex, Vertex}, - partial2::{ + partial::{ Partial, PartialCurve, PartialCycle, PartialGlobalEdge, PartialHalfEdge, PartialSurfaceVertex, PartialVertex, }, diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 156ac2c7a..3efb4613e 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -3,7 +3,7 @@ use fj_math::{Point, Scalar}; use crate::{ objects::{Curve, Surface, Vertex}, - partial2::{Partial, PartialGlobalEdge, PartialHalfEdge}, + partial::{Partial, PartialGlobalEdge, PartialHalfEdge}, storage::Handle, }; diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index 1bda6225f..2eb68d7c5 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -2,7 +2,7 @@ use fj_math::Point; use crate::{ objects::Surface, - partial2::{Partial, PartialCycle, PartialFace}, + partial::{Partial, PartialCycle, PartialFace}, storage::Handle, }; diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 517a2b41d..2f1dc1818 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -9,7 +9,7 @@ use crate::{ builder::{FaceBuilder, HalfEdgeBuilder, SurfaceBuilder}, insert::Insert, objects::{Face, FaceSet, HalfEdge, Objects, Shell, Vertex}, - partial2::{ + partial::{ Partial, PartialCurve, PartialCycle, PartialFace, PartialGlobalEdge, PartialHalfEdge, PartialObject, PartialSurface, PartialSurfaceVertex, PartialVertex, diff --git a/crates/fj-kernel/src/builder/sketch.rs b/crates/fj-kernel/src/builder/sketch.rs index 68088b58d..3f94b6692 100644 --- a/crates/fj-kernel/src/builder/sketch.rs +++ b/crates/fj-kernel/src/builder/sketch.rs @@ -3,7 +3,7 @@ use fj_math::Point; use crate::{ insert::Insert, objects::{Face, FaceSet, Objects, Sketch, Surface}, - partial2::{PartialFace, PartialObject}, + partial::{PartialFace, PartialObject}, services::Service, storage::Handle, }; diff --git a/crates/fj-kernel/src/builder/surface.rs b/crates/fj-kernel/src/builder/surface.rs index 03f1c52e5..cc1d57728 100644 --- a/crates/fj-kernel/src/builder/surface.rs +++ b/crates/fj-kernel/src/builder/surface.rs @@ -2,7 +2,7 @@ use fj_math::{Line, Point, Vector}; use crate::{ geometry::{path::GlobalPath, surface::SurfaceGeometry}, - partial2::PartialSurface, + partial::PartialSurface, }; /// Builder API for [`PartialSurface`] diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 445d504ad..2d12dd6d0 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -3,7 +3,7 @@ use fj_math::Point; use crate::{ geometry::surface::SurfaceGeometry, objects::Curve, - partial2::{ + partial::{ Partial, PartialGlobalVertex, PartialSurfaceVertex, PartialVertex, }, }; diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index 133a61cd7..6ec8de881 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -370,7 +370,7 @@ mod tests { GlobalCurve, GlobalVertex, Objects, Shell, Sketch, Solid, SurfaceVertex, Vertex, }, - partial2::{ + partial::{ Partial, PartialCurve, PartialCycle, PartialFace, PartialGlobalEdge, PartialHalfEdge, PartialObject, }, diff --git a/crates/fj-kernel/src/lib.rs b/crates/fj-kernel/src/lib.rs index 529c2acf5..0a1b20ea8 100644 --- a/crates/fj-kernel/src/lib.rs +++ b/crates/fj-kernel/src/lib.rs @@ -98,7 +98,7 @@ pub mod geometry; pub mod insert; pub mod iter; pub mod objects; -pub mod partial2; +pub mod partial; pub mod services; pub mod storage; pub mod validate; diff --git a/crates/fj-kernel/src/objects/full/edge.rs b/crates/fj-kernel/src/objects/full/edge.rs index bd86cdf96..e45c5176d 100644 --- a/crates/fj-kernel/src/objects/full/edge.rs +++ b/crates/fj-kernel/src/objects/full/edge.rs @@ -152,9 +152,7 @@ mod tests { use crate::{ builder::HalfEdgeBuilder, objects::Vertex, - partial2::{ - Partial, PartialGlobalEdge, PartialHalfEdge, PartialObject, - }, + partial::{Partial, PartialGlobalEdge, PartialHalfEdge, PartialObject}, services::Services, }; diff --git a/crates/fj-kernel/src/partial2/mod.rs b/crates/fj-kernel/src/partial/mod.rs similarity index 100% rename from crates/fj-kernel/src/partial2/mod.rs rename to crates/fj-kernel/src/partial/mod.rs diff --git a/crates/fj-kernel/src/partial2/objects/curve.rs b/crates/fj-kernel/src/partial/objects/curve.rs similarity index 97% rename from crates/fj-kernel/src/partial2/objects/curve.rs rename to crates/fj-kernel/src/partial/objects/curve.rs index d6029ddbd..54fa9d7e1 100644 --- a/crates/fj-kernel/src/partial2/objects/curve.rs +++ b/crates/fj-kernel/src/partial/objects/curve.rs @@ -1,7 +1,7 @@ use crate::{ geometry::path::SurfacePath, objects::{Curve, GlobalCurve, Objects, Surface}, - partial2::{FullToPartialCache, Partial, PartialObject}, + partial::{FullToPartialCache, Partial, PartialObject}, services::Service, }; diff --git a/crates/fj-kernel/src/partial2/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs similarity index 95% rename from crates/fj-kernel/src/partial2/objects/cycle.rs rename to crates/fj-kernel/src/partial/objects/cycle.rs index f6cab75e4..2c21d79f6 100644 --- a/crates/fj-kernel/src/partial2/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -1,6 +1,6 @@ use crate::{ objects::{Cycle, HalfEdge, Objects, Surface}, - partial2::{FullToPartialCache, Partial, PartialObject}, + partial::{FullToPartialCache, Partial, PartialObject}, services::Service, }; diff --git a/crates/fj-kernel/src/partial2/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs similarity index 98% rename from crates/fj-kernel/src/partial2/objects/edge.rs rename to crates/fj-kernel/src/partial/objects/edge.rs index 494ae909a..22b9bd22c 100644 --- a/crates/fj-kernel/src/partial2/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -4,7 +4,7 @@ use crate::{ objects::{ Curve, GlobalCurve, GlobalEdge, GlobalVertex, HalfEdge, Objects, Vertex, }, - partial2::{FullToPartialCache, Partial, PartialObject, PartialVertex}, + partial::{FullToPartialCache, Partial, PartialObject, PartialVertex}, services::Service, }; diff --git a/crates/fj-kernel/src/partial2/objects/face.rs b/crates/fj-kernel/src/partial/objects/face.rs similarity index 96% rename from crates/fj-kernel/src/partial2/objects/face.rs rename to crates/fj-kernel/src/partial/objects/face.rs index b202bba95..28de124da 100644 --- a/crates/fj-kernel/src/partial2/objects/face.rs +++ b/crates/fj-kernel/src/partial/objects/face.rs @@ -2,7 +2,7 @@ use fj_interop::mesh::Color; use crate::{ objects::{Cycle, Face, Objects}, - partial2::{FullToPartialCache, Partial, PartialObject}, + partial::{FullToPartialCache, Partial, PartialObject}, services::Service, }; diff --git a/crates/fj-kernel/src/partial2/objects/mod.rs b/crates/fj-kernel/src/partial/objects/mod.rs similarity index 100% rename from crates/fj-kernel/src/partial2/objects/mod.rs rename to crates/fj-kernel/src/partial/objects/mod.rs diff --git a/crates/fj-kernel/src/partial2/objects/shell.rs b/crates/fj-kernel/src/partial/objects/shell.rs similarity index 94% rename from crates/fj-kernel/src/partial2/objects/shell.rs rename to crates/fj-kernel/src/partial/objects/shell.rs index 6d2751825..e13275690 100644 --- a/crates/fj-kernel/src/partial2/objects/shell.rs +++ b/crates/fj-kernel/src/partial/objects/shell.rs @@ -1,6 +1,6 @@ use crate::{ objects::{Face, Objects, Shell}, - partial2::{FullToPartialCache, Partial, PartialObject}, + partial::{FullToPartialCache, Partial, PartialObject}, services::Service, }; diff --git a/crates/fj-kernel/src/partial2/objects/sketch.rs b/crates/fj-kernel/src/partial/objects/sketch.rs similarity index 94% rename from crates/fj-kernel/src/partial2/objects/sketch.rs rename to crates/fj-kernel/src/partial/objects/sketch.rs index f7a2f25e6..c0b239b3a 100644 --- a/crates/fj-kernel/src/partial2/objects/sketch.rs +++ b/crates/fj-kernel/src/partial/objects/sketch.rs @@ -1,6 +1,6 @@ use crate::{ objects::{Face, Objects, Sketch}, - partial2::{FullToPartialCache, Partial, PartialObject}, + partial::{FullToPartialCache, Partial, PartialObject}, services::Service, }; diff --git a/crates/fj-kernel/src/partial2/objects/solid.rs b/crates/fj-kernel/src/partial/objects/solid.rs similarity index 94% rename from crates/fj-kernel/src/partial2/objects/solid.rs rename to crates/fj-kernel/src/partial/objects/solid.rs index 4d81b098e..557c15b80 100644 --- a/crates/fj-kernel/src/partial2/objects/solid.rs +++ b/crates/fj-kernel/src/partial/objects/solid.rs @@ -1,6 +1,6 @@ use crate::{ objects::{Objects, Shell, Solid}, - partial2::{FullToPartialCache, Partial, PartialObject}, + partial::{FullToPartialCache, Partial, PartialObject}, services::Service, }; diff --git a/crates/fj-kernel/src/partial2/objects/surface.rs b/crates/fj-kernel/src/partial/objects/surface.rs similarity index 94% rename from crates/fj-kernel/src/partial2/objects/surface.rs rename to crates/fj-kernel/src/partial/objects/surface.rs index 547967786..96ad6edf7 100644 --- a/crates/fj-kernel/src/partial2/objects/surface.rs +++ b/crates/fj-kernel/src/partial/objects/surface.rs @@ -1,7 +1,7 @@ use crate::{ geometry::surface::SurfaceGeometry, objects::{Objects, Surface}, - partial2::{FullToPartialCache, PartialObject}, + partial::{FullToPartialCache, PartialObject}, services::Service, }; diff --git a/crates/fj-kernel/src/partial2/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs similarity index 98% rename from crates/fj-kernel/src/partial2/objects/vertex.rs rename to crates/fj-kernel/src/partial/objects/vertex.rs index e8bb7a667..eb4ece440 100644 --- a/crates/fj-kernel/src/partial2/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -3,7 +3,7 @@ use fj_math::Point; use crate::{ builder::SurfaceVertexBuilder, objects::{Curve, GlobalVertex, Objects, Surface, SurfaceVertex, Vertex}, - partial2::{FullToPartialCache, Partial, PartialCurve, PartialObject}, + partial::{FullToPartialCache, Partial, PartialCurve, PartialObject}, services::Service, }; diff --git a/crates/fj-kernel/src/partial2/traits.rs b/crates/fj-kernel/src/partial/traits.rs similarity index 100% rename from crates/fj-kernel/src/partial2/traits.rs rename to crates/fj-kernel/src/partial/traits.rs diff --git a/crates/fj-kernel/src/partial2/wrapper.rs b/crates/fj-kernel/src/partial/wrapper.rs similarity index 99% rename from crates/fj-kernel/src/partial2/wrapper.rs rename to crates/fj-kernel/src/partial/wrapper.rs index c9a69cdb4..46c9dbf8b 100644 --- a/crates/fj-kernel/src/partial2/wrapper.rs +++ b/crates/fj-kernel/src/partial/wrapper.rs @@ -12,7 +12,7 @@ use type_map::TypeMap; use crate::{ insert::Insert, objects::Objects, - partial2::traits::PartialObject, + partial::traits::PartialObject, services::Service, storage::{Handle, ObjectId}, }; diff --git a/crates/fj-kernel/src/validate/cycle.rs b/crates/fj-kernel/src/validate/cycle.rs index a79e4edd6..82cf04de6 100644 --- a/crates/fj-kernel/src/validate/cycle.rs +++ b/crates/fj-kernel/src/validate/cycle.rs @@ -68,7 +68,7 @@ mod tests { use crate::{ builder::CycleBuilder, objects::Cycle, - partial2::{Partial, PartialCycle, PartialObject}, + partial::{Partial, PartialCycle, PartialObject}, services::Services, validate::Validate, }; diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index 94d312d2e..8008fd674 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -206,7 +206,7 @@ mod tests { builder::HalfEdgeBuilder, insert::Insert, objects::{GlobalCurve, HalfEdge, Vertex}, - partial2::{ + partial::{ Partial, PartialGlobalEdge, PartialHalfEdge, PartialObject, PartialSurfaceVertex, PartialVertex, }, diff --git a/crates/fj-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index d24c94c39..80795932b 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -108,7 +108,7 @@ mod tests { builder::{CycleBuilder, FaceBuilder}, insert::Insert, objects::Face, - partial2::{PartialCycle, PartialFace, PartialObject}, + partial::{PartialCycle, PartialFace, PartialObject}, services::Services, validate::Validate, }; diff --git a/crates/fj-kernel/src/validate/vertex.rs b/crates/fj-kernel/src/validate/vertex.rs index baf9a884a..bfa1cc5bc 100644 --- a/crates/fj-kernel/src/validate/vertex.rs +++ b/crates/fj-kernel/src/validate/vertex.rs @@ -183,7 +183,7 @@ mod tests { builder::{CurveBuilder, SurfaceVertexBuilder}, insert::Insert, objects::{GlobalVertex, SurfaceVertex, Vertex}, - partial2::{ + partial::{ Partial, PartialCurve, PartialObject, PartialSurfaceVertex, PartialVertex, }, diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index 030cc2bfe..a3ac475d3 100644 --- a/crates/fj-operations/src/difference_2d.rs +++ b/crates/fj-operations/src/difference_2d.rs @@ -6,7 +6,7 @@ use fj_kernel::{ insert::Insert, iter::ObjectIters, objects::{Objects, Sketch}, - partial2::{Partial, PartialFace, PartialObject}, + partial::{Partial, PartialFace, PartialObject}, services::Service, }; use fj_math::Aabb; diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 64d9a8e83..e92e3addf 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -5,7 +5,7 @@ use fj_kernel::{ builder::{FaceBuilder, HalfEdgeBuilder}, insert::Insert, objects::{Objects, Sketch, Vertex}, - partial2::{ + partial::{ Partial, PartialCurve, PartialCycle, PartialFace, PartialGlobalEdge, PartialHalfEdge, PartialObject, PartialSurfaceVertex, PartialVertex, },