Skip to content

Commit

Permalink
Merge pull request #1067 from hannobraun/find
Browse files Browse the repository at this point in the history
Add API for finding faces
  • Loading branch information
hannobraun authored Sep 9, 2022
2 parents 5374f13 + 05aa620 commit 43025a9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
11 changes: 11 additions & 0 deletions crates/fj-kernel/src/objects/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ impl Faces {
pub fn new() -> Self {
Self::default()
}

/// Find the given face
pub fn find(&self, face: &Face) -> Option<Face> {
for f in self {
if f == face {
return Some(f.clone());
}
}

None
}
}

impl Extend<Face> for Faces {
Expand Down
5 changes: 5 additions & 0 deletions crates/fj-kernel/src/objects/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ impl Shell {
pub fn into_faces(self) -> Faces {
self.faces
}

/// Find the given face in this shell
pub fn find_face(&self, face: &Face) -> Option<Face> {
self.faces().find(face)
}
}

impl Default for Shell {
Expand Down
13 changes: 12 additions & 1 deletion crates/fj-kernel/src/objects/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::BTreeSet;

use crate::builder::SolidBuilder;

use super::Shell;
use super::{Face, Shell};

/// A 3-dimensional shape
///
Expand Down Expand Up @@ -49,6 +49,17 @@ impl Solid {
pub fn into_shells(self) -> impl Iterator<Item = Shell> {
self.shells.into_iter()
}

/// Find the given face in this solid
pub fn find_face(&self, face: &Face) -> Option<Face> {
for shell in self.shells() {
if let Some(face) = shell.find_face(face) {
return Some(face);
}
}

None
}
}

impl Default for Solid {
Expand Down

0 comments on commit 43025a9

Please sign in to comment.