diff --git a/fj-math/src/segment.rs b/fj-math/src/segment.rs index 4739f3437..eb2d9e3ab 100644 --- a/fj-math/src/segment.rs +++ b/fj-math/src/segment.rs @@ -12,6 +12,19 @@ pub struct Segment { } impl Segment { + /// Construct a segment from two points + /// + /// # Panics + /// + /// Panics, if the points are coincident. + pub fn from_points(points: [Point; 2]) -> Self { + let [a, b] = points; + + assert!(a != b, "Invalid segment; both points are identical {a:?}"); + + Self { points } + } + /// Access the points of the segment pub fn points(&self) -> [Point; 2] { self.points @@ -34,11 +47,7 @@ impl Segment<3> { impl From<[Point; 2]> for Segment { fn from(points: [Point; 2]) -> Self { - let [a, b] = points; - - assert!(a != b, "Invalid segment; both points are identical {a:?}"); - - Self { points } + Self::from_points(points) } }