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