diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index 76d839a07..3724fb123 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, FaceBuilder}, + builder::{CurveBuilder, CycleBuilder, FaceBuilder}, partial::{Partial, PartialCurve, PartialFace, PartialObject}, services::Services, }; @@ -188,8 +188,12 @@ mod tests { let face = { let mut face = PartialFace::default(); face.exterior.write().surface = surface; - face.update_exterior_as_polygon_from_points(exterior); - face.add_interior_polygon_from_points(interior); + face.exterior + .write() + .update_as_polygon_from_points(exterior); + face.add_interior() + .write() + .update_as_polygon_from_points(interior); face.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 a8ba4668a..499aa0719 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_face.rs @@ -69,7 +69,7 @@ mod tests { use crate::{ algorithms::intersect::CurveFaceIntersection, - builder::{CurveBuilder, FaceBuilder}, + builder::{CurveBuilder, CycleBuilder}, insert::Insert, partial::{Partial, PartialCurve, PartialFace, PartialObject}, services::Services, @@ -95,7 +95,7 @@ mod tests { .map(|surface| { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(surface); - face.update_exterior_as_polygon_from_points(points); + face.exterior.write().update_as_polygon_from_points(points); face.build(&mut services.objects) }); @@ -124,7 +124,7 @@ mod tests { let [a, b] = surfaces.clone().map(|surface| { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(surface); - face.update_exterior_as_polygon_from_points(points); + face.exterior.write().update_as_polygon_from_points(points); face.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 465f260b2..698999e6c 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_point.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_point.rs @@ -135,7 +135,7 @@ mod tests { use crate::{ algorithms::intersect::{face_point::FacePointIntersection, Intersect}, - builder::FaceBuilder, + builder::CycleBuilder, insert::Insert, partial::{Partial, PartialFace, PartialObject}, services::Services, @@ -148,7 +148,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.xy_plane()); - face.update_exterior_as_polygon_from_points([ + face.exterior.write().update_as_polygon_from_points([ [0., 0.], [1., 1.], [0., 2.], @@ -169,7 +169,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.xy_plane()); - face.update_exterior_as_polygon_from_points([ + face.exterior.write().update_as_polygon_from_points([ [0., 0.], [2., 1.], [0., 2.], @@ -193,7 +193,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.xy_plane()); - face.update_exterior_as_polygon_from_points([ + face.exterior.write().update_as_polygon_from_points([ [4., 2.], [0., 4.], [0., 0.], @@ -217,7 +217,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.xy_plane()); - face.update_exterior_as_polygon_from_points([ + face.exterior.write().update_as_polygon_from_points([ [0., 0.], [2., 1.], [3., 0.], @@ -242,7 +242,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.xy_plane()); - face.update_exterior_as_polygon_from_points([ + face.exterior.write().update_as_polygon_from_points([ [0., 0.], [2., 1.], [3., 1.], @@ -267,7 +267,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.xy_plane()); - face.update_exterior_as_polygon_from_points([ + face.exterior.write().update_as_polygon_from_points([ [0., 0.], [2., 1.], [3., 1.], @@ -293,7 +293,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.xy_plane()); - face.update_exterior_as_polygon_from_points([ + face.exterior.write().update_as_polygon_from_points([ [0., 0.], [2., 0.], [0., 1.], @@ -327,7 +327,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.xy_plane()); - face.update_exterior_as_polygon_from_points([ + face.exterior.write().update_as_polygon_from_points([ [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 21cb23157..7565a50ef 100644 --- a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs @@ -151,7 +151,7 @@ mod tests { }, transform::TransformObject, }, - builder::FaceBuilder, + builder::CycleBuilder, insert::Insert, partial::{Partial, PartialFace, PartialObject}, services::Services, @@ -166,7 +166,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.yz_plane()); - face.update_exterior_as_polygon_from_points([ + face.exterior.write().update_as_polygon_from_points([ [-1., -1.], [1., -1.], [1., 1.], @@ -189,7 +189,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.yz_plane()); - face.update_exterior_as_polygon_from_points([ + face.exterior.write().update_as_polygon_from_points([ [-1., -1.], [1., -1.], [1., 1.], @@ -215,7 +215,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.yz_plane()); - face.update_exterior_as_polygon_from_points([ + face.exterior.write().update_as_polygon_from_points([ [-1., -1.], [1., -1.], [1., 1.], @@ -238,7 +238,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.yz_plane()); - face.update_exterior_as_polygon_from_points([ + face.exterior.write().update_as_polygon_from_points([ [-1., -1.], [1., -1.], [1., 1.], @@ -273,7 +273,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.yz_plane()); - face.update_exterior_as_polygon_from_points([ + face.exterior.write().update_as_polygon_from_points([ [-1., -1.], [1., -1.], [1., 1.], @@ -307,7 +307,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.xy_plane()); - face.update_exterior_as_polygon_from_points([ + face.exterior.write().update_as_polygon_from_points([ [-1., -1.], [1., -1.], [1., 1.], @@ -332,7 +332,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.xy_plane()); - face.update_exterior_as_polygon_from_points([ + face.exterior.write().update_as_polygon_from_points([ [-1., -1.], [1., -1.], [1., 1.], diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 65d0f298f..7f54e4ff4 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -87,7 +87,7 @@ mod tests { use crate::{ algorithms::{reverse::Reverse, transform::TransformObject}, - builder::{FaceBuilder, HalfEdgeBuilder, SketchBuilder}, + builder::{CycleBuilder, HalfEdgeBuilder, SketchBuilder}, insert::Insert, partial::{ Partial, PartialFace, PartialHalfEdge, PartialObject, PartialSketch, @@ -116,7 +116,10 @@ mod tests { let mut bottom = PartialFace::default(); bottom.exterior.write().surface = Partial::from(surface.clone()); - bottom.update_exterior_as_polygon_from_points(TRIANGLE); + bottom + .exterior + .write() + .update_as_polygon_from_points(TRIANGLE); let bottom = bottom .build(&mut services.objects) .insert(&mut services.objects) @@ -124,7 +127,7 @@ mod tests { let mut top = PartialFace::default(); top.exterior.write().surface = Partial::from(surface.translate(UP, &mut services.objects)); - top.update_exterior_as_polygon_from_points(TRIANGLE); + top.exterior.write().update_as_polygon_from_points(TRIANGLE); let top = top .build(&mut services.objects) .insert(&mut services.objects); @@ -169,14 +172,17 @@ mod tests { bottom.exterior.write().surface = Partial::from( surface.clone().translate(DOWN, &mut services.objects), ); - bottom.update_exterior_as_polygon_from_points(TRIANGLE); + bottom + .exterior + .write() + .update_as_polygon_from_points(TRIANGLE); let bottom = bottom .build(&mut services.objects) .insert(&mut services.objects) .reverse(&mut services.objects); let mut top = PartialFace::default(); top.exterior.write().surface = Partial::from(surface); - top.update_exterior_as_polygon_from_points(TRIANGLE); + top.exterior.write().update_as_polygon_from_points(TRIANGLE); let top = top .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 c252bb7fc..ec841dd1a 100644 --- a/crates/fj-kernel/src/algorithms/triangulate/mod.rs +++ b/crates/fj-kernel/src/algorithms/triangulate/mod.rs @@ -77,7 +77,7 @@ mod tests { use crate::{ algorithms::approx::{Approx, Tolerance}, - builder::FaceBuilder, + builder::{CycleBuilder, FaceBuilder}, insert::Insert, objects::Face, partial::{Partial, PartialFace, PartialObject}, @@ -99,7 +99,9 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.xy_plane()); - face.update_exterior_as_polygon_from_points([a, b, c, d]); + face.exterior + .write() + .update_as_polygon_from_points([a, b, c, d]); let face = face .build(&mut services.objects) .insert(&mut services.objects); @@ -136,8 +138,12 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(surface.clone()); - face.update_exterior_as_polygon_from_points([a, b, c, d]); - face.add_interior_polygon_from_points([e, f, g, h]); + face.exterior + .write() + .update_as_polygon_from_points([a, b, c, d]); + face.add_interior() + .write() + .update_as_polygon_from_points([e, f, g, h]); let face = face .build(&mut services.objects) .insert(&mut services.objects); @@ -196,7 +202,9 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(surface.clone()); - face.update_exterior_as_polygon_from_points([a, b, c, d, e]); + face.exterior + .write() + .update_as_polygon_from_points([a, b, c, d, e]); let face = 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 fb5e74f61..33ec5f27d 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -1,76 +1,21 @@ -use fj_math::Point; - use crate::{ - objects::HalfEdge, + objects::Cycle, partial::{Partial, PartialCycle, PartialFace}, }; -use super::CycleBuilder; - /// Builder API for [`PartialFace`] pub trait FaceBuilder { - /// Update the face exterior as a polygon from the provided points - fn update_exterior_as_polygon_from_points( - &mut self, - points: impl IntoIterator>>, - ) -> Vec>; - - /// Update the face exterior as a polygon - fn update_exterior_as_polygon(&mut self); - - /// Update the face exterior as a triangle, from 3D points - /// - /// Uses the three points to infer a plane that is used as the surface. - /// - /// # Implementation Note - /// - /// This method is probably just temporary, and will be generalized into a - /// "update as polygon from global points" method sooner or later. For now, - /// I didn't want to deal with the question of how to infer the surface, and - /// how to handle points that don't fit that surface. - fn update_exterior_as_triangle_from_global_points( - &mut self, - points: [impl Into>; 3], - ) -> [Partial; 3]; - - /// Add an interior polygon, from the provided points - fn add_interior_polygon_from_points( - &mut self, - points: impl IntoIterator>>, - ); + /// Add an interior cycle + fn add_interior(&mut self) -> Partial; } impl FaceBuilder for PartialFace { - fn update_exterior_as_polygon_from_points( - &mut self, - points: impl IntoIterator>>, - ) -> Vec> { - self.exterior.write().update_as_polygon_from_points(points) - } - - fn update_exterior_as_polygon(&mut self) { - self.exterior.write().update_as_polygon() - } - - fn update_exterior_as_triangle_from_global_points( - &mut self, - points_global: [impl Into>; 3], - ) -> [Partial; 3] { - self.exterior - .write() - .update_as_triangle_from_global_points(points_global) - } - - fn add_interior_polygon_from_points( - &mut self, - points: impl IntoIterator>>, - ) { - let mut cycle = PartialCycle { + fn add_interior(&mut self) -> Partial { + let cycle = Partial::from_partial(PartialCycle { surface: self.exterior.read().surface.clone(), ..Default::default() - }; - cycle.update_as_polygon_from_points(points); - - self.interiors.push(Partial::from_partial(cycle)); + }); + self.interiors.push(cycle.clone()); + cycle } } diff --git a/crates/fj-kernel/src/builder/sketch.rs b/crates/fj-kernel/src/builder/sketch.rs index 57ca036fb..890804b2a 100644 --- a/crates/fj-kernel/src/builder/sketch.rs +++ b/crates/fj-kernel/src/builder/sketch.rs @@ -5,7 +5,7 @@ use crate::{ partial::{Partial, PartialFace, PartialSketch}, }; -use super::FaceBuilder; +use super::CycleBuilder; /// Builder API for [`PartialSketch`] pub trait SketchBuilder { @@ -25,7 +25,7 @@ impl SketchBuilder for PartialSketch { ) { let mut face = PartialFace::default(); face.exterior.write().surface = surface.into(); - face.update_exterior_as_polygon_from_points(points); + face.exterior.write().update_as_polygon_from_points(points); self.faces.extend([Partial::from_partial(face)]); } diff --git a/crates/fj-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index d94bd4325..2aabcda3e 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -122,12 +122,12 @@ mod tests { let valid = { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(surface); - face.update_exterior_as_polygon_from_points([ + face.exterior.write().update_as_polygon_from_points([ [0., 0.], [3., 0.], [0., 3.], ]); - face.add_interior_polygon_from_points([ + face.add_interior().write().update_as_polygon_from_points([ [1., 1.], [1., 2.], [2., 1.], @@ -164,12 +164,12 @@ mod tests { let valid = { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(surface); - face.update_exterior_as_polygon_from_points([ + face.exterior.write().update_as_polygon_from_points([ [0., 0.], [3., 0.], [0., 3.], ]); - face.add_interior_polygon_from_points([ + face.add_interior().write().update_as_polygon_from_points([ [1., 1.], [1., 2.], [2., 1.],