Skip to content

Commit

Permalink
Extract non-essential methods from PartialFace
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Nov 9, 2022
1 parent 2dd5f6d commit e8e74cf
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 36 deletions.
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ where
#[cfg(test)]
mod tests {
use crate::{
builder::CurveBuilder,
builder::{CurveBuilder, FaceBuilder},
objects::{Curve, Face, Objects},
partial::HasPartial,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/intersect/face_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ mod tests {

use crate::{
algorithms::intersect::CurveFaceIntersection,
builder::CurveBuilder,
builder::{CurveBuilder, FaceBuilder},
objects::{Curve, Face, Objects},
partial::HasPartial,
};
Expand Down
1 change: 1 addition & 0 deletions crates/fj-kernel/src/algorithms/intersect/face_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ mod tests {

use crate::{
algorithms::intersect::{face_point::FacePointIntersection, Intersect},
builder::FaceBuilder,
iter::ObjectIters,
objects::{Face, Objects},
partial::HasPartial,
Expand Down
1 change: 1 addition & 0 deletions crates/fj-kernel/src/algorithms/intersect/ray_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ mod tests {
},
transform::TransformObject,
},
builder::FaceBuilder,
iter::ObjectIters,
objects::{Face, Objects},
partial::HasPartial,
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/sweep/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
1 change: 1 addition & 0 deletions crates/fj-kernel/src/algorithms/triangulate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ mod tests {

use crate::{
algorithms::approx::{Approx, Tolerance},
builder::FaceBuilder,
objects::{Face, Objects},
partial::HasPartial,
storage::Handle,
Expand Down
49 changes: 49 additions & 0 deletions crates/fj-kernel/src/builder/face.rs
Original file line number Diff line number Diff line change
@@ -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()])
}
}
2 changes: 2 additions & 0 deletions crates/fj-kernel/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/builder/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions crates/fj-kernel/src/builder/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use crate::{
storage::Handle,
};

use super::FaceBuilder;

/// API for building a [`Sketch`]
///
/// Also see [`Sketch::builder`].
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 1 addition & 29 deletions crates/fj-kernel/src/partial/objects/face.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/validate/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-operations/src/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e8e74cf

Please sign in to comment.