Merge pull request #461 from hannobraun/triangle

Make `Triangle::from_points` more flexible
This commit is contained in:
Hanno Braun 2022-04-12 15:07:29 +02:00 committed by GitHub
commit 19b0899621
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,7 +16,9 @@ impl<const D: usize> Triangle<D> {
/// # Panics /// # Panics
/// ///
/// Panics, if the points don't form a triangle. /// Panics, if the points don't form a triangle.
pub fn from_points(points: [Point<D>; 3]) -> Self { pub fn from_points(points: [impl Into<Point<D>>; 3]) -> Self {
let points = points.map(Into::into);
let area = { let area = {
let [a, b, c] = points.map(Point::to_xyz); let [a, b, c] = points.map(Point::to_xyz);
(b - a).cross(&(c - a)).magnitude() (b - a).cross(&(c - a)).magnitude()
@ -61,7 +63,6 @@ where
P: Into<Point<D>>, P: Into<Point<D>>,
{ {
fn from(points: [P; 3]) -> Self { fn from(points: [P; 3]) -> Self {
let points = points.map(Into::into);
Self::from_points(points) Self::from_points(points)
} }
} }