Extract non-essential methods from PartialFace

This commit is contained in:
Hanno Braun 2022-11-09 14:30:32 +01:00
parent 2dd5f6d68d
commit e8e74cf295
14 changed files with 64 additions and 36 deletions

View File

@ -150,7 +150,7 @@ where
#[cfg(test)]
mod tests {
use crate::{
builder::CurveBuilder,
builder::{CurveBuilder, FaceBuilder},
objects::{Curve, Face, Objects},
partial::HasPartial,
};

View File

@ -67,7 +67,7 @@ mod tests {
use crate::{
algorithms::intersect::CurveFaceIntersection,
builder::CurveBuilder,
builder::{CurveBuilder, FaceBuilder},
objects::{Curve, Face, Objects},
partial::HasPartial,
};

View File

@ -136,6 +136,7 @@ mod tests {
use crate::{
algorithms::intersect::{face_point::FacePointIntersection, Intersect},
builder::FaceBuilder,
iter::ObjectIters,
objects::{Face, Objects},
partial::HasPartial,

View File

@ -152,6 +152,7 @@ mod tests {
},
transform::TransformObject,
},
builder::FaceBuilder,
iter::ObjectIters,
objects::{Face, Objects},
partial::HasPartial,

View File

@ -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,
};

View File

@ -84,6 +84,7 @@ mod tests {
use crate::{
algorithms::approx::{Approx, Tolerance},
builder::FaceBuilder,
objects::{Face, Objects},
partial::HasPartial,
storage::Handle,

View File

@ -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<Item = impl Into<Point<2>>>,
) -> Self;
/// Update the [`PartialFace`] with an interior polygon
fn with_interior_polygon_from_points(
self,
points: impl IntoIterator<Item = impl Into<Point<2>>>,
) -> Self;
}
impl FaceBuilder for PartialFace {
fn with_exterior_polygon_from_points(
self,
points: impl IntoIterator<Item = impl Into<Point<2>>>,
) -> 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<Item = impl Into<Point<2>>>,
) -> 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()])
}
}

View File

@ -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,

View File

@ -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,

View File

@ -6,6 +6,8 @@ use crate::{
storage::Handle,
};
use super::FaceBuilder;
/// API for building a [`Sketch`]
///
/// Also see [`Sketch::builder`].

View File

@ -360,7 +360,7 @@ impl<T> Iterator for Iter<T> {
#[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,

View File

@ -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<Item = impl Into<Point<2>>>,
) -> 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<Item = impl Into<Point<2>>>,
) -> 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);

View File

@ -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,

View File

@ -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,