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

Simplify Edge reversal #1055

Merged
merged 3 commits into from
Sep 8, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/approx/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn number_of_vertices_for_circle(
}

/// The range on which a curve should be approximated
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct RangeOnCurve {
/// The boundary of the range
///
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/reverse/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ impl Reverse for Cycle {

let mut edges = self
.into_edges()
.map(|edge| edge.reverse())
.map(|edge| edge.reverse_including_curve())
.collect::<Vec<_>>();

edges.reverse();
Expand Down
5 changes: 1 addition & 4 deletions crates/fj-kernel/src/algorithms/reverse/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ use super::Reverse;

impl Reverse for Edge {
fn reverse(self) -> Self {
Edge::from_curve_and_vertices(
self.curve().reverse(),
self.vertices().reverse(),
)
Edge::from_curve_and_vertices(*self.curve(), self.vertices().reverse())
}
}
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn create_non_continuous_side_face(
color: Color,
) -> Face {
let edge = if path.is_negative_direction() {
edge.reverse()
edge.reverse_including_curve()
} else {
*edge
};
Expand Down
45 changes: 29 additions & 16 deletions crates/fj-kernel/src/objects/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,34 @@ impl Edge {
Self::new(curve, vertices, global)
}

/// Reverse the edge, including the curve
///
/// # Implementation Note
///
/// It would be much nicer to just reverse the edge normally everywhere, but
/// we can't do that, until #695 is addressed:
/// <https://github.com/hannobraun/Fornjot/issues/695>
pub fn reverse_including_curve(self) -> Self {
let vertices = VerticesOfEdge(self.vertices.get().map(|[a, b]| {
[
Vertex::new(
-b.position(),
b.curve().reverse(),
*b.surface_form(),
*b.global_form(),
),
Vertex::new(
-a.position(),
a.curve().reverse(),
*a.surface_form(),
*a.global_form(),
),
]
}));

Self::from_curve_and_vertices(self.curve().reverse(), vertices)
}

/// Access the curve that defines the edge's geometry
///
/// The edge can be a segment of the curve that is bounded by two vertices,
Expand Down Expand Up @@ -211,22 +239,7 @@ impl VerticesOfEdge<Vertex> {
///
/// Makes sure that the local coordinates are still correct.
pub fn reverse(self) -> Self {
Self(self.0.map(|[a, b]| {
[
Vertex::new(
-b.position(),
b.curve().reverse(),
*b.surface_form(),
*b.global_form(),
),
Vertex::new(
-a.position(),
a.curve().reverse(),
*a.surface_form(),
*a.global_form(),
),
]
}))
Self(self.0.map(|[a, b]| [b, a]))
}

/// Convert this instance into its global variant
Expand Down