diff --git a/CHANGELOG.md b/CHANGELOG.md index 808264db4..ba1ff86db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Breaking Changes +- `ex.Vector.normalize()` return zero-vector (`(0,0)`) instead of `(0,1)` when normalizing a vector with a magnitude of 0 - `ex.Gif` transparent color constructor arg is removed in favor of the built in Gif file mechanism - Remove core-js dependency, it is no longer necessary in modern browsers. Technically a breaking change for older browsers - `ex.Particle` and `ex.ParticleEmitter` now have an API that looks like modern Excalibur APIs diff --git a/src/engine/Math/vector.ts b/src/engine/Math/vector.ts index 95524904d..b7e281a96 100644 --- a/src/engine/Math/vector.ts +++ b/src/engine/Math/vector.ts @@ -227,15 +227,15 @@ export class Vector implements Clonable { } /** - * Normalizes a vector to have a magnitude of 1. + * Normalizes a non-zero vector to have a magnitude of 1. Zero vectors return a new zero vector. */ public normalize(): Vector { - const d = this.distance(); - if (d > 0) { - return new Vector(this.x / d, this.y / d); - } else { - return new Vector(0, 1); + const distance = this.distance(); + if (distance === 0) { + return Vector.Zero; } + + return new Vector(this.x / distance, this.y / distance); } /**