Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Mar 3, 2022
1 parent ff19058 commit 9237c25
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
47 changes: 45 additions & 2 deletions src/kernel/algorithms/sweep.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use std::collections::HashMap;

use crate::{
kernel::topology::{
edges::Edge,
faces::{Face, Faces},
Shape,
},
Expand All @@ -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 {
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/kernel/topology/vertices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = Vertex<3>> {
// TASK: Implement
std::iter::empty()
}
}

/// A vertex
Expand Down

0 comments on commit 9237c25

Please sign in to comment.