Skip to content

Commit

Permalink
Merge pull request #747 from hannobraun/shape
Browse files Browse the repository at this point in the history
Abolish `Shape`
  • Loading branch information
hannobraun authored Jun 29, 2022
2 parents d9983a9 + eb72149 commit 9078668
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 635 deletions.
8 changes: 4 additions & 4 deletions crates/fj-kernel/src/algorithms/reverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ fn reverse_local_coordinates_in_cycle(cycles: &CyclesInFace) -> CyclesInFace {
// a work in progress, this doesn't lead to any observable
// bugs.
*edge.local().curve.local(),
edge.local().curve.canonical(),
*edge.local().curve.canonical(),
);
let vertices = edge.local().vertices.clone().map(|vertex| {
LocalForm::new(*vertex.local(), vertex.canonical())
LocalForm::new(*vertex.local(), *vertex.canonical())
});
let local = Edge { curve, vertices };
LocalForm::new(local, edge.canonical())
LocalForm::new(local, edge.canonical().clone())
})
.collect();
let local = Cycle { edges };
LocalForm::new(local, cycle.canonical())
LocalForm::new(local, cycle.canonical().clone())
});

CyclesInFace::new(cycles)
Expand Down
7 changes: 4 additions & 3 deletions crates/fj-kernel/src/algorithms/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fn create_non_continuous_side_face(
};

let global = Edge {
curve: LocalForm::canonical_only(curve.canonical()),
curve: LocalForm::canonical_only(*curve.canonical()),
vertices,
};

