Skip to content

Commit

Permalink
Make construction of side faces more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Jan 23, 2025
1 parent 36e472c commit b7610f2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
28 changes: 13 additions & 15 deletions experiments/2024-12-09/src/model.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use itertools::Itertools;

use crate::{
geometry::{AnyOp, Sketch},
math::{Bivector, Plane, Point, Vector},
Expand Down Expand Up @@ -30,21 +28,21 @@ pub fn model() -> AnyOp {
&mut stores.vertices,
);

let [a, b, c, d] = bottom.vertices().collect_array().unwrap();
let [e, f, g, h] = top.vertices().collect_array().unwrap();

let [left, right, front, back] =
[[a, e, h, d], [b, c, g, f], [a, b, f, e], [c, d, h, g]].map(
|[q, r, s, t]| {
let surface = stores.surfaces.insert(Plane::from_points(
[q, r, s].map(|vertex| vertex.point),
));
Face::new(surface, [q, r, s, t].map(|vertex| vertex.clone()))
},
);
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),
));
Face::new(surface, [q, r, s, t].map(|vertex| vertex.clone()))
})
.collect::<Vec<_>>();

let solid = Solid::new(
[bottom, top, left, right, front, back]
[bottom, top]
.into_iter()
.chain(side_faces)
.map(|face| stores.faces.insert(face)),
);

Expand Down
9 changes: 9 additions & 0 deletions experiments/2024-12-09/src/topology/face.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use itertools::Itertools;
use spade::Triangulation;

use crate::{
Expand Down Expand Up @@ -25,10 +26,18 @@ impl Face {
}
}

#[allow(unused)] // fell out of use, but will likely be required again
pub fn vertices(&self) -> impl Iterator<Item = &Handle<Vertex>> {
self.vertices.iter()
}

pub fn half_edges(&self) -> impl Iterator<Item = [&Handle<Vertex>; 2]> {
self.vertices
.iter()
.circular_tuple_windows()
.map(|(a, b)| [a, b])
}

pub fn flip(&self, surfaces: &mut Store<Plane>) -> Self {
Self {
surface: surfaces.insert(self.surface.flip()),
Expand Down

0 comments on commit b7610f2

Please sign in to comment.