@galacean/engine-math 1.1.0-beta.3 → 1.1.0-beta.30

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.
@@ -697,8 +697,11 @@ function _create_class(Constructor, protoProps, staticProps) {
697
697
  * @param out - The center point of this bounding box
698
698
  * @returns The center point of this bounding box
699
699
  */ _proto.getCenter = function getCenter(out) {
700
- Vector3.add(this.min, this.max, out);
701
- Vector3.scale(out, 0.5, out);
700
+ var _this = this, min = _this.min, max = _this.max;
701
+ var centerX = max._x + min._x;
702
+ var centerY = max._y + min._y;
703
+ var centerZ = max._z + min._z;
704
+ out.set(isNaN(centerX) ? 0 : centerX * 0.5, isNaN(centerY) ? 0 : centerY * 0.5, isNaN(centerZ) ? 0 : centerZ * 0.5);
702
705
  return out;
703
706
  };
704
707
  /**
@@ -706,8 +709,11 @@ function _create_class(Constructor, protoProps, staticProps) {
706
709
  * @param out - The extent of this bounding box
707
710
  * @returns The extent of this bounding box
708
711
  */ _proto.getExtent = function getExtent(out) {
709
- Vector3.subtract(this.max, this.min, out);
710
- Vector3.scale(out, 0.5, out);
712
+ var _this = this, min = _this.min, max = _this.max;
713
+ var extentX = max._x - min._x;
714
+ var extentY = max._y - min._y;
715
+ var extentZ = max._z - min._z;
716
+ out.set(isNaN(extentX) ? 0 : extentX * 0.5, isNaN(extentY) ? 0 : extentY * 0.5, isNaN(extentZ) ? 0 : extentZ * 0.5);
711
717
  return out;
712
718
  };
713
719
  /**
@@ -817,9 +823,9 @@ function _create_class(Constructor, protoProps, staticProps) {
817
823
  Vector3.transformCoordinate(center, matrix, center);
818
824
  var x = extent.x, y = extent.y, z = extent.z;
819
825
  var e = matrix.elements;
820
- extent.x = Math.abs(x * e[0]) + Math.abs(y * e[4]) + Math.abs(z * e[8]);
821
- extent.y = Math.abs(x * e[1]) + Math.abs(y * e[5]) + Math.abs(z * e[9]);
822
- extent.z = Math.abs(x * e[2]) + Math.abs(y * e[6]) + Math.abs(z * e[10]);
826
+ // prettier-ignore
827
+ var e0 = e[0], e1 = e[1], e2 = e[2], e4 = e[4], e5 = e[5], e6 = e[6], e8 = e[8], e9 = e[9], e10 = e[10];
828
+ extent.set((e0 === 0 ? 0 : Math.abs(x * e0)) + (e4 === 0 ? 0 : Math.abs(y * e4)) + (e8 === 0 ? 0 : Math.abs(z * e8)), (e1 === 0 ? 0 : Math.abs(x * e1)) + (e5 === 0 ? 0 : Math.abs(y * e5)) + (e9 === 0 ? 0 : Math.abs(z * e9)), (e2 === 0 ? 0 : Math.abs(x * e2)) + (e6 === 0 ? 0 : Math.abs(y * e6)) + (e10 === 0 ? 0 : Math.abs(z * e10)));
823
829
  // set min、max
824
830
  Vector3.subtract(center, extent, out.min);
825
831
  Vector3.add(center, extent, out.max);
@@ -2234,14 +2240,27 @@ function _create_class(Constructor, protoProps, staticProps) {
2234
2240
  };
2235
2241
  };
2236
2242
  _proto._toYawPitchRoll = function _toYawPitchRoll(out) {
2237
- // https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
2243
+ // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/
2238
2244
  var _this = this, x = _this._x, y = _this._y, z = _this._z, w = _this._w;
2239
2245
  var xx = x * x;
2240
- var sinP = 2.0 * (x * w - y * z);
2241
- // use 90 degrees if out of range
2242
- out._y = Math.abs(sinP) >= 1 ? Math.sign(sinP) * (Math.PI / 2) : Math.asin(sinP);
2243
- out._x = Math.atan2(2.0 * (z * x + y * w), 1.0 - 2.0 * (y * y + xx));
2244
- out._z = Math.atan2(2.0 * (x * y + z * w), 1.0 - 2.0 * (z * z + xx));
2246
+ var yy = y * y;
2247
+ var zz = z * z;
2248
+ var ww = w * w;
2249
+ var unit = xx + yy + zz + ww;
2250
+ var test = 2 * (x * w - y * z);
2251
+ if (test > (1 - MathUtil.zeroTolerance) * unit) {
2252
+ out._x = Math.atan2(2.0 * (w * y - x * z), zz + ww - yy - zz);
2253
+ out._y = Math.PI / 2;
2254
+ out._z = 0;
2255
+ } else if (test < -(1 - MathUtil.zeroTolerance) * unit) {
2256
+ out._x = Math.atan2(2.0 * (w * y - x * z), zz + ww - yy - zz);
2257
+ out._y = -Math.PI / 2;
2258
+ out._z = 0;
2259
+ } else {
2260
+ out._x = Math.atan2(2.0 * (z * x + y * w), zz + ww - yy - xx);
2261
+ out._y = Math.asin(test / unit);
2262
+ out._z = Math.atan2(2.0 * (x * y + z * w), yy + ww - zz - xx);
2263
+ }
2245
2264
  };
2246
2265
  /**
2247
2266
  * Determines the sum of two quaternions.
@@ -2767,22 +2786,17 @@ function _create_class(Constructor, protoProps, staticProps) {
2767
2786
  var m11 = e[0];
2768
2787
  var m12 = e[1];
2769
2788
  var m13 = e[2];
2770
- var m14 = e[3];
2771
2789
  var m21 = e[4];
2772
2790
  var m22 = e[5];
2773
2791
  var m23 = e[6];
2774
- var m24 = e[7];
2775
2792
  var m31 = e[8];
2776
2793
  var m32 = e[9];
2777
2794
  var m33 = e[10];
2778
- var m34 = e[11];
2779
2795
  translation.set(e[12], e[13], e[14]);
2780
- var xs = Math.sign(m11 * m12 * m13 * m14) < 0 ? -1 : 1;
2781
- var ys = Math.sign(m21 * m22 * m23 * m24) < 0 ? -1 : 1;
2782
- var zs = Math.sign(m31 * m32 * m33 * m34) < 0 ? -1 : 1;
2783
- var sx = xs * Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13);
2784
- var sy = ys * Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23);
2785
- var sz = zs * Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33);
2796
+ var sx = Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13);
2797
+ var sy = Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23);
2798
+ var sz = Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33);
2799
+ if (this.determinant() < 0) sx = -sx;
2786
2800
  scale.set(sx, sy, sz);
2787
2801
  if (Math.abs(sx) < MathUtil.zeroTolerance || Math.abs(sy) < MathUtil.zeroTolerance || Math.abs(sz) < MathUtil.zeroTolerance) {
2788
2802
  rotation.identity();
package/dist/module.js CHANGED
@@ -693,8 +693,11 @@ function _create_class(Constructor, protoProps, staticProps) {
693
693
  * @param out - The center point of this bounding box
694
694
  * @returns The center point of this bounding box
695
695
  */ _proto.getCenter = function getCenter(out) {
696
- Vector3.add(this.min, this.max, out);
697
- Vector3.scale(out, 0.5, out);
696
+ var _this = this, min = _this.min, max = _this.max;
697
+ var centerX = max._x + min._x;
698
+ var centerY = max._y + min._y;
699
+ var centerZ = max._z + min._z;
700
+ out.set(isNaN(centerX) ? 0 : centerX * 0.5, isNaN(centerY) ? 0 : centerY * 0.5, isNaN(centerZ) ? 0 : centerZ * 0.5);
698
701
  return out;
699
702
  };
700
703
  /**
@@ -702,8 +705,11 @@ function _create_class(Constructor, protoProps, staticProps) {
702
705
  * @param out - The extent of this bounding box
703
706
  * @returns The extent of this bounding box
704
707
  */ _proto.getExtent = function getExtent(out) {
705
- Vector3.subtract(this.max, this.min, out);
706
- Vector3.scale(out, 0.5, out);
708
+ var _this = this, min = _this.min, max = _this.max;
709
+ var extentX = max._x - min._x;
710
+ var extentY = max._y - min._y;
711
+ var extentZ = max._z - min._z;
712
+ out.set(isNaN(extentX) ? 0 : extentX * 0.5, isNaN(extentY) ? 0 : extentY * 0.5, isNaN(extentZ) ? 0 : extentZ * 0.5);
707
713
  return out;
708
714
  };
709
715
  /**
@@ -813,9 +819,9 @@ function _create_class(Constructor, protoProps, staticProps) {
813
819
  Vector3.transformCoordinate(center, matrix, center);
814
820
  var x = extent.x, y = extent.y, z = extent.z;
815
821
  var e = matrix.elements;
816
- extent.x = Math.abs(x * e[0]) + Math.abs(y * e[4]) + Math.abs(z * e[8]);
817
- extent.y = Math.abs(x * e[1]) + Math.abs(y * e[5]) + Math.abs(z * e[9]);
818
- extent.z = Math.abs(x * e[2]) + Math.abs(y * e[6]) + Math.abs(z * e[10]);
822
+ // prettier-ignore
823
+ var e0 = e[0], e1 = e[1], e2 = e[2], e4 = e[4], e5 = e[5], e6 = e[6], e8 = e[8], e9 = e[9], e10 = e[10];
824
+ extent.set((e0 === 0 ? 0 : Math.abs(x * e0)) + (e4 === 0 ? 0 : Math.abs(y * e4)) + (e8 === 0 ? 0 : Math.abs(z * e8)), (e1 === 0 ? 0 : Math.abs(x * e1)) + (e5 === 0 ? 0 : Math.abs(y * e5)) + (e9 === 0 ? 0 : Math.abs(z * e9)), (e2 === 0 ? 0 : Math.abs(x * e2)) + (e6 === 0 ? 0 : Math.abs(y * e6)) + (e10 === 0 ? 0 : Math.abs(z * e10)));
819
825
  // set min、max
820
826
  Vector3.subtract(center, extent, out.min);
821
827
  Vector3.add(center, extent, out.max);
@@ -2230,14 +2236,27 @@ function _create_class(Constructor, protoProps, staticProps) {
2230
2236
  };
2231
2237
  };
2232
2238
  _proto._toYawPitchRoll = function _toYawPitchRoll(out) {
2233
- // https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
2239
+ // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/
2234
2240
  var _this = this, x = _this._x, y = _this._y, z = _this._z, w = _this._w;
2235
2241
  var xx = x * x;
2236
- var sinP = 2.0 * (x * w - y * z);
2237
- // use 90 degrees if out of range
2238
- out._y = Math.abs(sinP) >= 1 ? Math.sign(sinP) * (Math.PI / 2) : Math.asin(sinP);
2239
- out._x = Math.atan2(2.0 * (z * x + y * w), 1.0 - 2.0 * (y * y + xx));
2240
- out._z = Math.atan2(2.0 * (x * y + z * w), 1.0 - 2.0 * (z * z + xx));
2242
+ var yy = y * y;
2243
+ var zz = z * z;
2244
+ var ww = w * w;
2245
+ var unit = xx + yy + zz + ww;
2246
+ var test = 2 * (x * w - y * z);
2247
+ if (test > (1 - MathUtil.zeroTolerance) * unit) {
2248
+ out._x = Math.atan2(2.0 * (w * y - x * z), zz + ww - yy - zz);
2249
+ out._y = Math.PI / 2;
2250
+ out._z = 0;
2251
+ } else if (test < -(1 - MathUtil.zeroTolerance) * unit) {
2252
+ out._x = Math.atan2(2.0 * (w * y - x * z), zz + ww - yy - zz);
2253
+ out._y = -Math.PI / 2;
2254
+ out._z = 0;
2255
+ } else {
2256
+ out._x = Math.atan2(2.0 * (z * x + y * w), zz + ww - yy - xx);
2257
+ out._y = Math.asin(test / unit);
2258
+ out._z = Math.atan2(2.0 * (x * y + z * w), yy + ww - zz - xx);
2259
+ }
2241
2260
  };
2242
2261
  /**
2243
2262
  * Determines the sum of two quaternions.
@@ -2763,22 +2782,17 @@ function _create_class(Constructor, protoProps, staticProps) {
2763
2782
  var m11 = e[0];
2764
2783
  var m12 = e[1];
2765
2784
  var m13 = e[2];
2766
- var m14 = e[3];
2767
2785
  var m21 = e[4];
2768
2786
  var m22 = e[5];
2769
2787
  var m23 = e[6];
2770
- var m24 = e[7];
2771
2788
  var m31 = e[8];
2772
2789
  var m32 = e[9];
2773
2790
  var m33 = e[10];
2774
- var m34 = e[11];
2775
2791
  translation.set(e[12], e[13], e[14]);
2776
- var xs = Math.sign(m11 * m12 * m13 * m14) < 0 ? -1 : 1;
2777
- var ys = Math.sign(m21 * m22 * m23 * m24) < 0 ? -1 : 1;
2778
- var zs = Math.sign(m31 * m32 * m33 * m34) < 0 ? -1 : 1;
2779
- var sx = xs * Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13);
2780
- var sy = ys * Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23);
2781
- var sz = zs * Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33);
2792
+ var sx = Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13);
2793
+ var sy = Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23);
2794
+ var sz = Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33);
2795
+ if (this.determinant() < 0) sx = -sx;
2782
2796
  scale.set(sx, sy, sz);
2783
2797
  if (Math.abs(sx) < MathUtil.zeroTolerance || Math.abs(sy) < MathUtil.zeroTolerance || Math.abs(sz) < MathUtil.zeroTolerance) {
2784
2798
  rotation.identity();