Add Solid::connect_faces

This commit is contained in:
Hanno Braun 2025-01-28 20:10:36 +01:00
parent e9f4b1f67c
commit 8c615c7904
2 changed files with 34 additions and 16 deletions

View File

@ -2,7 +2,7 @@ use crate::{
geometry::{AnyOp, Sketch},
math::{Bivector, Plane, Point, Vector},
storage::Stores,
topology::{Face, Solid},
topology::Solid,
};
pub fn model() -> AnyOp {
@ -30,20 +30,11 @@ pub fn model() -> AnyOp {
let [bottom, top] = [bottom, top].map(|face| stores.faces.insert(face));
let side_faces = bottom
.half_edges()
.zip(top.half_edges())
.map(|([q, r], [t, s])| {
let surface = stores.surfaces.insert(Plane::from_points(
[q, r, s].map(|vertex| vertex.point),
));
let face =
Face::new(surface, [q, r, s, t].map(|vertex| vertex.clone()));
stores.faces.insert(face)
})
.collect::<Vec<_>>();
let solid = Solid::new([bottom, top].into_iter().chain(side_faces));
let solid = Solid::connect_faces(
[bottom, top],
&mut stores.surfaces,
&mut stores.faces,
);
AnyOp::new(solid)
}

View File

@ -1,4 +1,8 @@
use crate::geometry::{AnyOp, Handle, Operation, TriMesh};
use crate::{
geometry::{AnyOp, Handle, Operation, TriMesh},
math::Plane,
storage::Store,
};
use super::Face;
@ -12,6 +16,29 @@ impl Solid {
faces: faces.into_iter().collect(),
}
}
pub fn connect_faces(
[a, b]: [Handle<Face>; 2],
surfaces: &mut Store<Plane>,
faces: &mut Store<Face>,
) -> Self {
let side_faces = a
.half_edges()
.zip(b.half_edges())
.map(|([q, r], [t, s])| {
let surface = surfaces.insert(Plane::from_points(
[q, r, s].map(|vertex| vertex.point),
));
let face = Face::new(
surface,
[q, r, s, t].map(|vertex| vertex.clone()),
);
faces.insert(face)
})
.collect::<Vec<_>>();
Solid::new([a, b].into_iter().chain(side_faces))
}
}
impl Operation for Solid {