Skip to content

Commit

Permalink
Add Segment::from_points
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Mar 17, 2022
1 parent 32506b5 commit c218fa4
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions fj-math/src/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ pub struct Segment<const D: usize> {
}

impl<const D: usize> Segment<D> {
/// Construct a segment from two points
///
/// # Panics
///
/// Panics, if the points are coincident.
pub fn from_points(points: [Point<D>; 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<D>; 2] {
self.points
Expand All @@ -34,11 +47,7 @@ impl Segment<3> {

impl<const D: usize> From<[Point<D>; 2]> for Segment<D> {
fn from(points: [Point<D>; 2]) -> Self {
let [a, b] = points;

assert!(a != b, "Invalid segment; both points are identical {a:?}");

Self { points }
Self::from_points(points)
}
}

Expand Down

0 comments on commit c218fa4

Please sign in to comment.