From c511cff86de9ff548c37c147abb0de1a60da0998 Mon Sep 17 00:00:00 2001 From: hodapp Date: Tue, 14 Jan 2020 18:41:59 -0500 Subject: [PATCH] Test MeshBound struct to walk mesh boundary --- src/main.rs | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/main.rs b/src/main.rs index 1ad9ff1..9ffc6a6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -215,6 +215,61 @@ fn cube_thing_rule(_v: Vec) -> Vec { turns.iter().map(gen_rulestep).collect() } +struct MeshBound<'a> { + m: &'a Mesh, + start: HalfEdgeID, + cur: HalfEdgeID, +} + +impl<'a> MeshBound<'a> { + fn new(m: &'a Mesh) -> Option { + for halfedge_id in m.edge_iter() { + if m.is_edge_on_boundary(halfedge_id) { + return Some(MeshBound { + m: m, + start: halfedge_id, + cur: halfedge_id, + }); + } + } + return None; + } +} + +impl<'a> Iterator for MeshBound<'a> { + type Item = HalfEdgeID; + + fn next(&mut self) -> Option { + + // Start from self.cur. + // Pick a vertex. (Doesn't matter which, as long as consistent.) + // Step to all *other* half-edges. + // Find the one that is a boundary. + // + // Update 'cur' to this half-edge. + + let (v1, v2) = self.m.edge_vertices(self.cur); + // TODO: v1 or v2? + for halfedge_id in self.m.vertex_halfedge_iter(v1) { + if self.m.is_edge_on_boundary(halfedge_id) { + if self.start == halfedge_id { + // If we are walking the boundary and reach the + // starting edge again, we're done: + break; + } + // Otherwise, yield the next edge: + self.cur = halfedge_id; + return Some(halfedge_id); + } + } + return None; + } + +} + +//fn mesh_boundary(m: &Mesh) -> Vec { +//} + // TODO: Do I want to make 'geom' shared somehow, maybe with Rc? I // could end up having a lot of identical geometry that need not be // duplicated until it is transformed into the global space. @@ -309,6 +364,11 @@ fn main() { s.apply_transformation(Matrix4::from_translation(vec3(-0.5, -0.5, 0.0))); s }; + // TODO: Something is wrong here + let mb = MeshBound::new(&seed); + for bound_edge in mb { + println!("Boundary edge: {}", bound_edge); + } let (mesh, nodes) = rule_to_mesh(&r2, vec![seed], 75); println!("Collected {} nodes, produced {} faces, {} vertices", nodes, mesh.no_faces(), mesh.no_vertices());