Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API for finding faces #1067

Merged
merged 3 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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