ncollide3d/utils/
ccw_face_normal.rs

1use crate::math::{Point, Vector};
2use na::{RealField, Unit};
3
4/// Computes the direction pointing toward the right-hand-side of an oriented segment.
5///
6/// Returns `None` if the segment is degenerate.
7#[inline]
8#[cfg(feature = "dim2")]
9pub fn ccw_face_normal<N: RealField + Copy>(pts: [&Point<N>; 2]) -> Option<Unit<Vector<N>>> {
10    let ab = pts[1] - pts[0];
11    let res = Vector::new(ab[1], -ab[0]);
12
13    Unit::try_new(res, N::default_epsilon())
14}
15
16/// Computes the normal of a counter-clock-wise triangle.
17///
18/// Returns `None` if the triangle is degenerate.
19#[inline]
20#[cfg(feature = "dim3")]
21pub fn ccw_face_normal<N: RealField + Copy>(pts: [&Point<N>; 3]) -> Option<Unit<Vector<N>>> {
22    let ab = pts[1] - pts[0];
23    let ac = pts[2] - pts[0];
24    let res = ab.cross(&ac);
25
26    Unit::try_new(res, N::default_epsilon())
27}