From 9237c25a931602bf3efe4c1710fbc7c2e4790b28 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Mar 2022 16:36:04 +0100 Subject: [PATCH] WIP --- src/kernel/algorithms/sweep.rs | 47 +++++++++++++++++++++++++++++++-- src/kernel/topology/vertices.rs | 8 ++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/kernel/algorithms/sweep.rs b/src/kernel/algorithms/sweep.rs index 7d64da4d9..ed3008478 100644 --- a/src/kernel/algorithms/sweep.rs +++ b/src/kernel/algorithms/sweep.rs @@ -1,5 +1,8 @@ +use std::collections::HashMap; + use crate::{ kernel::topology::{ + edges::Edge, faces::{Face, Faces}, Shape, }, @@ -10,7 +13,7 @@ use super::{approximation::Approximation, transform::transform_face}; /// Create a new shape by sweeping an existing one pub fn sweep_shape( - shape_orig: Shape, + mut shape_orig: Shape, path: Vector<3>, tolerance: Scalar, ) -> Shape { @@ -25,7 +28,47 @@ pub fn sweep_shape( let mut top_faces = Vec::new(); let mut side_faces = Vec::new(); - for face in &shape_orig.faces.0 { + // Create new vertices. + let mut vertices = HashMap::new(); + for vertex_orig in shape_orig.vertices().all() { + let point = vertex_orig.point().canonical() + path; + + let vertex = shape.vertices().create(point); + + vertices.insert(vertex_orig, vertex); + } + + // Create top edges. + let mut edges = HashMap::new(); + for cycle_orig in shape_orig.edges.cycles { + let mut cycle_edges = Vec::new(); + + for edge_orig in cycle_orig.edges { + let curve = edge_orig.curve.transform(&translation); + let vertices = edge_orig.vertices.map(|vs| { + vs.map(|v| { + *vertices.get(&v.to_canonical()).expect( + "Edge is referring to vertex that doesn't exist in shape", + ) + }) + }); + + let edge = Edge::new(curve, vertices); + cycle_edges. + // TASK: We need to insert `edge` into `shape` here, but that doesn't + // quite work. We're losing the cycles here, but we need to + // faithfully reproduce those too. + + edges.insert(edge_orig, edge); + } + } + + // Create top faces. + + // We could use `vertices` to create the side edges and faces here, but the + // side walls is created below, in triangle representation. + + for face in &original.faces.0 { bottom_faces.push(face.clone()); // TASK: This can only work, if all the original faces don't share any diff --git a/src/kernel/topology/vertices.rs b/src/kernel/topology/vertices.rs index e0c1bfc11..23392d894 100644 --- a/src/kernel/topology/vertices.rs +++ b/src/kernel/topology/vertices.rs @@ -63,6 +63,14 @@ impl Vertices<'_> { Vertex(point) } + + /// Access iterator over all vertices + /// + /// The caller must not make any assumptions about the order of vertices. + pub fn all(&self) -> impl Iterator> { + // TASK: Implement + std::iter::empty() + } } /// A vertex