@predy-js/math 0.3.0-beta.26 → 0.3.0-beta.27

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/index.js CHANGED
@@ -1107,6 +1107,28 @@ function quatStar(out, quat) {
1107
1107
  out[3] = w;
1108
1108
  return out;
1109
1109
  }
1110
+ function quatFromVec3s(v1, v2) {
1111
+ const cross = [
1112
+ v1[1] * v2[2] - v1[2] * v2[1],
1113
+ v1[2] * v2[0] - v1[0] * v2[2],
1114
+ v1[0] * v2[1] - v1[1] * v2[0],
1115
+ ];
1116
+ const dot = v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];
1117
+ if (dot < -0.999999) {
1118
+ let orthogonalAxis = [1, 0, 0];
1119
+ if (Math.abs(v1[0]) > Math.abs(v1[2])) {
1120
+ orthogonalAxis = [0, 0, 1];
1121
+ }
1122
+ const orthogonalCross = [
1123
+ v1[1] * orthogonalAxis[2] - v1[2] * orthogonalAxis[1],
1124
+ v1[2] * orthogonalAxis[0] - v1[0] * orthogonalAxis[2],
1125
+ v1[0] * orthogonalAxis[1] - v1[1] * orthogonalAxis[0],
1126
+ ];
1127
+ return vecNormalize([orthogonalCross[0], orthogonalCross[1], orthogonalCross[2], 0]);
1128
+ }
1129
+ const w = Math.sqrt((Math.pow(v1[0], 2) + Math.pow(v1[1], 2) + Math.pow(v1[2], 2)) * (Math.pow(v2[0], 2) + Math.pow(v2[1], 2) + Math.pow(v2[2], 2))) + dot;
1130
+ return vecNormalize([cross[0], cross[1], cross[2], w]);
1131
+ }
1110
1132
 
1111
1133
  exports.NumberEpsilon = NumberEpsilon;
1112
1134
  exports.clamp = clamp;
@@ -1140,6 +1162,7 @@ exports.quatCreate = quatCreate;
1140
1162
  exports.quatEquals = quatEquals;
1141
1163
  exports.quatFromRotation = quatFromRotation;
1142
1164
  exports.quatFromRotationXYZ = quatFromRotationXYZ;
1165
+ exports.quatFromVec3s = quatFromVec3s;
1143
1166
  exports.quatMultiply = quatMultiply;
1144
1167
  exports.quatStar = quatStar;
1145
1168
  exports.rotateVec2 = rotateVec2;
package/dist/index.mjs CHANGED
@@ -1103,5 +1103,27 @@ function quatStar(out, quat) {
1103
1103
  out[3] = w;
1104
1104
  return out;
1105
1105
  }
1106
+ function quatFromVec3s(v1, v2) {
1107
+ const cross = [
1108
+ v1[1] * v2[2] - v1[2] * v2[1],
1109
+ v1[2] * v2[0] - v1[0] * v2[2],
1110
+ v1[0] * v2[1] - v1[1] * v2[0],
1111
+ ];
1112
+ const dot = v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];
1113
+ if (dot < -0.999999) {
1114
+ let orthogonalAxis = [1, 0, 0];
1115
+ if (Math.abs(v1[0]) > Math.abs(v1[2])) {
1116
+ orthogonalAxis = [0, 0, 1];
1117
+ }
1118
+ const orthogonalCross = [
1119
+ v1[1] * orthogonalAxis[2] - v1[2] * orthogonalAxis[1],
1120
+ v1[2] * orthogonalAxis[0] - v1[0] * orthogonalAxis[2],
1121
+ v1[0] * orthogonalAxis[1] - v1[1] * orthogonalAxis[0],
1122
+ ];
1123
+ return vecNormalize([orthogonalCross[0], orthogonalCross[1], orthogonalCross[2], 0]);
1124
+ }
1125
+ const w = Math.sqrt((Math.pow(v1[0], 2) + Math.pow(v1[1], 2) + Math.pow(v1[2], 2)) * (Math.pow(v2[0], 2) + Math.pow(v2[1], 2) + Math.pow(v2[2], 2))) + dot;
1126
+ return vecNormalize([cross[0], cross[1], cross[2], w]);
1127
+ }
1106
1128
 
