Skip to content

Commit

Permalink
Simplify RangeOnPath
Browse files Browse the repository at this point in the history
It has been dumbed down so much, that the API it still had no longer
made sense.
  • Loading branch information
hannobraun committed Sep 15, 2022
1 parent c051f4d commit 24e1e36
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 29 deletions.
3 changes: 2 additions & 1 deletion crates/fj-kernel/src/algorithms/approx/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ impl Approx for &HalfEdge {
cache: &mut Self::Cache,
) -> Self::Approximation {
let &[a, b] = self.vertices();
let range = RangeOnPath::new([a, b].map(|vertex| vertex.position()));
let boundary = [a, b].map(|vertex| vertex.position());
let range = RangeOnPath { boundary };

let first = ApproxPoint::new(
a.surface_form().position(),
Expand Down
32 changes: 4 additions & 28 deletions crates/fj-kernel/src/algorithms/approx/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,41 +59,17 @@ impl Approx for (GlobalPath, RangeOnPath) {
/// The range on which a path should be approximated
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub struct RangeOnPath {
boundary: [Point<1>; 2],
}

impl RangeOnPath {
/// Construct an instance of `RangeOnCurve`
///
/// Ranges are normalized on construction, meaning that the order of
/// vertices passed to this constructor does not influence the range that is
/// constructed.
///
/// This is done to prevent bugs during mesh construction: The curve
/// approximation code is regularly faced with ranges that are reversed
/// versions of each other. This can lead to slightly different
/// approximations, which in turn leads to the aforementioned invalid
/// meshes.
///
/// The caller can use `is_reversed` to determine, if the range was reversed
/// during normalization, to adjust the approximation accordingly.
pub fn new(boundary: [impl Into<Point<1>>; 2]) -> Self {
let boundary = boundary.map(Into::into);
Self { boundary }
}

/// Access the boundary of the range
pub fn boundary(&self) -> [Point<1>; 2] {
self.boundary
}
/// The boundary of the range
pub boundary: [Point<1>; 2],
}

impl<T> From<[T; 2]> for RangeOnPath
where
T: Into<Point<1>>,
{
fn from(boundary: [T; 2]) -> Self {
Self::new(boundary)
let boundary = boundary.map(Into::into);
Self { boundary }
}
}

Expand Down

0 comments on commit 24e1e36

Please sign in to comment.