Store faces in Storage

This commit is contained in:
Hanno Braun 2022-03-08 14:13:06 +01:00
parent 4d5a279f71
commit 2aeb724992
5 changed files with 30 additions and 25 deletions

View File

@ -53,7 +53,7 @@ pub fn sweep_shape(
} }
for face in bottom_faces { for face in bottom_faces {
shape.faces().add(face); shape.faces().add((*face).clone());
} }
for face in top_faces { for face in top_faces {
shape.faces().add(face); shape.faces().add(face);

View File

@ -17,19 +17,23 @@ pub struct Faces<'r> {
impl Faces<'_> { impl Faces<'_> {
/// Add a face to the shape /// Add a face to the shape
pub fn add(&mut self, face: Face) -> Handle<Face> { pub fn add(&mut self, face: Face) -> Handle<Face> {
self.faces.push(face.clone()); let storage = Storage::new(face);
Storage::new(face).handle() let handle = storage.handle();
self.faces.push(storage);
handle
} }
/// Check whether the shape contains a specific face /// Check whether the shape contains a specific face
#[cfg(test)] #[cfg(test)]
pub fn contains(&self, face: &Face) -> bool { pub fn contains(&self, face: &Face) -> bool {
self.faces.contains(face) self.faces.contains(&Storage::new(face.clone()))
} }
/// Access an iterator over all faces /// Access an iterator over all faces
pub fn all(&self) -> impl Iterator<Item = Face> + '_ { pub fn all(&self) -> impl Iterator<Item = Handle<Face>> + '_ {
self.faces.iter().cloned() self.faces.iter().map(|storage| storage.handle())
} }
pub fn triangles( pub fn triangles(

View File

@ -92,4 +92,4 @@ impl Shape {
type VerticesInner = Vec<Storage<Vertex>>; type VerticesInner = Vec<Storage<Vertex>>;
type CyclesInner = Vec<Storage<Cycle>>; type CyclesInner = Vec<Storage<Cycle>>;
type FacesInner = Vec<Face>; type FacesInner = Vec<Storage<Face>>;

View File

@ -56,22 +56,23 @@ impl ToShape for fj::Difference2d {
); );
}; };
let (a, b, surface_a, surface_b) = match (a, b) { let (a, b, surface_a, surface_b) =
( match ((*a).clone(), (*b).clone()) {
Face::Face { (
cycles: a, Face::Face {
surface: surface_a, cycles: a,
}, surface: surface_a,
Face::Face { },
cycles: b, Face::Face {
surface: surface_b, cycles: b,
}, surface: surface_b,
) => (a, b, surface_a, surface_b), },
_ => { ) => (a, b, surface_a, surface_b),
// None of the 2D types still use the triangles representation. _ => {
unreachable!() // None of the 2D types still use the triangles representation.
} unreachable!()
}; }
};
assert!( assert!(
surface_a == surface_b, surface_a == surface_b,

View File

@ -19,10 +19,10 @@ impl ToShape for fj::Union {
// See issue: // See issue:
// https://github.com/hannobraun/Fornjot/issues/42 // https://github.com/hannobraun/Fornjot/issues/42
for face in a.faces().all() { for face in a.faces().all() {
shape.faces().add(face); shape.faces().add((*face).clone());
} }
for face in b.faces().all() { for face in b.faces().all() {
shape.faces().add(face); shape.faces().add((*face).clone());
} }
shape shape