From e8e74cf2954573f8de5891f08d1ed434b465294f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 9 Nov 2022 14:30:32 +0100 Subject: [PATCH] Extract non-essential methods from `PartialFace` --- .../src/algorithms/intersect/curve_face.rs | 2 +- .../src/algorithms/intersect/face_face.rs | 2 +- .../src/algorithms/intersect/face_point.rs | 1 + .../src/algorithms/intersect/ray_face.rs | 1 + crates/fj-kernel/src/algorithms/sweep/face.rs | 2 +- .../src/algorithms/triangulate/mod.rs | 1 + crates/fj-kernel/src/builder/face.rs | 49 +++++++++++++++++++ crates/fj-kernel/src/builder/mod.rs | 2 + crates/fj-kernel/src/builder/shell.rs | 2 +- crates/fj-kernel/src/builder/sketch.rs | 2 + crates/fj-kernel/src/iter.rs | 2 +- crates/fj-kernel/src/partial/objects/face.rs | 30 +----------- crates/fj-kernel/src/validate/face.rs | 2 +- crates/fj-operations/src/sketch.rs | 2 +- 14 files changed, 64 insertions(+), 36 deletions(-) create mode 100644 crates/fj-kernel/src/builder/face.rs diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index 3dbe4a484..9e87ec130 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -150,7 +150,7 @@ where #[cfg(test)] mod tests { use crate::{ - builder::CurveBuilder, + builder::{CurveBuilder, FaceBuilder}, objects::{Curve, Face, Objects}, partial::HasPartial, }; diff --git a/crates/fj-kernel/src/algorithms/intersect/face_face.rs b/crates/fj-kernel/src/algorithms/intersect/face_face.rs index 3f72039e7..66b41ac30 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_face.rs @@ -67,7 +67,7 @@ mod tests { use crate::{ algorithms::intersect::CurveFaceIntersection, - builder::CurveBuilder, + builder::{CurveBuilder, FaceBuilder}, objects::{Curve, Face, Objects}, partial::HasPartial, }; diff --git a/crates/fj-kernel/src/algorithms/intersect/face_point.rs b/crates/fj-kernel/src/algorithms/intersect/face_point.rs index 007caa096..6fa3d17b9 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_point.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_point.rs @@ -136,6 +136,7 @@ mod tests { use crate::{ algorithms::intersect::{face_point::FacePointIntersection, Intersect}, + builder::FaceBuilder, iter::ObjectIters, objects::{Face, Objects}, partial::HasPartial, diff --git a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs index 9a3b873da..38201c372 100644 --- a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs @@ -152,6 +152,7 @@ mod tests { }, transform::TransformObject, }, + builder::FaceBuilder, iter::ObjectIters, objects::{Face, Objects}, partial::HasPartial, diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 181da6a69..3919832f7 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -84,7 +84,7 @@ mod tests { use crate::{ algorithms::{reverse::Reverse, transform::TransformObject}, - builder::HalfEdgeBuilder, + builder::{FaceBuilder, HalfEdgeBuilder}, objects::{Face, HalfEdge, Objects, Sketch}, partial::HasPartial, }; diff --git a/crates/fj-kernel/src/algorithms/triangulate/mod.rs b/crates/fj-kernel/src/algorithms/triangulate/mod.rs index 8fc63496a..6f9579c70 100644 --- a/crates/fj-kernel/src/algorithms/triangulate/mod.rs +++ b/crates/fj-kernel/src/algorithms/triangulate/mod.rs @@ -84,6 +84,7 @@ mod tests { use crate::{ algorithms::approx::{Approx, Tolerance}, + builder::FaceBuilder, objects::{Face, Objects}, partial::HasPartial, storage::Handle, diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs new file mode 100644 index 000000000..41f6dc5b1 --- /dev/null +++ b/crates/fj-kernel/src/builder/face.rs @@ -0,0 +1,49 @@ +use fj_math::Point; + +use crate::{ + objects::Cycle, + partial::{HasPartial, PartialFace}, +}; + +use super::CycleBuilder; + +/// Builder API for [`PartialFace`] +pub trait FaceBuilder { + /// Update the [`PartialFace`] with an exterior polygon + fn with_exterior_polygon_from_points( + self, + points: impl IntoIterator>>, + ) -> Self; + + /// Update the [`PartialFace`] with an interior polygon + fn with_interior_polygon_from_points( + self, + points: impl IntoIterator>>, + ) -> Self; +} + +impl FaceBuilder for PartialFace { + fn with_exterior_polygon_from_points( + self, + points: impl IntoIterator>>, + ) -> Self { + let surface = self.surface().expect("Need surface to create polygon"); + + self.with_exterior( + Cycle::partial() + .with_poly_chain_from_points(surface, points) + .close_with_line_segment(), + ) + } + + fn with_interior_polygon_from_points( + self, + points: impl IntoIterator>>, + ) -> Self { + let surface = self.surface().expect("Need surface to build polygon."); + + self.with_interiors([Cycle::partial() + .with_poly_chain_from_points(surface, points) + .close_with_line_segment()]) + } +} diff --git a/crates/fj-kernel/src/builder/mod.rs b/crates/fj-kernel/src/builder/mod.rs index b6cf74d99..1d96e73d7 100644 --- a/crates/fj-kernel/src/builder/mod.rs +++ b/crates/fj-kernel/src/builder/mod.rs @@ -11,12 +11,14 @@ mod solid; mod curve; mod cycle; mod edge; +mod face; mod vertex; pub use self::{ curve::CurveBuilder, cycle::CycleBuilder, edge::{GlobalEdgeBuilder, HalfEdgeBuilder}, + face::FaceBuilder, shell::ShellBuilder, sketch::SketchBuilder, solid::SolidBuilder, diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index ef1580478..867519507 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -5,7 +5,7 @@ use fj_math::Scalar; use crate::{ algorithms::transform::TransformObject, - builder::HalfEdgeBuilder, + builder::{FaceBuilder, HalfEdgeBuilder}, objects::{ Curve, Cycle, Face, FaceSet, HalfEdge, Objects, Shell, Surface, SurfaceVertex, Vertex, diff --git a/crates/fj-kernel/src/builder/sketch.rs b/crates/fj-kernel/src/builder/sketch.rs index 7052b4a36..aad2b9620 100644 --- a/crates/fj-kernel/src/builder/sketch.rs +++ b/crates/fj-kernel/src/builder/sketch.rs @@ -6,6 +6,8 @@ use crate::{ storage::Handle, }; +use super::FaceBuilder; + /// API for building a [`Sketch`] /// /// Also see [`Sketch::builder`]. diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index 3be9a3493..6708c96b1 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -360,7 +360,7 @@ impl Iterator for Iter { #[cfg(test)] mod tests { use crate::{ - builder::{CurveBuilder, CycleBuilder, HalfEdgeBuilder}, + builder::{CurveBuilder, CycleBuilder, FaceBuilder, HalfEdgeBuilder}, objects::{ Curve, Cycle, Face, GlobalCurve, GlobalVertex, HalfEdge, Objects, Shell, Sketch, Solid, SurfaceVertex, Vertex, diff --git a/crates/fj-kernel/src/partial/objects/face.rs b/crates/fj-kernel/src/partial/objects/face.rs index 87cf3bb23..c2dbf2a33 100644 --- a/crates/fj-kernel/src/partial/objects/face.rs +++ b/crates/fj-kernel/src/partial/objects/face.rs @@ -1,10 +1,8 @@ use fj_interop::mesh::Color; -use fj_math::Point; use crate::{ - builder::CycleBuilder, objects::{Cycle, Face, Objects, Surface}, - partial::{util::merge_options, HasPartial, MaybePartial}, + partial::{util::merge_options, MaybePartial}, storage::Handle, validate::ValidationError, }; @@ -56,20 +54,6 @@ impl PartialFace { self } - /// Build the [`Face`] with an exterior polygon from the provided points - pub fn with_exterior_polygon_from_points( - self, - points: impl IntoIterator>>, - ) -> Self { - let surface = self.surface().expect("Need surface to create polygon"); - - self.with_exterior( - Cycle::partial() - .with_poly_chain_from_points(surface, points) - .close_with_line_segment(), - ) - } - /// Build the [`Face`] with the provided interior polygons pub fn with_interiors( mut self, @@ -80,18 +64,6 @@ impl PartialFace { self } - /// Build the [`Face`] with an interior polygon from the provided points - pub fn with_interior_polygon_from_points( - self, - points: impl IntoIterator>>, - ) -> Self { - let surface = self.surface().expect("Need surface to build polygon."); - - self.with_interiors([Cycle::partial() - .with_poly_chain_from_points(surface, points) - .close_with_line_segment()]) - } - /// Build the [`Face`] with the provided color pub fn with_color(mut self, color: Color) -> Self { self.color = Some(color); diff --git a/crates/fj-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index f0b0fdd81..098b5ea28 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -105,7 +105,7 @@ impl FaceValidationError { mod tests { use crate::{ algorithms::reverse::Reverse, - builder::CycleBuilder, + builder::{CycleBuilder, FaceBuilder}, objects::{Cycle, Face, Objects}, partial::HasPartial, validate::Validate, diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index f3ebf3dbd..83ab1911c 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -2,7 +2,7 @@ use std::ops::Deref; use fj_interop::{debug::DebugInfo, mesh::Color}; use fj_kernel::{ - builder::HalfEdgeBuilder, + builder::{FaceBuilder, HalfEdgeBuilder}, objects::{Cycle, Face, HalfEdge, Objects, Sketch}, partial::HasPartial, validate::ValidationError,