From 6ee9693cdcc3a80aad9b0862c98b81df2fe7ad6b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 17 Mar 2022 15:20:03 +0100 Subject: [PATCH] Clean up internal representation of `Segment` --- fj-math/src/segment.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/fj-math/src/segment.rs b/fj-math/src/segment.rs index 1d9f1f329..4739f3437 100644 --- a/fj-math/src/segment.rs +++ b/fj-math/src/segment.rs @@ -8,28 +8,27 @@ use super::Point; /// parameter. #[derive(Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct Segment { - a: Point, - b: Point, + points: [Point; 2], } impl Segment { /// Access the points of the segment pub fn points(&self) -> [Point; 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 From<[Point; 2]> for Segment { assert!(a != b, "Invalid segment; both points are identical {a:?}"); - Self { - a: points[0], - b: points[1], - } + Self { points } } } impl fmt::Debug for Segment { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "[{:?} -> {:?}]", self.a, self.b) + write!(f, "[{:?} -> {:?}]", self.points[0], self.points[1]) } }