Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abolish Shape #747

Merged
merged 8 commits into from Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/fj-kernel/src/algorithms/reverse.rs
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
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
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
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
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
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
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