1107
- export { NumberEpsilon, clamp, ensureVec3, getMat4TR, getMat4TRS, getMat4Transform, invertMat4, isZeroVec, mat3FromQuat, mat3FromRotation, mat3FromRotationZ, mat3MulMat3, mat3NormalFromMat4, mat3Rotate, mat3Scale, mat3Translate, mat3create, mat4Clone, mat4Determinate, mat4create, mat4fromRotationTranslationScale, mat4identity, mat4invert, mat4multiply, mat4perspective, mat4rotate, mat4scale, mat4translate, quatCreate, quatEquals, quatFromRotation, quatFromRotationXYZ, quatMultiply, quatStar, rotateVec2, rotationFromMat3, transposeMat3, transposeMat4, vec2AddVec2, vec2Create, vec2MulMat3, vec2MulVec2, vec2SubVec2, vec2TransformByMat3, vec3AddVec3, vec3Create, vec3Cross, vec3MulMat3, vec3MulMat4, vec3MulNum, vec3MulVec3, vec3RotateByMat4, vec3RotateByQuat, vec3TranslateByMat4, vec4Create, vecAdd, vecAddCombine, vecAssign, vecDot, vecFill, vecMinus, vecMulCombine, vecMulScalar, vecNormalize, vecSquareDistance, vecSub };
1129
+ export { NumberEpsilon, clamp, ensureVec3, getMat4TR, getMat4TRS, getMat4Transform, invertMat4, isZeroVec, mat3FromQuat, mat3FromRotation, mat3FromRotationZ, mat3MulMat3, mat3NormalFromMat4, mat3Rotate, mat3Scale, mat3Translate, mat3create, mat4Clone, mat4Determinate, mat4create, mat4fromRotationTranslationScale, mat4identity, mat4invert, mat4multiply, mat4perspective, mat4rotate, mat4scale, mat4translate, quatCreate, quatEquals, quatFromRotation, quatFromRotationXYZ, quatFromVec3s, quatMultiply, quatStar, rotateVec2, rotationFromMat3, transposeMat3, transposeMat4, vec2AddVec2, vec2Create, vec2MulMat3, vec2MulVec2, vec2SubVec2, vec2TransformByMat3, vec3AddVec3, vec3Create, vec3Cross, vec3MulMat3, vec3MulMat4, vec3MulNum, vec3MulVec3, vec3RotateByMat4, vec3RotateByQuat, vec3TranslateByMat4, vec4Create, vecAdd, vecAddCombine, vecAssign, vecDot, vecFill, vecMinus, vecMulCombine, vecMulScalar, vecNormalize, vecSquareDistance, vecSub };
package/dist/quat.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { mat3, vec4 } from '@predy-js/render-interface';
1
+ import type { mat3, vec3, vec4 } from '@predy-js/render-interface';
2
2
  export declare function quatCreate(): vec4;
3
3
  export declare function quatMultiply(out: vec4, a: vec4, b: vec4): vec4;
4
4
  export declare function mat3FromQuat(out: mat3 | number[], quat: vec4): mat3;
@@ -6,3 +6,4 @@ export declare function quatEquals(q1: vec4, q2: vec4): boolean;
6
6
  export declare function quatFromRotation(out: vec4, x: number, y: number, z: number): vec4;
7
7
  export declare function quatFromRotationXYZ(out: vec4, x: number, y: number, z: number): vec4;
8
8
  export declare function quatStar(out: vec4, quat: vec4): vec4;
9
+ export declare function quatFromVec3s(v1: vec3, v2: vec3): vec4;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@predy-js/math",
3
- "version": "0.3.0-beta.26",
3
+ "version": "0.3.0-beta.27",
4
4
  "description": "Mars JSON Specification",
5
5
  "module": "./dist/index.mjs",
6
6
  "main": "./dist/index.js",
@@ -28,7 +28,7 @@
28
28
  "prepublishOnly": "npm run build"
29
29
  },
30
30
  "devDependencies": {
31
- "@predy-js/render-interface": "0.3.0-beta.26",
31
+ "@predy-js/render-interface": "0.3.0-beta.27",
32
32
  "@commitlint/cli": "^13.2.1",
33
33
  "@commitlint/config-conventional": "^13.2.0",
34
34
  "@rollup/plugin-commonjs": "^21.0.3",