mirror of
https://github.com/hannobraun/Fornjot
synced 2025-02-27 09:35:52 +00:00
Clean up internal representation of Segment
This commit is contained in:
parent
3ea35f18d6
commit
6ee9693cdc
@ -8,28 +8,27 @@ use super::Point;
|
||||
/// parameter.
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd)]
|
||||
pub struct Segment<const D: usize> {
|
||||
a: Point<D>,
|
||||
b: Point<D>,
|
||||
points: [Point<D>; 2],
|
||||
}
|
||||
|
||||
impl<const D: usize> Segment<D> {
|
||||
/// Access the points of the segment
|
||||
pub fn points(&self) -> [Point<D>; 2] {
|
||||
[self.a, self.b]
|
||||
self.points
|
||||
}
|
||||
}
|
||||
|
||||
impl Segment<2> {
|
||||
/// Convert the 2-dimensional segment to a Parry segment
|
||||
pub fn to_parry(self) -> parry2d_f64::shape::Segment {
|
||||
[self.a.to_na(), self.b.to_na()].into()
|
||||
self.points.map(|point| point.to_na()).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl Segment<3> {
|
||||
/// Convert the 3-dimensional segment to a Parry segment
|
||||
pub fn to_parry(self) -> parry3d_f64::shape::Segment {
|
||||
[self.a.to_na(), self.b.to_na()].into()
|
||||
self.points.map(|point| point.to_na()).into()
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,15 +38,12 @@ impl<const D: usize> From<[Point<D>; 2]> for Segment<D> {
|
||||
|
||||
assert!(a != b, "Invalid segment; both points are identical {a:?}");
|
||||
|
||||
Self {
|
||||
a: points[0],
|
||||
b: points[1],
|
||||
}
|
||||
Self { points }
|
||||
}
|
||||
}
|
||||
|
||||
impl<const D: usize> fmt::Debug for Segment<D> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "[{:?} -> {:?}]", self.a, self.b)
|
||||
write!(f, "[{:?} -> {:?}]", self.points[0], self.points[1])
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user