Skip to content

Commit

Permalink
Merge pull request #1051 from hannobraun/faces
Browse files Browse the repository at this point in the history
Add `Faces`
  • Loading branch information
hannobraun authored Sep 7, 2022
2 parents 8d3dfb1 + 508003f commit ede3d6d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 21 deletions.
10 changes: 8 additions & 2 deletions crates/fj-kernel/src/algorithms/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,20 @@ impl TransformObject for GlobalVertex {

impl TransformObject for Shell {
fn transform(self, transform: &Transform) -> Self {
let faces = self.into_faces().map(|face| face.transform(transform));
let faces = self
.into_faces()
.into_iter()
.map(|face| face.transform(transform));
Self::new().with_faces(faces)
}
}

impl TransformObject for Sketch {
fn transform(self, transform: &Transform) -> Self {
let faces = self.into_faces().map(|face| face.transform(transform));
let faces = self
.into_faces()
.into_iter()
.map(|face| face.transform(transform));
Self::new().with_faces(faces)
}
}
Expand Down
39 changes: 39 additions & 0 deletions crates/fj-kernel/src/objects/face.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,49 @@
use std::collections::{btree_set, BTreeSet};

use fj_interop::mesh::Color;
use fj_math::Triangle;

use crate::builder::FaceBuilder;

use super::{Cycle, Surface};

/// A collection of faces
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct Faces {
inner: BTreeSet<Face>,
}

impl Faces {
/// Create an empty instance of `Faces`
pub fn new() -> Self {
Self::default()
}
}

impl Extend<Face> for Faces {
fn extend<T: IntoIterator<Item = Face>>(&mut self, iter: T) {
self.inner.extend(iter)
}
}

impl IntoIterator for Faces {
type Item = Face;
type IntoIter = btree_set::IntoIter<Face>;

fn into_iter(self) -> Self::IntoIter {
self.inner.into_iter()
}
}

impl<'a> IntoIterator for &'a Faces {
type Item = &'a Face;
type IntoIter = btree_set::Iter<'a, Face>;

fn into_iter(self) -> Self::IntoIter {
self.inner.iter()
}
}

/// A face of a shape
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct Face {
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/objects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub use self::{
curve::{Curve, CurveKind, GlobalCurve},
cycle::Cycle,
edge::{Edge, GlobalEdge, VerticesOfEdge},
face::Face,
face::{Face, Faces},
shell::Shell,
sketch::Sketch,
solid::Solid,
Expand Down
16 changes: 7 additions & 9 deletions crates/fj-kernel/src/objects/shell.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::collections::BTreeSet;

use crate::builder::ShellBuilder;

use super::Face;
use super::{face::Faces, Face};

/// A 3-dimensional closed shell
///
Expand All @@ -12,7 +10,7 @@ use super::Face;
/// currently validated.
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct Shell {
faces: BTreeSet<Face>,
faces: Faces,
}

impl Shell {
Expand All @@ -24,7 +22,7 @@ impl Shell {
/// Construct an empty instance of `Shell`
pub fn new() -> Self {
Self {
faces: BTreeSet::new(),
faces: Faces::new(),
}
}

Expand All @@ -41,13 +39,13 @@ impl Shell {
}

/// Access the shell's faces
pub fn faces(&self) -> impl Iterator<Item = &Face> {
self.faces.iter()
pub fn faces(&self) -> &Faces {
&self.faces
}

/// Convert the shell into a list of faces
pub fn into_faces(self) -> impl Iterator<Item = Face> {
self.faces.into_iter()
pub fn into_faces(self) -> Faces {
self.faces
}
}

Expand Down
16 changes: 7 additions & 9 deletions crates/fj-kernel/src/objects/sketch.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::collections::BTreeSet;

use crate::builder::SketchBuilder;

use super::{Face, Surface};
use super::{face::Faces, Face, Surface};

/// A 2-dimensional shape
///
Expand All @@ -12,7 +10,7 @@ use super::{Face, Surface};
/// currently validated.
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct Sketch {
faces: BTreeSet<Face>,
faces: Faces,
}

impl Sketch {
Expand All @@ -24,7 +22,7 @@ impl Sketch {
/// Construct an empty instance of `Sketch`
pub fn new() -> Self {
Self {
faces: BTreeSet::new(),
faces: Faces::new(),
}
}

Expand All @@ -41,13 +39,13 @@ impl Sketch {
}

/// Access the sketch's faces
pub fn faces(&self) -> impl Iterator<Item = &Face> {
self.faces.iter()
pub fn faces(&self) -> &Faces {
&self.faces
}

/// Convert the sketch into a list of faces
pub fn into_faces(self) -> impl Iterator<Item = Face> {
self.faces.into_iter()
pub fn into_faces(self) -> Faces {
self.faces
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/fj-operations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl Shape for fj::Shape {
.compute_brep(config, tolerance, debug_info)?
.into_inner()
.into_faces()
.into_iter()
.collect::<Vec<_>>()
.validate_with_config(config),
Self::Group(shape) => {
Expand Down

0 comments on commit ede3d6d

Please sign in to comment.