@galacean/engine-math 2.0.0-alpha.47 → 2.0.0-alpha.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.js CHANGED
@@ -465,13 +465,16 @@ function _create_class(Constructor, protoProps, staticProps) {
465
465
  * Converts the vector into a unit vector.
466
466
  * @param a - The vector to normalize
467
467
  * @param out - The normalized vector
468
+ * @returns True if the vector has a unit form, otherwise false and `out` is left untouched
468
469
  */ Vector3.normalize = function normalize(a, out) {
469
470
  var _x = a._x, _y = a._y, _z = a._z;
470
471
  var len = Math.sqrt(_x * _x + _y * _y + _z * _z);
471
- if (len > MathUtil.zeroTolerance) {
472
- len = 1 / len;
473
- out.set(_x * len, _y * len, _z * len);
472
+ if (len > MathUtil.zeroTolerance && Number.isFinite(len)) {
473
+ var inv = 1 / len;
474
+ out.set(_x * inv, _y * inv, _z * inv);
475
+ return true;
474
476
  }
477
+ return false;
475
478
  };
476
479
  /**
477
480
  * Scale a vector by the given value.