diff --git a/experiments/2024-12-09/src/model.rs b/experiments/2024-12-09/src/model.rs index b73f67ebb..b6dde918d 100644 --- a/experiments/2024-12-09/src/model.rs +++ b/experiments/2024-12-09/src/model.rs @@ -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::>(); - - 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) } diff --git a/experiments/2024-12-09/src/topology/solid.rs b/experiments/2024-12-09/src/topology/solid.rs index 6a6634db0..3ea3951b8 100644 --- a/experiments/2024-12-09/src/topology/solid.rs +++ b/experiments/2024-12-09/src/topology/solid.rs @@ -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; 2], + surfaces: &mut Store, + faces: &mut Store, + ) -> 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::>(); + + Solid::new([a, b].into_iter().chain(side_faces)) + } } impl Operation for Solid {