mirror of
https://github.com/hannobraun/Fornjot
synced 2025-02-27 09:35:52 +00:00
Add Segment::from_points
This commit is contained in:
parent
6ee9693cdc
commit
967d0358fb
@ -12,6 +12,19 @@ pub struct Segment<const D: usize> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<const D: usize> Segment<D> {
|
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
|
/// Access the points of the segment
|
||||||
pub fn points(&self) -> [Point<D>; 2] {
|
pub fn points(&self) -> [Point<D>; 2] {
|
||||||
self.points
|
self.points
|
||||||
@ -34,11 +47,7 @@ impl Segment<3> {
|
|||||||
|
|
||||||
impl<const D: usize> From<[Point<D>; 2]> for Segment<D> {
|
impl<const D: usize> From<[Point<D>; 2]> for Segment<D> {
|
||||||
fn from(points: [Point<D>; 2]) -> Self {
|
fn from(points: [Point<D>; 2]) -> Self {
|
||||||
let [a, b] = points;
|
Self::from_points(points)
|
||||||
|
|
||||||
assert!(a != b, "Invalid segment; both points are identical {a:?}");
|
|
||||||
|
|
||||||
Self { points }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user