mirror of https://github.com/hannobraun/Fornjot
Give `LocalForm` ownership of the canonical form
We're entering the last stretch of the work towards removing `Shape`. Now, nothing should really depend on `Shape` any more, so it's a matter of replacing `Handle`s where we can find them with direct ownership of the previously referred to object.
This commit is contained in:
parent
a17e400b2b
commit
68da99913a
|
@ -13,7 +13,7 @@ pub fn approx_edge(
|
||||||
// the same vertex would be understood to refer to very close, but distinct
|
// the same vertex would be understood to refer to very close, but distinct
|
||||||
// vertices.
|
// vertices.
|
||||||
let vertices = vertices.convert(|vertex| {
|
let vertices = vertices.convert(|vertex| {
|
||||||
geometry::Point::new(*vertex.local(), vertex.canonical().get().point)
|
geometry::Point::new(*vertex.local(), vertex.canonical().point)
|
||||||
});
|
});
|
||||||
if let Some([a, b]) = vertices {
|
if let Some([a, b]) = vertices {
|
||||||
points.insert(0, a);
|
points.insert(0, a);
|
||||||
|
@ -49,8 +49,8 @@ mod test {
|
||||||
let c = Point::from([3., 5., 8.]);
|
let c = Point::from([3., 5., 8.]);
|
||||||
let d = Point::from([5., 8., 13.]);
|
let d = Point::from([5., 8., 13.]);
|
||||||
|
|
||||||
let v1 = Vertex::builder(&mut shape).build_from_point(a);
|
let v1 = Vertex::builder(&mut shape).build_from_point(a).get();
|
||||||
let v2 = Vertex::builder(&mut shape).build_from_point(d);
|
let v2 = Vertex::builder(&mut shape).build_from_point(d).get();
|
||||||
|
|
||||||
let vertices = VerticesOfEdge::from_vertices([
|
let vertices = VerticesOfEdge::from_vertices([
|
||||||
LocalForm::new(Point::from([0.]), v1),
|
LocalForm::new(Point::from([0.]), v1),
|
||||||
|
|
|
@ -166,17 +166,15 @@ fn create_non_continuous_side_face(
|
||||||
|
|
||||||
let [[a, b], [c, d]] = [vertices_bottom, vertices_top];
|
let [[a, b], [c, d]] = [vertices_bottom, vertices_top];
|
||||||
|
|
||||||
let vertices = if is_sweep_along_negative_direction {
|
if is_sweep_along_negative_direction {
|
||||||
[b, a, c, d]
|
[b, a, c, d]
|
||||||
} else {
|
} else {
|
||||||
[a, b, d, c]
|
[a, b, d, c]
|
||||||
};
|
}
|
||||||
|
|
||||||
vertices.map(|vertex| tmp.get_handle_or_insert(vertex))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let surface = {
|
let surface = {
|
||||||
let [a, b, _, c] = vertices.clone().map(|vertex| vertex.get().point);
|
let [a, b, _, c] = vertices.map(|vertex| vertex.point);
|
||||||
Surface::plane_from_points([a, b, c])
|
Surface::plane_from_points([a, b, c])
|
||||||
};
|
};
|
||||||
let surface = tmp.get_handle_or_insert(surface);
|
let surface = tmp.get_handle_or_insert(surface);
|
||||||
|
@ -201,16 +199,15 @@ fn create_non_continuous_side_face(
|
||||||
let curve = {
|
let curve = {
|
||||||
let local = Curve::line_from_points([a.0, b.0]);
|
let local = Curve::line_from_points([a.0, b.0]);
|
||||||
|
|
||||||
let global = [a, b].map(|vertex| vertex.1.get().point);
|
let global = [a, b].map(|vertex| vertex.1.point);
|
||||||
let global = Curve::line_from_points(global);
|
let global = Curve::line_from_points(global);
|
||||||
let global = tmp.get_handle_or_insert(global);
|
|
||||||
|
|
||||||
LocalForm::new(local, global)
|
LocalForm::new(local, global)
|
||||||
};
|
};
|
||||||
|
|
||||||
let vertices = VerticesOfEdge::from_vertices([
|
let vertices = VerticesOfEdge::from_vertices([
|
||||||
LocalForm::new(Point::from([0.]), a.1.clone()),
|
LocalForm::new(Point::from([0.]), a.1),
|
||||||
LocalForm::new(Point::from([1.]), b.1.clone()),
|
LocalForm::new(Point::from([1.]), b.1),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let edge = {
|
let edge = {
|
||||||
|
@ -223,7 +220,6 @@ fn create_non_continuous_side_face(
|
||||||
curve: LocalForm::canonical_only(curve.canonical()),
|
curve: LocalForm::canonical_only(curve.canonical()),
|
||||||
vertices,
|
vertices,
|
||||||
};
|
};
|
||||||
let global = tmp.get_handle_or_insert(global);
|
|
||||||
|
|
||||||
LocalForm::new(local, global)
|
LocalForm::new(local, global)
|
||||||
};
|
};
|
||||||
|
@ -236,7 +232,6 @@ fn create_non_continuous_side_face(
|
||||||
|
|
||||||
let global =
|
let global =
|
||||||
Cycle::new(local.edges.iter().map(|edge| edge.canonical()));
|
Cycle::new(local.edges.iter().map(|edge| edge.canonical()));
|
||||||
let global = tmp.get_handle_or_insert(global);
|
|
||||||
|
|
||||||
LocalForm::new(local, global)
|
LocalForm::new(local, global)
|
||||||
};
|
};
|
||||||
|
@ -257,8 +252,6 @@ fn create_continuous_side_face(
|
||||||
) {
|
) {
|
||||||
let translation = Transform::translation(path);
|
let translation = Transform::translation(path);
|
||||||
|
|
||||||
let mut tmp = Shape::new();
|
|
||||||
let edge = tmp.merge(edge);
|
|
||||||
let cycle = Cycle::new(vec![edge]);
|
let cycle = Cycle::new(vec![edge]);
|
||||||
let approx = CycleApprox::new(&cycle, tolerance);
|
let approx = CycleApprox::new(&cycle, tolerance);
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,6 @@ pub fn transform_cycles(
|
||||||
cycles: &CyclesInFace,
|
cycles: &CyclesInFace,
|
||||||
transform: &Transform,
|
transform: &Transform,
|
||||||
) -> CyclesInFace {
|
) -> CyclesInFace {
|
||||||
let mut tmp = Shape::new();
|
|
||||||
|
|
||||||
let cycles = cycles.as_local_form().map(|cycle| {
|
let cycles = cycles.as_local_form().map(|cycle| {
|
||||||
let edges_local = cycle
|
let edges_local = cycle
|
||||||
.local()
|
.local()
|
||||||
|
@ -58,65 +56,62 @@ pub fn transform_cycles(
|
||||||
.iter()
|
.iter()
|
||||||
.map(|edge| {
|
.map(|edge| {
|
||||||
let curve_local = *edge.local().curve.local();
|
let curve_local = *edge.local().curve.local();
|
||||||
let curve_canonical = tmp
|
let curve_canonical =
|
||||||
.merge(edge.canonical().get().curve().transform(transform));
|
edge.canonical().curve().transform(transform);
|
||||||
|
|
||||||
let vertices = edge.canonical().get().vertices.map(|vertex| {
|
let vertices = edge.canonical().vertices.map(|vertex| {
|
||||||
let point = vertex.canonical().get().point;
|
let point = vertex.canonical().point;
|
||||||
let point = transform.transform_point(&point);
|
let point = transform.transform_point(&point);
|
||||||
|
|
||||||
let local = *vertex.local();
|
let local = *vertex.local();
|
||||||
let canonical = tmp.merge(Vertex { point });
|
let canonical = Vertex { point };
|
||||||
|
|
||||||
LocalForm::new(local, canonical)
|
LocalForm::new(local, canonical)
|
||||||
});
|
});
|
||||||
|
|
||||||
let edge_local = Edge {
|
let edge_local = Edge {
|
||||||
curve: LocalForm::new(curve_local, curve_canonical.clone()),
|
curve: LocalForm::new(curve_local, curve_canonical),
|
||||||
vertices: vertices.clone(),
|
vertices: vertices.clone(),
|
||||||
};
|
};
|
||||||
let edge_canonical = tmp.merge(Edge {
|
let edge_canonical = Edge {
|
||||||
curve: LocalForm::canonical_only(curve_canonical),
|
curve: LocalForm::canonical_only(curve_canonical),
|
||||||
vertices,
|
vertices,
|
||||||
});
|
};
|
||||||
|
|
||||||
LocalForm::new(edge_local, edge_canonical)
|
LocalForm::new(edge_local, edge_canonical)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let edges_canonical = cycle
|
let edges_canonical = cycle
|
||||||
.canonical()
|
.canonical()
|
||||||
.get()
|
|
||||||
.edges
|
.edges
|
||||||
.iter()
|
.iter()
|
||||||
.map(|edge| {
|
.map(|edge| {
|
||||||
let edge = edge.canonical().get();
|
let edge = edge.canonical();
|
||||||
|
|
||||||
let curve = {
|
let curve = {
|
||||||
let curve = edge.curve().transform(transform);
|
let curve = edge.curve().transform(transform);
|
||||||
|
|
||||||
let curve = tmp.merge(curve);
|
|
||||||
LocalForm::canonical_only(curve)
|
LocalForm::canonical_only(curve)
|
||||||
};
|
};
|
||||||
let vertices = edge.vertices.map(|vertex| {
|
let vertices = edge.vertices.map(|vertex| {
|
||||||
let point = vertex.canonical().get().point;
|
let point = vertex.canonical().point;
|
||||||
let point = transform.transform_point(&point);
|
let point = transform.transform_point(&point);
|
||||||
|
|
||||||
let local = *vertex.local();
|
let local = *vertex.local();
|
||||||
let canonical = tmp.merge(Vertex { point });
|
let canonical = Vertex { point };
|
||||||
|
|
||||||
LocalForm::new(local, canonical)
|
LocalForm::new(local, canonical)
|
||||||
});
|
});
|
||||||
|
|
||||||
let edge = tmp.merge(Edge { curve, vertices });
|
let edge = Edge { curve, vertices };
|
||||||
LocalForm::canonical_only(edge)
|
LocalForm::canonical_only(edge)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let cycle_local = Cycle { edges: edges_local };
|
let cycle_local = Cycle { edges: edges_local };
|
||||||
|
|
||||||
let cycle_canonical = tmp.merge(Cycle {
|
let cycle_canonical = Cycle {
|
||||||
edges: edges_canonical,
|
edges: edges_canonical,
|
||||||
});
|
};
|
||||||
|
|
||||||
LocalForm::new(cycle_local, cycle_canonical)
|
LocalForm::new(cycle_local, cycle_canonical)
|
||||||
});
|
});
|
||||||
|
|
|
@ -51,21 +51,20 @@ impl<'r> EdgeBuilder<'r> {
|
||||||
a: Vector::from([radius, Scalar::ZERO]),
|
a: Vector::from([radius, Scalar::ZERO]),
|
||||||
b: Vector::from([Scalar::ZERO, radius]),
|
b: Vector::from([Scalar::ZERO, radius]),
|
||||||
});
|
});
|
||||||
let curve_canonical =
|
let curve_canonical = Curve::Circle(Circle {
|
||||||
self.shape.get_handle_or_insert(Curve::Circle(Circle {
|
|
||||||
center: Point::origin(),
|
center: Point::origin(),
|
||||||
a: Vector::from([radius, Scalar::ZERO, Scalar::ZERO]),
|
a: Vector::from([radius, Scalar::ZERO, Scalar::ZERO]),
|
||||||
b: Vector::from([Scalar::ZERO, radius, Scalar::ZERO]),
|
b: Vector::from([Scalar::ZERO, radius, Scalar::ZERO]),
|
||||||
}));
|
});
|
||||||
|
|
||||||
let edge_local = Edge {
|
let edge_local = Edge {
|
||||||
curve: LocalForm::new(curve_local, curve_canonical.clone()),
|
curve: LocalForm::new(curve_local, curve_canonical),
|
||||||
vertices: VerticesOfEdge::none(),
|
vertices: VerticesOfEdge::none(),
|
||||||
};
|
};
|
||||||
let edge_canonical = self.shape.get_handle_or_insert(Edge {
|
let edge_canonical = Edge {
|
||||||
curve: LocalForm::canonical_only(curve_canonical),
|
curve: LocalForm::canonical_only(curve_canonical),
|
||||||
vertices: VerticesOfEdge::none(),
|
vertices: VerticesOfEdge::none(),
|
||||||
});
|
};
|
||||||
|
|
||||||
LocalForm::new(edge_local, edge_canonical)
|
LocalForm::new(edge_local, edge_canonical)
|
||||||
}
|
}
|
||||||
|
@ -90,12 +89,9 @@ impl<'r> EdgeBuilder<'r> {
|
||||||
) -> Handle<Edge<3>> {
|
) -> Handle<Edge<3>> {
|
||||||
let curve = {
|
let curve = {
|
||||||
let points = [a, b].map(|vertex| vertex.point);
|
let points = [a, b].map(|vertex| vertex.point);
|
||||||
let curve = Curve::Line(Line::from_points(points));
|
Curve::Line(Line::from_points(points))
|
||||||
self.shape.get_handle_or_insert(curve)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let [a, b] = [a, b].map(|vertex| self.shape.insert(vertex));
|
|
||||||
|
|
||||||
let vertices = [
|
let vertices = [
|
||||||
LocalForm::new(Point::from([0.]), a),
|
LocalForm::new(Point::from([0.]), a),
|
||||||
LocalForm::new(Point::from([1.]), b),
|
LocalForm::new(Point::from([1.]), b),
|
||||||
|
@ -144,14 +140,15 @@ impl<'r> CycleBuilder<'r> {
|
||||||
let points_canonical = points
|
let points_canonical = points
|
||||||
.map(|point| self.surface.point_from_surface_coords(point));
|
.map(|point| self.surface.point_from_surface_coords(point));
|
||||||
let edge_canonical = Edge::builder(self.shape)
|
let edge_canonical = Edge::builder(self.shape)
|
||||||
.build_line_segment_from_points(points_canonical);
|
.build_line_segment_from_points(points_canonical)
|
||||||
|
.get();
|
||||||
|
|
||||||
let edge_local = Edge {
|
let edge_local = Edge {
|
||||||
curve: LocalForm::new(
|
curve: LocalForm::new(
|
||||||
Curve::Line(Line::from_points(points)),
|
Curve::Line(Line::from_points(points)),
|
||||||
edge_canonical.get().curve.canonical(),
|
edge_canonical.curve.canonical(),
|
||||||
),
|
),
|
||||||
vertices: edge_canonical.get().vertices,
|
vertices: edge_canonical.vertices.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
edges.push(LocalForm::new(edge_local, edge_canonical));
|
edges.push(LocalForm::new(edge_local, edge_canonical));
|
||||||
|
@ -162,8 +159,7 @@ impl<'r> CycleBuilder<'r> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let edges_canonical = edges.into_iter().map(|edge| edge.canonical());
|
let edges_canonical = edges.into_iter().map(|edge| edge.canonical());
|
||||||
let canonical =
|
let canonical = Cycle::new(edges_canonical);
|
||||||
self.shape.get_handle_or_insert(Cycle::new(edges_canonical));
|
|
||||||
|
|
||||||
LocalForm::new(local, canonical)
|
LocalForm::new(local, canonical)
|
||||||
}
|
}
|
||||||
|
|
|
@ -463,8 +463,7 @@ mod tests {
|
||||||
let mut shape = Shape::new();
|
let mut shape = Shape::new();
|
||||||
let cycle = Cycle::builder(Surface::xy_plane(), &mut shape)
|
let cycle = Cycle::builder(Surface::xy_plane(), &mut shape)
|
||||||
.build_polygon([[0., 0.], [1., 0.], [0., 1.]])
|
.build_polygon([[0., 0.], [1., 0.], [0., 1.]])
|
||||||
.canonical()
|
.canonical();
|
||||||
.get();
|
|
||||||
|
|
||||||
assert_eq!(3, cycle.curve_iter().count());
|
assert_eq!(3, cycle.curve_iter().count());
|
||||||
assert_eq!(1, cycle.cycle_iter().count());
|
assert_eq!(1, cycle.cycle_iter().count());
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
builder::CycleBuilder,
|
builder::CycleBuilder,
|
||||||
shape::{Handle, LocalForm, Shape},
|
shape::{LocalForm, Shape},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{Edge, Surface};
|
use super::{Edge, Surface};
|
||||||
|
@ -28,7 +28,7 @@ pub struct Cycle<const D: usize> {
|
||||||
|
|
||||||
impl Cycle<3> {
|
impl Cycle<3> {
|
||||||
/// Construct a `Cycle`
|
/// Construct a `Cycle`
|
||||||
pub fn new(edges: impl IntoIterator<Item = Handle<Edge<3>>>) -> Self {
|
pub fn new(edges: impl IntoIterator<Item = Edge<3>>) -> Self {
|
||||||
let edges = edges.into_iter().map(LocalForm::canonical_only).collect();
|
let edges = edges.into_iter().map(LocalForm::canonical_only).collect();
|
||||||
|
|
||||||
Self { edges }
|
Self { edges }
|
||||||
|
@ -44,6 +44,6 @@ impl Cycle<3> {
|
||||||
/// This is a convenience method that saves the caller from dealing with the
|
/// This is a convenience method that saves the caller from dealing with the
|
||||||
/// [`Handle`]s.
|
/// [`Handle`]s.
|
||||||
pub fn edges(&self) -> impl Iterator<Item = Edge<3>> + '_ {
|
pub fn edges(&self) -> impl Iterator<Item = Edge<3>> + '_ {
|
||||||
self.edges.iter().map(|handle| handle.canonical().get())
|
self.edges.iter().map(|handle| handle.canonical())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ impl<const D: usize> Edge<D> {
|
||||||
/// This is a convenience method that saves the caller from dealing with the
|
/// This is a convenience method that saves the caller from dealing with the
|
||||||
/// [`Handle`].
|
/// [`Handle`].
|
||||||
pub fn curve(&self) -> Curve<3> {
|
pub fn curve(&self) -> Curve<3> {
|
||||||
self.curve.canonical().get()
|
self.curve.canonical()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Access the vertices that the edge refers to
|
/// Access the vertices that the edge refers to
|
||||||
|
@ -54,7 +54,7 @@ impl<const D: usize> Edge<D> {
|
||||||
self.vertices
|
self.vertices
|
||||||
.0
|
.0
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|[a, b]| [a.canonical().get(), b.canonical().get()])
|
.map(|[a, b]| [a.canonical(), b.canonical()])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ impl VerticesOfEdge {
|
||||||
[a.canonical(), b.canonical()]
|
[a.canonical(), b.canonical()]
|
||||||
};
|
};
|
||||||
|
|
||||||
return [a.clone(), b.clone()] == other || [b, a] == other;
|
return [a, b] == other || [b, a] == other;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -211,7 +211,7 @@ impl CyclesInFace {
|
||||||
|
|
||||||
/// Access an iterator over the canonical forms of the cycles
|
/// Access an iterator over the canonical forms of the cycles
|
||||||
pub fn as_canonical(&self) -> impl Iterator<Item = Cycle<3>> + '_ {
|
pub fn as_canonical(&self) -> impl Iterator<Item = Cycle<3>> + '_ {
|
||||||
self.0.iter().map(|cycle| cycle.canonical().get())
|
self.0.iter().map(|cycle| cycle.canonical())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Access an iterator over local forms of the cycles
|
/// Access an iterator over local forms of the cycles
|
||||||
|
|
|
@ -177,7 +177,7 @@ mod tests {
|
||||||
|
|
||||||
let vertex = Vertex { point };
|
let vertex = Vertex { point };
|
||||||
let edge = Edge {
|
let edge = Edge {
|
||||||
curve: LocalForm::canonical_only(curve),
|
curve: LocalForm::canonical_only(curve.get()),
|
||||||
vertices: VerticesOfEdge::none(),
|
vertices: VerticesOfEdge::none(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ mod tests {
|
||||||
assert!(shape.get_handle(&vertex.get()).as_ref() == Some(&vertex));
|
assert!(shape.get_handle(&vertex.get()).as_ref() == Some(&vertex));
|
||||||
assert!(shape.get_handle(&edge.get()).as_ref() == Some(&edge));
|
assert!(shape.get_handle(&edge.get()).as_ref() == Some(&edge));
|
||||||
|
|
||||||
let cycle = Cycle::new(vec![edge]);
|
let cycle = Cycle::new(vec![edge.get()]);
|
||||||
assert!(shape.get_handle(&cycle).is_none());
|
assert!(shape.get_handle(&cycle).is_none());
|
||||||
|
|
||||||
let cycle = shape.insert(cycle);
|
let cycle = shape.insert(cycle);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
|
||||||
use super::{Handle, Object};
|
use super::Object;
|
||||||
|
|
||||||
/// A reference to an object, which includes a local form
|
/// A reference to an object, which includes a local form
|
||||||
///
|
///
|
||||||
|
@ -17,7 +17,7 @@ use super::{Handle, Object};
|
||||||
#[derive(Clone, Debug, Eq, Ord, PartialOrd)]
|
#[derive(Clone, Debug, Eq, Ord, PartialOrd)]
|
||||||
pub struct LocalForm<Local, Canonical: Object> {
|
pub struct LocalForm<Local, Canonical: Object> {
|
||||||
local: Local,
|
local: Local,
|
||||||
canonical: Handle<Canonical>,
|
canonical: Canonical,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Local, Canonical: Object> LocalForm<Local, Canonical> {
|
impl<Local, Canonical: Object> LocalForm<Local, Canonical> {
|
||||||
|
@ -25,7 +25,7 @@ impl<Local, Canonical: Object> LocalForm<Local, Canonical> {
|
||||||
///
|
///
|
||||||
/// It is the caller's responsibility to make sure that the local and
|
/// It is the caller's responsibility to make sure that the local and
|
||||||
/// canonical forms passed to this method actually match.
|
/// canonical forms passed to this method actually match.
|
||||||
pub fn new(local: Local, canonical: Handle<Canonical>) -> Self {
|
pub fn new(local: Local, canonical: Canonical) -> Self {
|
||||||
Self { local, canonical }
|
Self { local, canonical }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ impl<Local, Canonical: Object> LocalForm<Local, Canonical> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Access the canonical form of the referenced object
|
/// Access the canonical form of the referenced object
|
||||||
pub fn canonical(&self) -> Handle<Canonical> {
|
pub fn canonical(&self) -> Canonical {
|
||||||
self.canonical.clone()
|
self.canonical.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,8 @@ impl<Canonical: Object> LocalForm<Canonical, Canonical> {
|
||||||
/// It's possible that an object's local and canonical forms are the same.
|
/// It's possible that an object's local and canonical forms are the same.
|
||||||
/// This is a convenience constructor that constructs a `LocalForm` instance
|
/// This is a convenience constructor that constructs a `LocalForm` instance
|
||||||
/// for such a situation.
|
/// for such a situation.
|
||||||
pub fn canonical_only(canonical: Handle<Canonical>) -> Self {
|
pub fn canonical_only(canonical: Canonical) -> Self {
|
||||||
Self::new(canonical.get(), canonical)
|
Self::new(canonical.clone(), canonical)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,8 +57,7 @@ where
|
||||||
Canonical: PartialEq,
|
Canonical: PartialEq,
|
||||||
{
|
{
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.local == other.local
|
self.local == other.local && self.canonical == other.canonical
|
||||||
&& self.canonical.get() == other.canonical.get()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +68,6 @@ where
|
||||||
{
|
{
|
||||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
self.local.hash(state);
|
self.local.hash(state);
|
||||||
self.canonical.get().hash(state);
|
self.canonical.hash(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,12 +44,12 @@ impl Object for Edge<3> {
|
||||||
|
|
||||||
let vertices = self.vertices.convert(|vertex| {
|
let vertices = self.vertices.convert(|vertex| {
|
||||||
let canonical = vertex.canonical();
|
let canonical = vertex.canonical();
|
||||||
let canonical = canonical.get().merge_into(shape);
|
let canonical = canonical.merge_into(shape);
|
||||||
LocalForm::new(*vertex.local(), canonical)
|
LocalForm::new(*vertex.local(), canonical.get())
|
||||||
});
|
});
|
||||||
|
|
||||||
shape.get_handle_or_insert(Edge {
|
shape.get_handle_or_insert(Edge {
|
||||||
curve: LocalForm::canonical_only(curve),
|
curve: LocalForm::canonical_only(curve.get()),
|
||||||
vertices: VerticesOfEdge::new(vertices),
|
vertices: VerticesOfEdge::new(vertices),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -60,8 +60,8 @@ impl Object for Cycle<3> {
|
||||||
let mut edges = Vec::new();
|
let mut edges = Vec::new();
|
||||||
for edge in self.edges {
|
for edge in self.edges {
|
||||||
let edge = edge.canonical();
|
let edge = edge.canonical();
|
||||||
let edge = edge.get().merge_into(shape);
|
let edge = edge.merge_into(shape);
|
||||||
edges.push(edge);
|
edges.push(edge.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
shape.get_handle_or_insert(Cycle::new(edges))
|
shape.get_handle_or_insert(Cycle::new(edges))
|
||||||
|
@ -76,14 +76,20 @@ impl Object for Face {
|
||||||
|
|
||||||
let mut exts = Vec::new();
|
let mut exts = Vec::new();
|
||||||
for cycle in face.exteriors.as_local_form() {
|
for cycle in face.exteriors.as_local_form() {
|
||||||
let merged = cycle.canonical().get().merge_into(shape);
|
let merged = cycle.canonical().merge_into(shape);
|
||||||
exts.push(LocalForm::new(cycle.local().clone(), merged));
|
exts.push(LocalForm::new(
|
||||||
|
cycle.local().clone(),
|
||||||
|
merged.get(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut ints = Vec::new();
|
let mut ints = Vec::new();
|
||||||
for cycle in face.interiors.as_local_form() {
|
for cycle in face.interiors.as_local_form() {
|
||||||
let merged = cycle.canonical().get().merge_into(shape);
|
let merged = cycle.canonical().merge_into(shape);
|
||||||
ints.push(LocalForm::new(cycle.local().clone(), merged));
|
ints.push(LocalForm::new(
|
||||||
|
cycle.local().clone(),
|
||||||
|
merged.get(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
shape.get_handle_or_insert(Face::new(
|
shape.get_handle_or_insert(Face::new(
|
||||||
|
|
|
@ -19,7 +19,7 @@ pub fn validate_edge(
|
||||||
for vertex in edge.vertices.iter() {
|
for vertex in edge.vertices.iter() {
|
||||||
let local = *vertex.local();
|
let local = *vertex.local();
|
||||||
let local_as_canonical = edge.curve().point_from_curve_coords(local);
|
let local_as_canonical = edge.curve().point_from_curve_coords(local);
|
||||||
let canonical = vertex.canonical().get().point;
|
let canonical = vertex.canonical().point;
|
||||||
let distance = (local_as_canonical - canonical).magnitude();
|
let distance = (local_as_canonical - canonical).magnitude();
|
||||||
|
|
||||||
if distance > max_distance {
|
if distance > max_distance {
|
||||||
|
|
|
@ -232,18 +232,16 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn coherence_edge() {
|
fn coherence_edge() {
|
||||||
let mut tmp = Shape::new();
|
|
||||||
|
|
||||||
let a = Point::from([0., 0., 0.]);
|
let a = Point::from([0., 0., 0.]);
|
||||||
let b = Point::from([1., 0., 0.]);
|
let b = Point::from([1., 0., 0.]);
|
||||||
|
|
||||||
let curve = {
|
let curve = {
|
||||||
let curve = tmp.insert(Curve::line_from_points([a, b]));
|
let curve = Curve::line_from_points([a, b]);
|
||||||
LocalForm::canonical_only(curve)
|
LocalForm::canonical_only(curve)
|
||||||
};
|
};
|
||||||
|
|
||||||
let a = tmp.insert(Vertex { point: a });
|
let a = Vertex { point: a };
|
||||||
let b = tmp.insert(Vertex { point: b });
|
let b = Vertex { point: b };
|
||||||
|
|
||||||
let deviation = Scalar::from_f64(0.25);
|
let deviation = Scalar::from_f64(0.25);
|
||||||
|
|
||||||
|
@ -279,15 +277,17 @@ mod tests {
|
||||||
|
|
||||||
// Trying to refer to edge that is not from the same shape. Should fail.
|
// Trying to refer to edge that is not from the same shape. Should fail.
|
||||||
let edge = Edge::builder(&mut other)
|
let edge = Edge::builder(&mut other)
|
||||||
.build_line_segment_from_points([[0., 0., 0.], [1., 0., 0.]]);
|
.build_line_segment_from_points([[0., 0., 0.], [1., 0., 0.]])
|
||||||
|
.get();
|
||||||
shape.insert(Cycle::new(vec![edge.clone()]));
|
shape.insert(Cycle::new(vec![edge.clone()]));
|
||||||
let err =
|
let err =
|
||||||
validate(shape.clone(), &ValidationConfig::default()).unwrap_err();
|
validate(shape.clone(), &ValidationConfig::default()).unwrap_err();
|
||||||
assert!(err.missing_edge(&edge.get()));
|
assert!(err.missing_edge(&edge));
|
||||||
|
|
||||||
// Referring to edge that *is* from the same shape. Should work.
|
// Referring to edge that *is* from the same shape. Should work.
|
||||||
let edge = Edge::builder(&mut shape)
|
let edge = Edge::builder(&mut shape)
|
||||||
.build_line_segment_from_points([[0., 0., 0.], [1., 0., 0.]]);
|
.build_line_segment_from_points([[0., 0., 0.], [1., 0., 0.]])
|
||||||
|
.get();
|
||||||
shape.insert(Cycle::new(vec![edge]));
|
shape.insert(Cycle::new(vec![edge]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,27 +296,35 @@ mod tests {
|
||||||
let mut shape = Shape::new();
|
let mut shape = Shape::new();
|
||||||
let mut other = Shape::new();
|
let mut other = Shape::new();
|
||||||
|
|
||||||
let curve = other.insert(Curve::x_axis());
|
let curve = Curve::x_axis();
|
||||||
let a = Vertex::builder(&mut other).build_from_point([1., 0., 0.]);
|
let a = Vertex::builder(&mut other)
|
||||||
let b = Vertex::builder(&mut other).build_from_point([2., 0., 0.]);
|
.build_from_point([1., 0., 0.])
|
||||||
|
.get();
|
||||||
|
let b = Vertex::builder(&mut other)
|
||||||
|
.build_from_point([2., 0., 0.])
|
||||||
|
.get();
|
||||||
|
|
||||||
let a = LocalForm::new(Point::from([1.]), a);
|
let a = LocalForm::new(Point::from([1.]), a);
|
||||||
let b = LocalForm::new(Point::from([2.]), b);
|
let b = LocalForm::new(Point::from([2.]), b);
|
||||||
|
|
||||||
// Shouldn't work. Nothing has been added to `shape`.
|
// Shouldn't work. Nothing has been added to `shape`.
|
||||||
shape.insert(Edge {
|
shape.insert(Edge {
|
||||||
curve: LocalForm::canonical_only(curve.clone()),
|
curve: LocalForm::canonical_only(curve),
|
||||||
vertices: VerticesOfEdge::from_vertices([a.clone(), b.clone()]),
|
vertices: VerticesOfEdge::from_vertices([a.clone(), b.clone()]),
|
||||||
});
|
});
|
||||||
let err =
|
let err =
|
||||||
validate(shape.clone(), &ValidationConfig::default()).unwrap_err();
|
validate(shape.clone(), &ValidationConfig::default()).unwrap_err();
|
||||||
assert!(err.missing_curve(&curve.get()));
|
assert!(err.missing_curve(&curve));
|
||||||
assert!(err.missing_vertex(&a.canonical().get()));
|
assert!(err.missing_vertex(&a.canonical()));
|
||||||
assert!(err.missing_vertex(&b.canonical().get()));
|
assert!(err.missing_vertex(&b.canonical()));
|
||||||
|
|
||||||
let curve = shape.insert(Curve::x_axis());
|
let curve = Curve::x_axis();
|
||||||
let a = Vertex::builder(&mut shape).build_from_point([1., 0., 0.]);
|
let a = Vertex::builder(&mut shape)
|
||||||
let b = Vertex::builder(&mut shape).build_from_point([2., 0., 0.]);
|
.build_from_point([1., 0., 0.])
|
||||||
|
.get();
|
||||||
|
let b = Vertex::builder(&mut shape)
|
||||||
|
.build_from_point([2., 0., 0.])
|
||||||
|
.get();
|
||||||
|
|
||||||
let a = LocalForm::new(Point::from([1.]), a);
|
let a = LocalForm::new(Point::from([1.]), a);
|
||||||
let b = LocalForm::new(Point::from([2.]), b);
|
let b = LocalForm::new(Point::from([2.]), b);
|
||||||
|
@ -349,7 +357,7 @@ mod tests {
|
||||||
let err =
|
let err =
|
||||||
validate(shape.clone(), &ValidationConfig::default()).unwrap_err();
|
validate(shape.clone(), &ValidationConfig::default()).unwrap_err();
|
||||||
assert!(err.missing_surface(&surface.get()));
|
assert!(err.missing_surface(&surface.get()));
|
||||||
assert!(err.missing_cycle(&cycle.canonical().get()));
|
assert!(err.missing_cycle(&cycle.canonical()));
|
||||||
|
|
||||||
let surface = shape.insert(Surface::xy_plane());
|
let surface = shape.insert(Surface::xy_plane());
|
||||||
let cycle =
|
let cycle =
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub fn validate_edge(
|
||||||
let mut missing_vertices = HashSet::new();
|
let mut missing_vertices = HashSet::new();
|
||||||
|
|
||||||
if !curves.contains(&edge.curve()) {
|
if !curves.contains(&edge.curve()) {
|
||||||
missing_curve = Some(edge.curve.canonical().get());
|
missing_curve = Some(edge.curve.canonical());
|
||||||
}
|
}
|
||||||
for vertex in edge.vertices().into_iter().flatten() {
|
for vertex in edge.vertices().into_iter().flatten() {
|
||||||
if !vertices.contains(&vertex) {
|
if !vertices.contains(&vertex) {
|
||||||
|
|
|
@ -27,7 +27,7 @@ impl ToShape for fj::Circle {
|
||||||
let cycle_local = Cycle {
|
let cycle_local = Cycle {
|
||||||
edges: vec![edge.clone()],
|
edges: vec![edge.clone()],
|
||||||
};
|
};
|
||||||
let cycle_canonical = tmp.insert(Cycle::new(vec![edge.canonical()]));
|
let cycle_canonical = Cycle::new(vec![edge.canonical()]);
|
||||||
|
|
||||||
let surface = tmp.insert(Surface::xy_plane());
|
let surface = tmp.insert(Surface::xy_plane());
|
||||||
let face = tmp
|
let face = tmp
|
||||||
|
|
|
@ -3,7 +3,7 @@ use fj_kernel::{
|
||||||
algorithms::Tolerance,
|
algorithms::Tolerance,
|
||||||
iter::ObjectIters,
|
iter::ObjectIters,
|
||||||
objects::{Cycle, Edge, Face},
|
objects::{Cycle, Edge, Face},
|
||||||
shape::{LocalForm, Shape},
|
shape::LocalForm,
|
||||||
validation::{validate, Validated, ValidationConfig, ValidationError},
|
validation::{validate, Validated, ValidationConfig, ValidationError},
|
||||||
};
|
};
|
||||||
use fj_math::Aabb;
|
use fj_math::Aabb;
|
||||||
|
@ -95,8 +95,6 @@ fn add_cycle(
|
||||||
cycle: LocalForm<Cycle<2>, Cycle<3>>,
|
cycle: LocalForm<Cycle<2>, Cycle<3>>,
|
||||||
reverse: bool,
|
reverse: bool,
|
||||||
) -> LocalForm<Cycle<2>, Cycle<3>> {
|
) -> LocalForm<Cycle<2>, Cycle<3>> {
|
||||||
let mut tmp = Shape::new();
|
|
||||||
|
|
||||||
let mut edges = Vec::new();
|
let mut edges = Vec::new();
|
||||||
for edge in cycle.local().edges.clone() {
|
for edge in cycle.local().edges.clone() {
|
||||||
let curve_local = *edge.local().curve.local();
|
let curve_local = *edge.local().curve.local();
|
||||||
|
@ -106,13 +104,12 @@ fn add_cycle(
|
||||||
curve_local
|
curve_local
|
||||||
};
|
};
|
||||||
|
|
||||||
let curve_canonical = edge.canonical().get().curve();
|
let curve_canonical = edge.canonical().curve();
|
||||||
let curve_canonical = if reverse {
|
let curve_canonical = if reverse {
|
||||||
curve_canonical.reverse()
|
curve_canonical.reverse()
|
||||||
} else {
|
} else {
|
||||||
curve_canonical
|
curve_canonical
|
||||||
};
|
};
|
||||||
let curve_canonical = tmp.insert(curve_canonical);
|
|
||||||
|
|
||||||
let vertices = if reverse {
|
let vertices = if reverse {
|
||||||
edge.local().vertices.clone().reverse()
|
edge.local().vertices.clone().reverse()
|
||||||
|
@ -121,13 +118,13 @@ fn add_cycle(
|
||||||
};
|
};
|
||||||
|
|
||||||
let edge_local = Edge {
|
let edge_local = Edge {
|
||||||
curve: LocalForm::new(curve_local, curve_canonical.clone()),
|
curve: LocalForm::new(curve_local, curve_canonical),
|
||||||
vertices: vertices.clone(),
|
vertices: vertices.clone(),
|
||||||
};
|
};
|
||||||
let edge_canonical = tmp.merge(Edge {
|
let edge_canonical = Edge {
|
||||||
curve: LocalForm::canonical_only(curve_canonical),
|
curve: LocalForm::canonical_only(curve_canonical),
|
||||||
vertices,
|
vertices,
|
||||||
});
|
};
|
||||||
|
|
||||||
edges.push(LocalForm::new(edge_local, edge_canonical));
|
edges.push(LocalForm::new(edge_local, edge_canonical));
|
||||||
}
|
}
|
||||||
|
@ -140,7 +137,7 @@ fn add_cycle(
|
||||||
edges: edges.clone(),
|
edges: edges.clone(),
|
||||||
};
|
};
|
||||||
let cycle_canonical =
|
let cycle_canonical =
|
||||||
tmp.insert(Cycle::new(edges.into_iter().map(|edge| edge.canonical())));
|
Cycle::new(edges.into_iter().map(|edge| edge.canonical()));
|
||||||
|
|
||||||
LocalForm::new(cycle_local, cycle_canonical)
|
LocalForm::new(cycle_local, cycle_canonical)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue