Skip to content

Commit

Permalink
Add FaceBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Mar 17, 2023
1 parent ab50bca commit 1440d41
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
58 changes: 58 additions & 0 deletions crates/fj-kernel/src/builder/face.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use fj_interop::mesh::Color;

use crate::{
insert::Insert,
objects::{Face, Objects, Surface},
services::Service,
storage::Handle,
};

use super::CycleBuilder;

/// Builder API for [`Face`]
pub struct FaceBuilder {
surface: Handle<Surface>,
exterior: CycleBuilder,
interiors: Vec<CycleBuilder>,
color: Option<Color>,
}
impl FaceBuilder {
/// Create an instance of `FaceBuilder`
pub fn new(surface: Handle<Surface>) -> Self {
Self {
surface,
exterior: CycleBuilder::new(),
interiors: Vec::new(),
color: None,
}
}

/// Replace the face's exterior cycle
pub fn with_exterior(mut self, exterior: CycleBuilder) -> Self {
self.exterior = exterior;
self
}

/// Add an interior cycle to the face
pub fn with_interior(mut self, interior: CycleBuilder) -> Self {
self.interiors.push(interior);
self
}

/// Define the color of the face
pub fn with_color(mut self, color: Color) -> Self {
self.color = Some(color);
self
}

/// Build the face
pub fn build(self, objects: &mut Service<Objects>) -> Face {
let exterior = self.exterior.build(objects).insert(objects);
let interiors = self
.interiors
.into_iter()
.map(|cycle| cycle.build(objects).insert(objects));

Face::new(self.surface, exterior, interiors, self.color)
}
}
3 changes: 2 additions & 1 deletion crates/fj-kernel/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
// These are new-style builders that build on top of the partial object API.
mod cycle;
mod edge;
mod face;

pub use self::{cycle::CycleBuilder, edge::HalfEdgeBuilder};
pub use self::{cycle::CycleBuilder, edge::HalfEdgeBuilder, face::FaceBuilder};

0 comments on commit 1440d41

Please sign in to comment.