Skip to content

Commit

Permalink
Merge pull request #693 from hannobraun/edge
Browse files Browse the repository at this point in the history
Remove `Edge::new`
  • Loading branch information
hannobraun authored Jun 14, 2022
2 parents 7a0f848 + a4c6a71 commit 95cdb27
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 34 deletions.
19 changes: 12 additions & 7 deletions crates/fj-kernel/src/shape/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,10 @@ 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 {
curve: LocalForm::canonical_only(curve),
vertices: VerticesOfEdge::none(),
};

assert!(shape.get_handle(&vertex).is_none());
assert!(shape.get_handle(&edge).is_none());
Expand Down Expand Up @@ -375,10 +378,10 @@ mod tests {

// Shouldn't work. Nothing has been added to `shape`.
let err = shape
.insert(Edge::new(
curve.clone(),
VerticesOfEdge::from_vertices([a.clone(), b.clone()]),
))
.insert(Edge {
curve: LocalForm::canonical_only(curve.clone()),
vertices: VerticesOfEdge::from_vertices([a.clone(), b.clone()]),
})
.unwrap_err();
assert!(err.missing_curve(&curve));
assert!(err.missing_vertex(&a.canonical()));
Expand All @@ -392,8 +395,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 {
curve: LocalForm::canonical_only(curve),
vertices: VerticesOfEdge::from_vertices([a, b]),
})?;

Ok(())
}
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-kernel/src/shape/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ impl Object for Edge<3> {
Ok(LocalForm::new(*vertex.local(), canonical))
})?;

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

if let Some(handle) = handle {
mapping.edges.insert(handle, merged.clone());
Expand Down
15 changes: 8 additions & 7 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 {
curve: LocalForm::canonical_only(curve_canonical),
vertices: VerticesOfEdge::none(),
})?;

Ok(LocalForm::new(edge_local, edge_canonical))
}
Expand Down Expand Up @@ -108,10 +109,10 @@ impl<'r> EdgeBuilder<'r> {
LocalForm::new(Point::from([1.]), b),
];

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

Ok(edge)
}
Expand Down
22 changes: 8 additions & 14 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 @@ -37,19 +37,6 @@ pub struct Edge<const D: usize> {
pub vertices: VerticesOfEdge,
}

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)
}
}

impl<const D: usize> Edge<D> {
/// Access the curve that the edge refers to
///
Expand All @@ -71,6 +58,13 @@ impl<const D: usize> Edge<D> {
}
}

impl Edge<3> {
/// Build an edge using the [`EdgeBuilder`] API
pub fn builder(shape: &mut Shape) -> EdgeBuilder {
EdgeBuilder::new(shape)
}
}

impl<const D: usize> fmt::Display for Edge<D> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.vertices() {
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 {
curve: LocalForm::canonical_only(curve_canonical),
vertices,
})?;

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

0 comments on commit 95cdb27

Please sign in to comment.