-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1017 from hannobraun/reverse2
Clean up and expand `algorithms::reverse`
- Loading branch information
Showing
10 changed files
with
165 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use crate::objects::{Curve, GlobalCurve}; | ||
|
||
use super::Reverse; | ||
|
||
impl Reverse for Curve { | ||
/// Reverse the curve | ||
/// | ||
/// # Implementation Note | ||
/// | ||
/// Right now, the orientation of a face is defined by the orientation of | ||
/// its surface. By extension, the orientation of a surface is defined by | ||
/// the orientation of the curve it was swept from. This leads to some | ||
/// complications. See this issue for context: | ||
/// <https://github.com/hannobraun/Fornjot/issues/695> | ||
/// | ||
/// It would probably be much better, if `Surface`s were without | ||
/// orientation, which would then make it possible for curves to be without | ||
/// direction. Then this implementation would not exist. | ||
fn reverse(self) -> Self { | ||
Curve::new(self.kind().reverse(), self.global().reverse()) | ||
} | ||
} | ||
|
||
impl Reverse for GlobalCurve { | ||
/// Reverse the curve | ||
/// | ||
/// # Implementation Note | ||
/// | ||
/// Right now, the orientation of a face is defined by the orientation of | ||
/// its surface. By extension, the orientation of a surface is defined by | ||
/// the orientation of the curve it was swept from. This leads to some | ||
/// complications. See this issue for context: | ||
/// <https://github.com/hannobraun/Fornjot/issues/695> | ||
/// | ||
/// It would probably be much better, if `Surface`s were without | ||
/// orientation, which would then make it possible for curves to be without | ||
/// direction. Then this implementation would not exist. | ||
fn reverse(self) -> Self { | ||
Self::from_kind(self.kind().reverse()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use crate::objects::Cycle; | ||
|
||
use super::Reverse; | ||
|
||
impl Reverse for Cycle { | ||
fn reverse(self) -> Self { | ||
let surface = *self.surface(); | ||
|
||
let mut edges = self | ||
.into_edges() | ||
.map(|edge| edge.reverse()) | ||
.collect::<Vec<_>>(); | ||
|
||
edges.reverse(); | ||
|
||
Cycle::new(surface).with_edges(edges) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use crate::objects::Edge; | ||
|
||
use super::Reverse; | ||
|
||
impl Reverse for Edge { | ||
fn reverse(self) -> Self { | ||
Edge::from_curve_and_vertices( | ||
self.curve().reverse(), | ||
self.vertices().reverse(), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//! Reverse the direction/orientation of objects | ||
mod curve; | ||
mod cycle; | ||
mod edge; | ||
mod face; | ||
mod surface; | ||
|
||
/// Reverse the direction/orientation of an object | ||
pub trait Reverse { | ||
/// Reverse the direction/orientation of the object | ||
#[must_use] | ||
fn reverse(self) -> Self; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use crate::objects::Surface; | ||
|
||
use super::Reverse; | ||
|
||
impl Reverse for Surface { | ||
/// Reverse the surface | ||
/// | ||
/// # Implementation Note | ||
/// | ||
/// Right now, the orientation of a face is defined by the orientation of | ||
/// its surface. This leads to some complications. See this issue for | ||
/// context: | ||
/// <https://github.com/hannobraun/Fornjot/issues/695> | ||
/// | ||
/// It would probably be much better, if `Surface`s were without | ||
/// orientation, and the orientation of a face were defined by the direction | ||
/// of the half-edges that bound it. | ||
/// | ||
/// Please note that, as of this writing, half-edges don't really exist as a | ||
/// concept in the kernel. We kind of treat `Edge` as a half-edge, but in an | ||
/// inconsistent way that causes problems. This issue has some context on | ||
/// that: | ||
/// <https://github.com/hannobraun/Fornjot/issues/993> | ||
/// | ||
/// So, in conclusion, in a perfect world, this implementation would not | ||
/// exist. | ||
fn reverse(self) -> Self { | ||
match self { | ||
Self::SweptCurve(surface) => Self::SweptCurve(surface.reverse()), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters