servo / euclid

Geometry primitives (basic linear algebra) for Rust
Other
458 stars 102 forks source link

NaN with zero normalized vector #424

Closed ankhers closed 4 years ago

ankhers commented 4 years ago

I have a really simple program,

use euclid::Vector2D;
use euclid::UnknownUnit;

fn main() {
  let v: Vector2D<f32, UnknownUnit> = Vector2D::zero();
  let v2 = v.normalize();
  println!("V2: {}", v2);
}

The output I am receiving is

V2: (NaN,Nan)

I am seeing the same behaviour for Vector3D as well.

Is this a bug in the crate, or am I expected to check for a zero vector before normalizing?

nical commented 4 years ago

You are expected to check for zero, because there isn't a correct answer to normalizing a nil-vector.

ankhers commented 4 years ago

That is fair. Thank you!