Prevent taking the square root of a negative number in the half-angle formula

This commit is contained in:
Patrick Walton 2020-03-31 13:32:00 -07:00
parent f142f045aa
commit 40377d657a
1 changed files with 2 additions and 1 deletions

View File

@ -41,6 +41,7 @@ impl UnitVector {
pub fn halve_angle(&self) -> UnitVector {
let x = self.0.x();
let term = F32x2::new(x, -x);
UnitVector(Vector2F((F32x2::splat(0.5) * (F32x2::splat(1.0) + term)).sqrt()))
UnitVector(Vector2F((F32x2::splat(0.5) * (F32x2::splat(1.0) + term)).max(F32x2::default())
.sqrt()))
}
}