-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #983 from hannobraun/shell
Extract `Shell` from `Solid`
- Loading branch information
Showing
10 changed files
with
191 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use fj_math::Scalar; | ||
|
||
use crate::{ | ||
algorithms::TransformObject, | ||
objects::{Face, Shell, Surface}, | ||
}; | ||
|
||
/// API for building a [`Shell`] | ||
pub struct ShellBuilder; | ||
|
||
impl ShellBuilder { | ||
/// Create a cube from the length of its edges | ||
pub fn cube_from_edge_length( | ||
&self, | ||
edge_length: impl Into<Scalar>, | ||
) -> Shell { | ||
// Let's define a short-hand for half the edge length. We're going to | ||
// need it a lot. | ||
let h = edge_length.into() / 2.; | ||
|
||
let points = [[-h, -h], [h, -h], [h, h], [-h, h]]; | ||
|
||
const Z: Scalar = Scalar::ZERO; | ||
let planes = [ | ||
Surface::xy_plane().translate([Z, Z, -h]), // bottom | ||
Surface::xy_plane().translate([Z, Z, h]), // top | ||
Surface::xz_plane().translate([Z, -h, Z]), // front | ||
Surface::xz_plane().translate([Z, h, Z]), // back | ||
Surface::yz_plane().translate([-h, Z, Z]), // left | ||
Surface::yz_plane().translate([h, Z, Z]), // right | ||
]; | ||
|
||
let faces = | ||
planes.map(|plane| Face::build(plane).polygon_from_points(points)); | ||
|
||
Shell::new().with_faces(faces) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use std::collections::BTreeSet; | ||
|
||
use crate::builder::ShellBuilder; | ||
|
||
use super::Face; | ||
|
||
/// A 3-dimensional closed shell | ||
/// | ||
/// # Implementation Note | ||
/// | ||
/// The faces that make up a shell should be closed ("watertight"). This is not | ||
/// currently validated. | ||
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] | ||
pub struct Shell { | ||
faces: BTreeSet<Face>, | ||
} | ||
|
||
impl Shell { | ||
/// Build a shell using [`ShellBuilder`] | ||
pub fn build() -> ShellBuilder { | ||
ShellBuilder | ||
} | ||
|
||
/// Construct an empty instance of `Shell` | ||
pub fn new() -> Self { | ||
Self { | ||
faces: BTreeSet::new(), | ||
} | ||
} | ||
|
||
/// Add faces to the shell | ||
/// | ||
/// Consumes the shell and returns the updated instance. | ||
pub fn with_faces( | ||
mut self, | ||
faces: impl IntoIterator<Item = impl Into<Face>>, | ||
) -> Self { | ||
let faces = faces.into_iter().map(Into::into); | ||
self.faces.extend(faces); | ||
self | ||
} | ||
|
||
/// Access the shell's faces | ||
pub fn faces(&self) -> impl Iterator<Item = &Face> { | ||
self.faces.iter() | ||
} | ||
|
||
/// Convert the shell into a list of faces | ||
pub fn into_faces(self) -> impl Iterator<Item = Face> { | ||
self.faces.into_iter() | ||
} | ||
} | ||
|
||
impl Default for Shell { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} |
Oops, something went wrong.