Expand All @@ -162,8 +162,9 @@ fn create_non_continuous_side_face(
let cycle = {
let local = Cycle { edges };

let global =
Cycle::new(local.edges.iter().map(|edge| edge.canonical()));
let global = Cycle::new(
local.edges.iter().map(|edge| edge.canonical().clone()),
);

LocalForm::new(local, global)
};
Expand Down
17 changes: 9 additions & 8 deletions crates/fj-kernel/src/algorithms/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ pub fn transform_cycles(
let curve_canonical =
edge.canonical().curve().transform(transform);

let vertices = edge.canonical().vertices.map(|vertex| {
let point = vertex.canonical().point;
let point = transform.transform_point(&point);
let vertices =
edge.canonical().clone().vertices.map(|vertex| {
let point = vertex.canonical().point;
let point = transform.transform_point(&point);

let local = *vertex.local();
let canonical = Vertex { point };
let local = *vertex.local();
let canonical = Vertex { point };

LocalForm::new(local, canonical)
});
LocalForm::new(local, canonical)
});

let edge_local = Edge {
curve: LocalForm::new(curve_local, curve_canonical),
Expand All @@ -89,7 +90,7 @@ pub fn transform_cycles(
let curve = edge.curve().transform(transform);
LocalForm::canonical_only(curve)
};
let vertices = edge.vertices.map(|vertex| {
let vertices = edge.vertices.clone().map(|vertex| {
let point = vertex.canonical().point;
let point = transform.transform_point(&point);

Expand Down
49 changes: 8 additions & 41 deletions crates/fj-kernel/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
use std::collections::VecDeque;

use crate::{
objects::{Curve, Cycle, Edge, Face, Surface, Vertex},
shape::Shape,
};
use crate::objects::{Curve, Cycle, Edge, Face, Surface, Vertex};

/// Access iterators over all objects of a shape, or part of it
///
Expand Down Expand Up @@ -297,40 +294,15 @@ impl ObjectIters for Vertex {
}
}

// This implementation exists to ease the transition away from `Shape`. It will
// likely be removed at some point, together with `Shape`.
impl ObjectIters for Shape {
fn curve_iter(&self) -> Iter<Curve<3>> {
Iter::from_iter(self.curves().map(|handle| handle.get()))
}

fn cycle_iter(&self) -> Iter<Cycle<3>> {
Iter::from_iter(self.cycles().map(|handle| handle.get()))
}

fn edge_iter(&self) -> Iter<Edge<3>> {
Iter::from_iter(self.edges().map(|handle| handle.get()))
}

fn face_iter(&self) -> Iter<Face> {
Iter::from_iter(self.faces().map(|handle| handle.get()))
}

fn surface_iter(&self) -> Iter<Surface> {
Iter::from_iter(self.surfaces().map(|handle| handle.get()))
}

fn vertex_iter(&self) -> Iter<Vertex> {
Iter::from_iter(self.vertices().map(|handle| handle.get()))
}
}

// This implementation exists to paper over the lack of any "top-level" objects
// that are an entry point into a shape (basically, the lack of `Sketch` and
// `Solid`).
impl<T> ObjectIters for T
//
// It is also very useful in test code.
impl<T, O> ObjectIters for T
where
for<'r> &'r T: IntoIterator<Item = &'r Face>,
for<'r> &'r T: IntoIterator<Item = &'r O>,
O: ObjectIters,
{
fn curve_iter(&self) -> Iter<Curve<3>> {
let mut iter = Iter::empty();
Expand Down Expand Up @@ -409,12 +381,6 @@ impl<T> Iter<T> {
Self(objects)
}

fn from_iter(iter: impl IntoIterator<Item = T>) -> Self {
let mut objects = VecDeque::new();
objects.extend(iter);
Self(objects)
}

fn with(mut self, other: Self) -> Self
where
T: PartialEq,
Expand Down Expand Up @@ -461,7 +427,8 @@ mod tests {
&Surface::xy_plane(),
[[0., 0.], [1., 0.], [0., 1.]],
)
.canonical();
.canonical()
.clone();

assert_eq!(3, cycle.curve_iter().count());
assert_eq!(1, cycle.cycle_iter().count());
Expand Down
7 changes: 4 additions & 3 deletions crates/fj-kernel/src/objects/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Cycle<3> {
let edge_local = Edge {
curve: LocalForm::new(
Curve::Line(Line::from_points(points)),
edge_canonical.curve.canonical(),
*edge_canonical.curve.canonical(),
),
vertices: edge_canonical.vertices.clone(),
};
Expand All @@ -68,7 +68,8 @@ impl Cycle<3> {
edges: edges.clone(),
};

let edges_canonical = edges.into_iter().map(|edge| edge.canonical());
let edges_canonical =
edges.into_iter().map(|edge| edge.canonical().clone());
let canonical = Cycle::new(edges_canonical);

LocalForm::new(local, canonical)
Expand All @@ -79,6 +80,6 @@ impl Cycle<3> {
/// This is a convenience method that saves the caller from dealing with the
/// [`Handle`]s.
pub fn edges(&self) -> impl Iterator<Item = Edge<3>> + '_ {
self.edges.iter().map(|handle| handle.canonical())
self.edges.iter().map(|handle| handle.canonical().clone())
}
}
8 changes: 4 additions & 4 deletions crates/fj-kernel/src/objects/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl<const D: usize> Edge<D> {
/// This is a convenience method that saves the caller from dealing with the
/// [`Handle`].
pub fn curve(&self) -> Curve<3> {
self.curve.canonical()
*self.curve.canonical()
}

/// Access the vertices that the edge refers to
Expand All @@ -46,7 +46,7 @@ impl<const D: usize> Edge<D> {
self.vertices
.0
.as_ref()
.map(|[a, b]| [a.canonical(), b.canonical()])
.map(|[a, b]| [*a.canonical(), *b.canonical()])
}
}

Expand Down Expand Up @@ -185,8 +185,8 @@ impl VerticesOfEdge {
pub fn reverse(self) -> Self {
Self(self.0.map(|[a, b]| {
[
LocalForm::new(-(*b.local()), b.canonical()),
LocalForm::new(-(*a.local()), a.canonical()),
LocalForm::new(-(*b.local()), *b.canonical()),
LocalForm::new(-(*a.local()), *a.canonical()),
]
}))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/objects/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl CyclesInFace {

/// Access an iterator over the canonical forms of the cycles
pub fn as_canonical(&self) -> impl Iterator<Item = Cycle<3>> + '_ {
self.0.iter().map(|cycle| cycle.canonical())
self.0.iter().map(|cycle| cycle.canonical().clone())
}

/// Access an iterator over local forms of the cycles
Expand Down
Loading

0 comments on commit 9078668

Please sign in to comment.