use na::{self, Scalar, Real, U3, DefaultAllocator}; use traits::{Number, Alloc, Dimension}; use aliases::Vec; pub fn cross(x: &Vec, y: &Vec) -> Vec { x.cross(y) } pub fn distance(p0: &Vec, p1: &Vec) -> N where DefaultAllocator: Alloc { (p1 - p0).norm() } pub fn dot(x: &Vec, y: &Vec) -> N where DefaultAllocator: Alloc { x.dot(y) } pub fn faceforward(n: &Vec, i: &Vec, nref: &Vec) -> Vec where DefaultAllocator: Alloc { if nref.dot(i) < N::zero() { n.clone() } else { -n.clone() } } pub fn length(x: &Vec) -> N where DefaultAllocator: Alloc { x.norm() } pub fn normalize(x: &Vec) -> Vec where DefaultAllocator: Alloc { x.normalize() } pub fn reflect(i: &Vec, n: &Vec) -> Vec where DefaultAllocator: Alloc { let _2 = N::one() + N::one(); i - n * (n.dot(i) * _2) } pub fn refract(i: &Vec, n: &Vec, eta: N) -> Vec where DefaultAllocator: Alloc { let ni = n.dot(i); let k = N::one() - eta * eta * (N::one() - ni * ni); if k < N::zero() { Vec::<_, D>::zeros() } else { i * eta - n * (eta * dot(n, i) + k.sqrt()) } }