Skip to content

Commit

Permalink
Make Edge::new generic
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Jun 14, 2022
1 parent 4fcfc3d commit 4549165
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
11 changes: 7 additions & 4 deletions crates/fj-kernel/src/shape/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ mod tests {
assert!(shape.get_handle(&surface.get()).as_ref() == Some(&surface));

let vertex = Vertex { point };
let edge = Edge::new(curve, VerticesOfEdge::none());
let edge =
Edge::new(LocalForm::canonical_only(curve), VerticesOfEdge::none());

assert!(shape.get_handle(&vertex).is_none());
assert!(shape.get_handle(&edge).is_none());
Expand Down Expand Up @@ -376,7 +377,7 @@ mod tests {
// Shouldn't work. Nothing has been added to `shape`.
let err = shape
.insert(Edge::new(
curve.clone(),
LocalForm::canonical_only(curve.clone()),
VerticesOfEdge::from_vertices([a.clone(), b.clone()]),
))
.unwrap_err();
Expand All @@ -392,8 +393,10 @@ mod tests {
let b = LocalForm::new(Point::from([2.]), b);

// Everything has been added to `shape` now. Should work!
shape
.insert(Edge::new(curve, VerticesOfEdge::from_vertices([a, b])))?;
shape.insert(Edge::new(
LocalForm::canonical_only(curve),
VerticesOfEdge::from_vertices([a, b]),
))?;

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/shape/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl Object for Edge<3> {
})?;

let merged = shape.get_handle_or_insert(Edge::new(
curve,
LocalForm::canonical_only(curve),
VerticesOfEdge::new(vertices),
))?;

Expand Down
9 changes: 5 additions & 4 deletions crates/fj-kernel/src/topology/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ impl<'r> EdgeBuilder<'r> {
curve: LocalForm::new(curve_local, curve_canonical.clone()),
vertices: VerticesOfEdge::none(),
};
let edge_canonical = self
.shape
.insert(Edge::new(curve_canonical, VerticesOfEdge::none()))?;
let edge_canonical = self.shape.insert(Edge::new(
LocalForm::canonical_only(curve_canonical),
VerticesOfEdge::none(),
))?;

Ok(LocalForm::new(edge_local, edge_canonical))
}
Expand Down Expand Up @@ -109,7 +110,7 @@ impl<'r> EdgeBuilder<'r> {
];

let edge = self.shape.insert(Edge::new(
curve,
LocalForm::canonical_only(curve),
VerticesOfEdge::from_vertices(vertices),
))?;

Expand Down
16 changes: 9 additions & 7 deletions crates/fj-kernel/src/topology/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use fj_math::Point;

use crate::{
geometry::Curve,
shape::{Handle, LocalForm, Shape},
shape::{LocalForm, Shape},
};

use super::{EdgeBuilder, Vertex};
Expand Down Expand Up @@ -38,6 +38,14 @@ pub struct Edge<const D: usize> {
}

impl<const D: usize> Edge<D> {
/// Construct an instance of `Edge`
pub fn new(
curve: LocalForm<Curve<D>, Curve<3>>,
vertices: VerticesOfEdge,
) -> Self {
Self { curve, vertices }
}

/// Access the curve that the edge refers to
///
/// This is a convenience method that saves the caller from dealing with the
Expand All @@ -59,12 +67,6 @@ impl<const D: usize> Edge<D> {
}

impl Edge<3> {
/// Construct an instance of `Edge`
pub fn new(curve: Handle<Curve<3>>, vertices: VerticesOfEdge) -> Self {
let curve = LocalForm::canonical_only(curve);
Self { curve, vertices }
}

/// Build an edge using the [`EdgeBuilder`] API
pub fn builder(shape: &mut Shape) -> EdgeBuilder {
EdgeBuilder::new(shape)
Expand Down
6 changes: 4 additions & 2 deletions crates/fj-operations/src/difference_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ fn add_cycle(
curve: LocalForm::new(curve_local, curve_canonical.clone()),
vertices: vertices.clone(),
};
let edge_canonical =
shape.merge(Edge::new(curve_canonical, vertices))?;
let edge_canonical = shape.merge(Edge::new(
LocalForm::canonical_only(curve_canonical),
vertices,
))?;

edges.push(LocalForm::new(edge_local, edge_canonical));
}
Expand Down

0 comments on commit 4549165

Please sign in to comment.