@vived/core 1.0.0
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/README.md +29 -0
- package/babel.config.js +12 -0
- package/dist/AppObject/AppObject.d.ts +15 -0
- package/dist/AppObject/AppObject.d.ts.map +1 -0
- package/dist/AppObject/AppObject.js +54 -0
- package/dist/AppObject/AppObject.js.map +1 -0
- package/dist/AppObject/AppObject.test.d.ts +7 -0
- package/dist/AppObject/AppObject.test.d.ts.map +1 -0
- package/dist/AppObject/AppObject.test.js +110 -0
- package/dist/AppObject/AppObject.test.js.map +1 -0
- package/dist/AppObject/AppObjectComponent.d.ts +26 -0
- package/dist/AppObject/AppObjectComponent.d.ts.map +1 -0
- package/dist/AppObject/AppObjectComponent.js +78 -0
- package/dist/AppObject/AppObjectComponent.js.map +1 -0
- package/dist/AppObject/AppObjectComponent.test.d.ts +2 -0
- package/dist/AppObject/AppObjectComponent.test.d.ts.map +1 -0
- package/dist/AppObject/AppObjectComponent.test.js +130 -0
- package/dist/AppObject/AppObjectComponent.test.js.map +1 -0
- package/dist/AppObject/AppObjectController.d.ts +5 -0
- package/dist/AppObject/AppObjectController.d.ts.map +1 -0
- package/dist/AppObject/AppObjectController.js +8 -0
- package/dist/AppObject/AppObjectController.js.map +1 -0
- package/dist/AppObject/AppObjectEntity.d.ts +16 -0
- package/dist/AppObject/AppObjectEntity.d.ts.map +1 -0
- package/dist/AppObject/AppObjectEntity.js +34 -0
- package/dist/AppObject/AppObjectEntity.js.map +1 -0
- package/dist/AppObject/AppObjectEntity.test.d.ts +2 -0
- package/dist/AppObject/AppObjectEntity.test.d.ts.map +1 -0
- package/dist/AppObject/AppObjectEntity.test.js +106 -0
- package/dist/AppObject/AppObjectEntity.test.js.map +1 -0
- package/dist/AppObject/AppObjectEntityRepo.d.ts +16 -0
- package/dist/AppObject/AppObjectEntityRepo.d.ts.map +1 -0
- package/dist/AppObject/AppObjectEntityRepo.js +52 -0
- package/dist/AppObject/AppObjectEntityRepo.js.map +1 -0
- package/dist/AppObject/AppObjectEntityRepo.test.d.ts +2 -0
- package/dist/AppObject/AppObjectEntityRepo.test.d.ts.map +1 -0
- package/dist/AppObject/AppObjectEntityRepo.test.js +147 -0
- package/dist/AppObject/AppObjectEntityRepo.test.js.map +1 -0
- package/dist/AppObject/AppObjectPM.d.ts +13 -0
- package/dist/AppObject/AppObjectPM.d.ts.map +1 -0
- package/dist/AppObject/AppObjectPM.js +36 -0
- package/dist/AppObject/AppObjectPM.js.map +1 -0
- package/dist/AppObject/AppObjectPM.test.d.ts +2 -0
- package/dist/AppObject/AppObjectPM.test.d.ts.map +1 -0
- package/dist/AppObject/AppObjectPM.test.js +101 -0
- package/dist/AppObject/AppObjectPM.test.js.map +1 -0
- package/dist/AppObject/AppObjectRepo.d.ts +26 -0
- package/dist/AppObject/AppObjectRepo.d.ts.map +1 -0
- package/dist/AppObject/AppObjectRepo.js +128 -0
- package/dist/AppObject/AppObjectRepo.js.map +1 -0
- package/dist/AppObject/AppObjectRepo.test.d.ts +2 -0
- package/dist/AppObject/AppObjectRepo.test.d.ts.map +1 -0
- package/dist/AppObject/AppObjectRepo.test.js +211 -0
- package/dist/AppObject/AppObjectRepo.test.js.map +1 -0
- package/dist/AppObject/AppObjectUC.d.ts +5 -0
- package/dist/AppObject/AppObjectUC.d.ts.map +1 -0
- package/dist/AppObject/AppObjectUC.js +8 -0
- package/dist/AppObject/AppObjectUC.js.map +1 -0
- package/dist/AppObject/AppObjectView.d.ts +5 -0
- package/dist/AppObject/AppObjectView.d.ts.map +1 -0
- package/dist/AppObject/AppObjectView.js +8 -0
- package/dist/AppObject/AppObjectView.js.map +1 -0
- package/dist/AppObject/getSingletonComponent.d.ts +4 -0
- package/dist/AppObject/getSingletonComponent.d.ts.map +1 -0
- package/dist/AppObject/getSingletonComponent.js +4 -0
- package/dist/AppObject/getSingletonComponent.js.map +1 -0
- package/dist/AppObject/getSingletonComponent.test.d.ts +2 -0
- package/dist/AppObject/getSingletonComponent.test.d.ts.map +1 -0
- package/dist/AppObject/getSingletonComponent.test.js +11 -0
- package/dist/AppObject/getSingletonComponent.test.js.map +1 -0
- package/dist/AppObject/index.d.ts +11 -0
- package/dist/AppObject/index.d.ts.map +1 -0
- package/dist/AppObject/index.js +11 -0
- package/dist/AppObject/index.js.map +1 -0
- package/dist/AppObject/printAppObjectDetails.d.ts +3 -0
- package/dist/AppObject/printAppObjectDetails.d.ts.map +1 -0
- package/dist/AppObject/printAppObjectDetails.js +15 -0
- package/dist/AppObject/printAppObjectDetails.js.map +1 -0
- package/dist/Entities/MemoizedAngle.d.ts +10 -0
- package/dist/Entities/MemoizedAngle.d.ts.map +1 -0
- package/dist/Entities/MemoizedAngle.js +19 -0
- package/dist/Entities/MemoizedAngle.js.map +1 -0
- package/dist/Entities/MemoizedAngle.test.d.ts +2 -0
- package/dist/Entities/MemoizedAngle.test.d.ts.map +1 -0
- package/dist/Entities/MemoizedAngle.test.js +28 -0
- package/dist/Entities/MemoizedAngle.test.js.map +1 -0
- package/dist/Entities/MemoizedBoolean.d.ts +9 -0
- package/dist/Entities/MemoizedBoolean.d.ts.map +1 -0
- package/dist/Entities/MemoizedBoolean.js +19 -0
- package/dist/Entities/MemoizedBoolean.js.map +1 -0
- package/dist/Entities/MemoizedBoolean.test.d.ts +2 -0
- package/dist/Entities/MemoizedBoolean.test.d.ts.map +1 -0
- package/dist/Entities/MemoizedBoolean.test.js +32 -0
- package/dist/Entities/MemoizedBoolean.test.js.map +1 -0
- package/dist/Entities/MemoizedColor.d.ts +10 -0
- package/dist/Entities/MemoizedColor.d.ts.map +1 -0
- package/dist/Entities/MemoizedColor.js +20 -0
- package/dist/Entities/MemoizedColor.js.map +1 -0
- package/dist/Entities/MemoizedColor.test.d.ts +2 -0
- package/dist/Entities/MemoizedColor.test.d.ts.map +1 -0
- package/dist/Entities/MemoizedColor.test.js +30 -0
- package/dist/Entities/MemoizedColor.test.js.map +1 -0
- package/dist/Entities/MemoizedNumber.d.ts +9 -0
- package/dist/Entities/MemoizedNumber.d.ts.map +1 -0
- package/dist/Entities/MemoizedNumber.js +19 -0
- package/dist/Entities/MemoizedNumber.js.map +1 -0
- package/dist/Entities/MemoizedNumber.test.d.ts +2 -0
- package/dist/Entities/MemoizedNumber.test.d.ts.map +1 -0
- package/dist/Entities/MemoizedNumber.test.js +27 -0
- package/dist/Entities/MemoizedNumber.test.js.map +1 -0
- package/dist/Entities/MemoizedQuaternion.d.ts +10 -0
- package/dist/Entities/MemoizedQuaternion.d.ts.map +1 -0
- package/dist/Entities/MemoizedQuaternion.js +20 -0
- package/dist/Entities/MemoizedQuaternion.js.map +1 -0
- package/dist/Entities/MemoizedQuaternion.test.d.ts +2 -0
- package/dist/Entities/MemoizedQuaternion.test.d.ts.map +1 -0
- package/dist/Entities/MemoizedQuaternion.test.js +30 -0
- package/dist/Entities/MemoizedQuaternion.test.js.map +1 -0
- package/dist/Entities/MemoizedString.d.ts +9 -0
- package/dist/Entities/MemoizedString.d.ts.map +1 -0
- package/dist/Entities/MemoizedString.js +19 -0
- package/dist/Entities/MemoizedString.js.map +1 -0
- package/dist/Entities/MemoizedString.test.d.ts +2 -0
- package/dist/Entities/MemoizedString.test.d.ts.map +1 -0
- package/dist/Entities/MemoizedString.test.js +27 -0
- package/dist/Entities/MemoizedString.test.js.map +1 -0
- package/dist/Entities/MemoizedVector2.d.ts +10 -0
- package/dist/Entities/MemoizedVector2.d.ts.map +1 -0
- package/dist/Entities/MemoizedVector2.js +20 -0
- package/dist/Entities/MemoizedVector2.js.map +1 -0
- package/dist/Entities/MemoizedVector2.test.d.ts +2 -0
- package/dist/Entities/MemoizedVector2.test.d.ts.map +1 -0
- package/dist/Entities/MemoizedVector2.test.js +30 -0
- package/dist/Entities/MemoizedVector2.test.js.map +1 -0
- package/dist/Entities/MemoizedVector3.d.ts +10 -0
- package/dist/Entities/MemoizedVector3.d.ts.map +1 -0
- package/dist/Entities/MemoizedVector3.js +20 -0
- package/dist/Entities/MemoizedVector3.js.map +1 -0
- package/dist/Entities/MemoizedVector3.test.d.ts +2 -0
- package/dist/Entities/MemoizedVector3.test.d.ts.map +1 -0
- package/dist/Entities/MemoizedVector3.test.js +30 -0
- package/dist/Entities/MemoizedVector3.test.js.map +1 -0
- package/dist/Entities/ObservableEntity.d.ts +8 -0
- package/dist/Entities/ObservableEntity.d.ts.map +1 -0
- package/dist/Entities/ObservableEntity.js +16 -0
- package/dist/Entities/ObservableEntity.js.map +1 -0
- package/dist/Entities/ObservableEntity.test.d.ts +2 -0
- package/dist/Entities/ObservableEntity.test.d.ts.map +1 -0
- package/dist/Entities/ObservableEntity.test.js +23 -0
- package/dist/Entities/ObservableEntity.test.js.map +1 -0
- package/dist/Entities/ObserverList.d.ts +8 -0
- package/dist/Entities/ObserverList.d.ts.map +1 -0
- package/dist/Entities/ObserverList.js +23 -0
- package/dist/Entities/ObserverList.js.map +1 -0
- package/dist/Entities/ObserverList.test.d.ts +2 -0
- package/dist/Entities/ObserverList.test.d.ts.map +1 -0
- package/dist/Entities/ObserverList.test.js +42 -0
- package/dist/Entities/ObserverList.test.js.map +1 -0
- package/dist/Entities/index.d.ts +11 -0
- package/dist/Entities/index.d.ts.map +1 -0
- package/dist/Entities/index.js +11 -0
- package/dist/Entities/index.js.map +1 -0
- package/dist/Types/AppBoundary.d.ts +11 -0
- package/dist/Types/AppBoundary.d.ts.map +1 -0
- package/dist/Types/AppBoundary.js +2 -0
- package/dist/Types/AppBoundary.js.map +1 -0
- package/dist/Types/EaseFn.d.ts +2 -0
- package/dist/Types/EaseFn.d.ts.map +1 -0
- package/dist/Types/EaseFn.js +2 -0
- package/dist/Types/EaseFn.js.map +1 -0
- package/dist/Types/PmAdapter.d.ts +7 -0
- package/dist/Types/PmAdapter.d.ts.map +1 -0
- package/dist/Types/PmAdapter.js +2 -0
- package/dist/Types/PmAdapter.js.map +1 -0
- package/dist/Types/SingletonPmAdapter.d.ts +7 -0
- package/dist/Types/SingletonPmAdapter.d.ts.map +1 -0
- package/dist/Types/SingletonPmAdapter.js +2 -0
- package/dist/Types/SingletonPmAdapter.js.map +1 -0
- package/dist/Types/index.d.ts +5 -0
- package/dist/Types/index.d.ts.map +1 -0
- package/dist/Types/index.js +5 -0
- package/dist/Types/index.js.map +1 -0
- package/dist/ValueObjects/Angle.d.ts +27 -0
- package/dist/ValueObjects/Angle.d.ts.map +1 -0
- package/dist/ValueObjects/Angle.js +43 -0
- package/dist/ValueObjects/Angle.js.map +1 -0
- package/dist/ValueObjects/Angle.test.d.ts +2 -0
- package/dist/ValueObjects/Angle.test.d.ts.map +1 -0
- package/dist/ValueObjects/Angle.test.js +26 -0
- package/dist/ValueObjects/Angle.test.js.map +1 -0
- package/dist/ValueObjects/Color.d.ts +83 -0
- package/dist/ValueObjects/Color.d.ts.map +1 -0
- package/dist/ValueObjects/Color.js +855 -0
- package/dist/ValueObjects/Color.js.map +1 -0
- package/dist/ValueObjects/Color.test.d.ts +2 -0
- package/dist/ValueObjects/Color.test.d.ts.map +1 -0
- package/dist/ValueObjects/Color.test.js +145 -0
- package/dist/ValueObjects/Color.test.js.map +1 -0
- package/dist/ValueObjects/LineSegment2D.d.ts +12 -0
- package/dist/ValueObjects/LineSegment2D.d.ts.map +1 -0
- package/dist/ValueObjects/LineSegment2D.js +68 -0
- package/dist/ValueObjects/LineSegment2D.js.map +1 -0
- package/dist/ValueObjects/LineSegment2D.test.d.ts +2 -0
- package/dist/ValueObjects/LineSegment2D.test.d.ts.map +1 -0
- package/dist/ValueObjects/LineSegment2D.test.js +100 -0
- package/dist/ValueObjects/LineSegment2D.test.js.map +1 -0
- package/dist/ValueObjects/Matrix.d.ts +124 -0
- package/dist/ValueObjects/Matrix.d.ts.map +1 -0
- package/dist/ValueObjects/Matrix.js +462 -0
- package/dist/ValueObjects/Matrix.js.map +1 -0
- package/dist/ValueObjects/Matrix.test.d.ts +2 -0
- package/dist/ValueObjects/Matrix.test.d.ts.map +1 -0
- package/dist/ValueObjects/Matrix.test.js +383 -0
- package/dist/ValueObjects/Matrix.test.js.map +1 -0
- package/dist/ValueObjects/ParametricLine.d.ts +31 -0
- package/dist/ValueObjects/ParametricLine.d.ts.map +1 -0
- package/dist/ValueObjects/ParametricLine.js +73 -0
- package/dist/ValueObjects/ParametricLine.js.map +1 -0
- package/dist/ValueObjects/ParametricLine.test.d.ts +2 -0
- package/dist/ValueObjects/ParametricLine.test.d.ts.map +1 -0
- package/dist/ValueObjects/ParametricLine.test.js +124 -0
- package/dist/ValueObjects/ParametricLine.test.js.map +1 -0
- package/dist/ValueObjects/ParametricPlane.d.ts +21 -0
- package/dist/ValueObjects/ParametricPlane.d.ts.map +1 -0
- package/dist/ValueObjects/ParametricPlane.js +61 -0
- package/dist/ValueObjects/ParametricPlane.js.map +1 -0
- package/dist/ValueObjects/ParametricPlane.test.d.ts +2 -0
- package/dist/ValueObjects/ParametricPlane.test.d.ts.map +1 -0
- package/dist/ValueObjects/ParametricPlane.test.js +99 -0
- package/dist/ValueObjects/ParametricPlane.test.js.map +1 -0
- package/dist/ValueObjects/Quaternion.d.ts +113 -0
- package/dist/ValueObjects/Quaternion.d.ts.map +1 -0
- package/dist/ValueObjects/Quaternion.js +286 -0
- package/dist/ValueObjects/Quaternion.js.map +1 -0
- package/dist/ValueObjects/Quaternion.test.d.ts +2 -0
- package/dist/ValueObjects/Quaternion.test.d.ts.map +1 -0
- package/dist/ValueObjects/Quaternion.test.js +238 -0
- package/dist/ValueObjects/Quaternion.test.js.map +1 -0
- package/dist/ValueObjects/Rectangle.d.ts +16 -0
- package/dist/ValueObjects/Rectangle.d.ts.map +1 -0
- package/dist/ValueObjects/Rectangle.js +20 -0
- package/dist/ValueObjects/Rectangle.js.map +1 -0
- package/dist/ValueObjects/Rectangle.test.d.ts +2 -0
- package/dist/ValueObjects/Rectangle.test.d.ts.map +1 -0
- package/dist/ValueObjects/Rectangle.test.js +30 -0
- package/dist/ValueObjects/Rectangle.test.js.map +1 -0
- package/dist/ValueObjects/Vector2.d.ts +121 -0
- package/dist/ValueObjects/Vector2.d.ts.map +1 -0
- package/dist/ValueObjects/Vector2.js +180 -0
- package/dist/ValueObjects/Vector2.js.map +1 -0
- package/dist/ValueObjects/Vector2.test.d.ts +2 -0
- package/dist/ValueObjects/Vector2.test.d.ts.map +1 -0
- package/dist/ValueObjects/Vector2.test.js +134 -0
- package/dist/ValueObjects/Vector2.test.js.map +1 -0
- package/dist/ValueObjects/Vector3.d.ts +150 -0
- package/dist/ValueObjects/Vector3.d.ts.map +1 -0
- package/dist/ValueObjects/Vector3.js +227 -0
- package/dist/ValueObjects/Vector3.js.map +1 -0
- package/dist/ValueObjects/Vector3.test.d.ts +2 -0
- package/dist/ValueObjects/Vector3.test.d.ts.map +1 -0
- package/dist/ValueObjects/Vector3.test.js +186 -0
- package/dist/ValueObjects/Vector3.test.js.map +1 -0
- package/dist/ValueObjects/index.d.ts +11 -0
- package/dist/ValueObjects/index.d.ts.map +1 -0
- package/dist/ValueObjects/index.js +11 -0
- package/dist/ValueObjects/index.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/jestconfig.json +10 -0
- package/package.json +41 -0
- package/src/AppObject/AppObject.test.ts +158 -0
- package/src/AppObject/AppObject.ts +83 -0
- package/src/AppObject/AppObjectComponent.test.ts +219 -0
- package/src/AppObject/AppObjectComponent.ts +100 -0
- package/src/AppObject/AppObjectController.ts +8 -0
- package/src/AppObject/AppObjectEntity.test.ts +151 -0
- package/src/AppObject/AppObjectEntity.ts +45 -0
- package/src/AppObject/AppObjectEntityRepo.test.ts +211 -0
- package/src/AppObject/AppObjectEntityRepo.ts +61 -0
- package/src/AppObject/AppObjectPM.test.ts +152 -0
- package/src/AppObject/AppObjectPM.ts +43 -0
- package/src/AppObject/AppObjectRepo.test.ts +317 -0
- package/src/AppObject/AppObjectRepo.ts +203 -0
- package/src/AppObject/AppObjectUC.ts +5 -0
- package/src/AppObject/AppObjectView.ts +5 -0
- package/src/AppObject/getSingletonComponent.test.ts +17 -0
- package/src/AppObject/getSingletonComponent.ts +9 -0
- package/src/AppObject/index.ts +10 -0
- package/src/AppObject/printAppObjectDetails.ts +17 -0
- package/src/Entities/MemoizedAngle.test.ts +38 -0
- package/src/Entities/MemoizedAngle.ts +25 -0
- package/src/Entities/MemoizedBoolean.test.ts +45 -0
- package/src/Entities/MemoizedBoolean.ts +23 -0
- package/src/Entities/MemoizedColor.test.ts +39 -0
- package/src/Entities/MemoizedColor.ts +27 -0
- package/src/Entities/MemoizedNumber.test.ts +37 -0
- package/src/Entities/MemoizedNumber.ts +23 -0
- package/src/Entities/MemoizedQuaternion.test.ts +39 -0
- package/src/Entities/MemoizedQuaternion.ts +27 -0
- package/src/Entities/MemoizedString.test.ts +37 -0
- package/src/Entities/MemoizedString.ts +23 -0
- package/src/Entities/MemoizedVector2.test.ts +39 -0
- package/src/Entities/MemoizedVector2.ts +27 -0
- package/src/Entities/MemoizedVector3.test.ts +39 -0
- package/src/Entities/MemoizedVector3.ts +27 -0
- package/src/Entities/ObservableEntity.test.ts +28 -0
- package/src/Entities/ObservableEntity.ts +17 -0
- package/src/Entities/ObserverList.test.ts +61 -0
- package/src/Entities/ObserverList.ts +24 -0
- package/src/Entities/index.ts +10 -0
- package/src/Types/AppBoundary.ts +13 -0
- package/src/Types/EaseFn.ts +1 -0
- package/src/Types/PmAdapter.ts +15 -0
- package/src/Types/SingletonPmAdapter.ts +7 -0
- package/src/Types/index.ts +4 -0
- package/src/ValueObjects/Angle.test.ts +30 -0
- package/src/ValueObjects/Angle.ts +47 -0
- package/src/ValueObjects/Color.test.ts +181 -0
- package/src/ValueObjects/Color.ts +891 -0
- package/src/ValueObjects/LineSegment2D.test.ts +144 -0
- package/src/ValueObjects/LineSegment2D.ts +93 -0
- package/src/ValueObjects/Matrix.test.ts +498 -0
- package/src/ValueObjects/Matrix.ts +567 -0
- package/src/ValueObjects/ParametricLine.test.ts +155 -0
- package/src/ValueObjects/ParametricLine.ts +114 -0
- package/src/ValueObjects/ParametricPlane.test.ts +122 -0
- package/src/ValueObjects/ParametricPlane.ts +82 -0
- package/src/ValueObjects/Quaternion.test.ts +356 -0
- package/src/ValueObjects/Quaternion.ts +353 -0
- package/src/ValueObjects/Rectangle.test.ts +32 -0
- package/src/ValueObjects/Rectangle.ts +33 -0
- package/src/ValueObjects/Vector2.test.ts +167 -0
- package/src/ValueObjects/Vector2.ts +209 -0
- package/src/ValueObjects/Vector3.test.ts +228 -0
- package/src/ValueObjects/Vector3.ts +269 -0
- package/src/ValueObjects/index.ts +14 -0
- package/src/index.ts +4 -0
- package/tsconfig.json +18 -0
- package/tslint.json +11 -0
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { Angle } from "./Angle";
|
|
2
|
+
import { Matrix } from "./Matrix";
|
|
3
|
+
import { Vector3 } from "./Vector3";
|
|
4
|
+
|
|
5
|
+
export interface QuaternionDTO {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
z: number;
|
|
9
|
+
w: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class Quaternion {
|
|
13
|
+
/**
|
|
14
|
+
* Checks to see if two Quaternions are equal
|
|
15
|
+
* @param a Quaternion A
|
|
16
|
+
* @param b Quaternion B
|
|
17
|
+
* @returns True if they are equal, otherwise false
|
|
18
|
+
*/
|
|
19
|
+
public static Equal(a: Quaternion, b: Quaternion): boolean {
|
|
20
|
+
if (a.x === b.x && a.y === b.y && a.z === b.z && a.w === b.w) {
|
|
21
|
+
return true;
|
|
22
|
+
} else {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Checks two quaternions to see if they are close
|
|
29
|
+
* @param a Quaterion A
|
|
30
|
+
* @param b Quaterion B
|
|
31
|
+
* @param threshold "Close" threshold. Defaults to 0.001
|
|
32
|
+
* @returns True if each of Quaterion's components are within the threshold of each other
|
|
33
|
+
*/
|
|
34
|
+
public static Close(
|
|
35
|
+
a: Quaternion,
|
|
36
|
+
b: Quaternion,
|
|
37
|
+
threshold = 0.001
|
|
38
|
+
): boolean {
|
|
39
|
+
const aArray = a.toArray();
|
|
40
|
+
const bArray = b.toArray();
|
|
41
|
+
|
|
42
|
+
let areClose = true;
|
|
43
|
+
for (let i = 0; i < 4; i++) {
|
|
44
|
+
let diff = aArray[i] - bArray[i];
|
|
45
|
+
if (diff < 0) {
|
|
46
|
+
diff = -diff;
|
|
47
|
+
}
|
|
48
|
+
if (diff > threshold) {
|
|
49
|
+
areClose = false;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return areClose;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Multiplies A*B
|
|
58
|
+
* @param a Quaterion A
|
|
59
|
+
* @param b Quaternion B
|
|
60
|
+
* @returns The result of A*B
|
|
61
|
+
*/
|
|
62
|
+
public static Multiply(a: Quaternion, b: Quaternion): Quaternion {
|
|
63
|
+
const x = a.x * b.w + a.y * b.z - a.z * b.y + a.w * b.x;
|
|
64
|
+
const y = -a.x * b.z + a.y * b.w + a.z * b.x + a.w * b.y;
|
|
65
|
+
const z = a.x * b.y - a.y * b.x + a.z * b.w + a.w * b.z;
|
|
66
|
+
const w = -a.x * b.x - a.y * b.y - a.z * b.z + a.w * b.w;
|
|
67
|
+
return Quaternion.FromArray([x, y, z, w]);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Creates a new Quaterion from an array of values
|
|
72
|
+
* @param values The four values of the Quaterion: [x,y,z,w]
|
|
73
|
+
* @returns A Quaterion
|
|
74
|
+
*/
|
|
75
|
+
public static FromArray(
|
|
76
|
+
values: [number, number, number, number]
|
|
77
|
+
): Quaternion {
|
|
78
|
+
return new Quaternion(values[0], values[1], values[2], values[3]);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Creates a Quaterion from a Data Transfer Object
|
|
83
|
+
* @param dto The Data Transfer Object
|
|
84
|
+
* @returns The Quaternion
|
|
85
|
+
*/
|
|
86
|
+
public static FromDTO(dto: QuaternionDTO): Quaternion {
|
|
87
|
+
return new Quaternion(dto.x, dto.y, dto.z, dto.w);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Creates an Identity Quaternion
|
|
92
|
+
* @returns An Identity Quaternion
|
|
93
|
+
*/
|
|
94
|
+
public static Identity(): Quaternion {
|
|
95
|
+
return new Quaternion(0, 0, 0, 1);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Creates an quaterion about an axis for a given angle
|
|
100
|
+
* @param axis The rotation axis
|
|
101
|
+
* @param angle The rotation angle
|
|
102
|
+
* @returns The resulting Quaterion
|
|
103
|
+
*/
|
|
104
|
+
public static FromAngleAxis(axis: Vector3, angle: Angle): Quaternion {
|
|
105
|
+
const sin = Math.sin(angle.radians / 2);
|
|
106
|
+
const axisUnit = axis.unit;
|
|
107
|
+
const w = Math.cos(angle.radians / 2);
|
|
108
|
+
const x = axisUnit.x * sin;
|
|
109
|
+
const y = axisUnit.y * sin;
|
|
110
|
+
const z = axisUnit.z * sin;
|
|
111
|
+
return new Quaternion(x, y, z, w);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public static FromDirectionVector(direction: Vector3): Quaternion {
|
|
115
|
+
if (direction.magnitude === 0) {
|
|
116
|
+
return Quaternion.Identity();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const dirUnit = direction.unit;
|
|
120
|
+
|
|
121
|
+
if (dirUnit.x === 0 && dirUnit.z === 0) {
|
|
122
|
+
if (dirUnit.y > 0) {
|
|
123
|
+
return Quaternion.FromYawPitchRoll(
|
|
124
|
+
Angle.FromDegrees(0),
|
|
125
|
+
Angle.FromDegrees(-90),
|
|
126
|
+
Angle.FromDegrees(0)
|
|
127
|
+
);
|
|
128
|
+
} else {
|
|
129
|
+
return Quaternion.FromYawPitchRoll(
|
|
130
|
+
Angle.FromDegrees(0),
|
|
131
|
+
Angle.FromDegrees(90),
|
|
132
|
+
Angle.FromDegrees(0)
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const yawRadians = -Math.atan2(dirUnit.z, dirUnit.x) + Math.PI / 2;
|
|
138
|
+
const len = Math.sqrt(dirUnit.x * dirUnit.x + dirUnit.z * dirUnit.z);
|
|
139
|
+
const pitchRadians = -Math.atan2(dirUnit.y, len);
|
|
140
|
+
|
|
141
|
+
const yaw = Angle.FromRadians(yawRadians);
|
|
142
|
+
const pitch = Angle.FromRadians(pitchRadians);
|
|
143
|
+
const roll = Angle.FromRadians(0);
|
|
144
|
+
|
|
145
|
+
return Quaternion.FromYawPitchRoll(yaw, pitch, roll);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Froms up a Quaternion from the Yaw-Pitch-Roll (Tait-Bryan) convetion
|
|
150
|
+
* @param yaw defines the rotation around the y axis
|
|
151
|
+
* @param pitch defines the rotation around the x axis
|
|
152
|
+
* @param roll defines the rotation around the z axis
|
|
153
|
+
* @returns the resulting quaterion
|
|
154
|
+
*/
|
|
155
|
+
public static FromYawPitchRoll(
|
|
156
|
+
yaw: Angle,
|
|
157
|
+
pitch: Angle,
|
|
158
|
+
roll: Angle
|
|
159
|
+
): Quaternion {
|
|
160
|
+
const halfRoll = roll.radians * 0.5;
|
|
161
|
+
const halfPitch = pitch.radians * 0.5;
|
|
162
|
+
const halfYaw = yaw.radians * 0.5;
|
|
163
|
+
|
|
164
|
+
const sinRoll = Math.sin(halfRoll);
|
|
165
|
+
const cosRoll = Math.cos(halfRoll);
|
|
166
|
+
const sinPitch = Math.sin(halfPitch);
|
|
167
|
+
const cosPitch = Math.cos(halfPitch);
|
|
168
|
+
const sinYaw = Math.sin(halfYaw);
|
|
169
|
+
const cosYaw = Math.cos(halfYaw);
|
|
170
|
+
|
|
171
|
+
const x = cosYaw * sinPitch * cosRoll + sinYaw * cosPitch * sinRoll;
|
|
172
|
+
const y = sinYaw * cosPitch * cosRoll - cosYaw * sinPitch * sinRoll;
|
|
173
|
+
const z = cosYaw * cosPitch * sinRoll - sinYaw * sinPitch * cosRoll;
|
|
174
|
+
const w = cosYaw * cosPitch * cosRoll + sinYaw * sinPitch * sinRoll;
|
|
175
|
+
|
|
176
|
+
return new Quaternion(x, y, z, w);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Creates a Quaternion from three euler angles.
|
|
181
|
+
* @param x Rotation about the x axis
|
|
182
|
+
* @param y Rotation about the y axis
|
|
183
|
+
* @param z Rotation about the z axis
|
|
184
|
+
* @returns The Quaterion
|
|
185
|
+
*/
|
|
186
|
+
public static FromEuler(x: Angle, y: Angle, z: Angle) {
|
|
187
|
+
return this.FromYawPitchRoll(y, x, z);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Returns a new Quaternion that is an invert of A
|
|
192
|
+
* @param a The quaternion to invert
|
|
193
|
+
* @returns The inverted Quaternion
|
|
194
|
+
*/
|
|
195
|
+
public static Inverse(a: Quaternion): Quaternion {
|
|
196
|
+
return new Quaternion(-a.x, -a.y, -a.z, a.w);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
public static AngleBetween(a: Quaternion, b: Quaternion): Angle {
|
|
200
|
+
const aInv = this.Inverse(a);
|
|
201
|
+
const diffQ = this.Multiply(aInv, b);
|
|
202
|
+
|
|
203
|
+
const angDeg = diffQ.angle.degrees;
|
|
204
|
+
if(angDeg > 180) {
|
|
205
|
+
return Angle.FromDegrees(360 - angDeg)
|
|
206
|
+
} else {
|
|
207
|
+
return diffQ.angle;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Spherically interpolates between two quaternions
|
|
213
|
+
* @param initial The initial quaternion
|
|
214
|
+
* @param final The final quaterion
|
|
215
|
+
* @param percent The percent along the slerp. 0 will return the initial quaterion and 1 will return the final quaterion
|
|
216
|
+
* @returns The interpolated quaterion
|
|
217
|
+
*/
|
|
218
|
+
public static Slerp(
|
|
219
|
+
initial: Quaternion,
|
|
220
|
+
final: Quaternion,
|
|
221
|
+
percent: number
|
|
222
|
+
): Quaternion {
|
|
223
|
+
let A;
|
|
224
|
+
let B;
|
|
225
|
+
let C =
|
|
226
|
+
initial.x * final.x +
|
|
227
|
+
initial.y * final.y +
|
|
228
|
+
initial.z * final.z +
|
|
229
|
+
initial.w * final.w;
|
|
230
|
+
let flip = false;
|
|
231
|
+
|
|
232
|
+
if (C < 0) {
|
|
233
|
+
flip = true;
|
|
234
|
+
C = -C;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (C > 0.999999) {
|
|
238
|
+
B = 1 - percent;
|
|
239
|
+
A = flip ? -percent : percent;
|
|
240
|
+
} else {
|
|
241
|
+
const D = Math.acos(C);
|
|
242
|
+
const E = 1.0 / Math.sin(D);
|
|
243
|
+
B = Math.sin((1.0 - percent) * D) * E;
|
|
244
|
+
A = flip ? -Math.sin(percent * D) * E : Math.sin(percent * D) * E;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const x = B * initial.x + A * final.x;
|
|
248
|
+
const y = B * initial.y + A * final.y;
|
|
249
|
+
const z = B * initial.z + A * final.z;
|
|
250
|
+
const w = B * initial.w + A * final.w;
|
|
251
|
+
|
|
252
|
+
return new Quaternion(x, y, z, w);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Calculates a Quaternion from a rotation matrix
|
|
257
|
+
* @param rotationMatrix A normalized, non-scaled rotation matrix
|
|
258
|
+
* @returns The Quaterion
|
|
259
|
+
*/
|
|
260
|
+
public static FromRotationMatrix(rotationMatrix: Matrix): Quaternion {
|
|
261
|
+
const m = rotationMatrix.m;
|
|
262
|
+
const m11 = m[0];
|
|
263
|
+
const m12 = m[4];
|
|
264
|
+
const m13 = m[8];
|
|
265
|
+
const m21 = m[1];
|
|
266
|
+
const m22 = m[5];
|
|
267
|
+
const m23 = m[9];
|
|
268
|
+
const m31 = m[2];
|
|
269
|
+
const m32 = m[6];
|
|
270
|
+
const m33 = m[10];
|
|
271
|
+
const trace = m11 + m22 + m33;
|
|
272
|
+
let s;
|
|
273
|
+
|
|
274
|
+
let x = 0;
|
|
275
|
+
let y = 0;
|
|
276
|
+
let z = 0;
|
|
277
|
+
let w = 0;
|
|
278
|
+
if (trace > 0) {
|
|
279
|
+
s = 0.5 / Math.sqrt(trace + 1.0);
|
|
280
|
+
|
|
281
|
+
w = 0.25 / s;
|
|
282
|
+
x = (m32 - m23) * s;
|
|
283
|
+
y = (m13 - m31) * s;
|
|
284
|
+
z = (m21 - m12) * s;
|
|
285
|
+
} else if (m11 > m22 && m11 > m33) {
|
|
286
|
+
s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
|
|
287
|
+
|
|
288
|
+
w = (m32 - m23) / s;
|
|
289
|
+
x = 0.25 * s;
|
|
290
|
+
y = (m12 + m21) / s;
|
|
291
|
+
z = (m13 + m31) / s;
|
|
292
|
+
} else if (m22 > m33) {
|
|
293
|
+
s = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
|
|
294
|
+
|
|
295
|
+
w = (m13 - m31) / s;
|
|
296
|
+
x = (m12 + m21) / s;
|
|
297
|
+
y = 0.25 * s;
|
|
298
|
+
z = (m23 + m32) / s;
|
|
299
|
+
} else {
|
|
300
|
+
s = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
|
|
301
|
+
|
|
302
|
+
w = (m21 - m12) / s;
|
|
303
|
+
x = (m13 + m31) / s;
|
|
304
|
+
y = (m23 + m32) / s;
|
|
305
|
+
z = 0.25 * s;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return new Quaternion(x, y, z, w);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
public static ToRotationMatrix(quat: Quaternion): Matrix {
|
|
312
|
+
return Matrix.Compose(Vector3.One(), quat, Vector3.Zero());
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Copy the quaternion to an array
|
|
317
|
+
* @returns an array populated with 4 elements from the quaternion coordinates
|
|
318
|
+
*/
|
|
319
|
+
toArray(): [number, number, number, number] {
|
|
320
|
+
return [this.x, this.y, this.z, this.w];
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
get angle(): Angle {
|
|
324
|
+
const angle = 2 * Math.acos(this.w);
|
|
325
|
+
return Angle.FromRadians(angle);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
get axis(): Vector3 {
|
|
329
|
+
const x = this.x / Math.sqrt(1 - this.w * this.w);
|
|
330
|
+
const y = this.y / Math.sqrt(1 - this.w * this.w);
|
|
331
|
+
const z = this.z / Math.sqrt(1 - this.w * this.w);
|
|
332
|
+
return new Vector3(x, y, z);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Get the quaternion as a Data Transfer Object
|
|
337
|
+
*/
|
|
338
|
+
get dto(): QuaternionDTO {
|
|
339
|
+
return { x: this.x, y: this.y, z: this.z, w: this.w };
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
readonly x: number;
|
|
343
|
+
readonly y: number;
|
|
344
|
+
readonly z: number;
|
|
345
|
+
readonly w: number;
|
|
346
|
+
|
|
347
|
+
constructor(x: number, y: number, z: number, w: number) {
|
|
348
|
+
this.x = x;
|
|
349
|
+
this.y = y;
|
|
350
|
+
this.z = z;
|
|
351
|
+
this.w = w;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {Rectangle} from "./Rectangle";
|
|
2
|
+
|
|
3
|
+
describe("Rectangle value object", ()=>{
|
|
4
|
+
it("Creates and stores the values", ()=>{
|
|
5
|
+
const rect = new Rectangle(1,2,3,4);
|
|
6
|
+
expect(rect.top).toEqual(1);
|
|
7
|
+
expect(rect.right).toEqual(2);
|
|
8
|
+
expect(rect.bottom).toEqual(3);
|
|
9
|
+
expect(rect.left).toEqual(4);
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it("Forms a dto", ()=>{
|
|
13
|
+
const rect = new Rectangle(1,2,3,4);
|
|
14
|
+
expect(rect.dto.top).toEqual(1);
|
|
15
|
+
expect(rect.dto.right).toEqual(2);
|
|
16
|
+
expect(rect.dto.bottom).toEqual(3);
|
|
17
|
+
expect(rect.dto.left).toEqual(4);
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it("Forms a rectangle from the DTO", ()=>{
|
|
21
|
+
const rect = Rectangle.FromDTO({
|
|
22
|
+
top: 1,
|
|
23
|
+
left: 2,
|
|
24
|
+
bottom: 3,
|
|
25
|
+
right: 4
|
|
26
|
+
});
|
|
27
|
+
expect(rect.top).toEqual(1);
|
|
28
|
+
expect(rect.left).toEqual(2);
|
|
29
|
+
expect(rect.bottom).toEqual(3);
|
|
30
|
+
expect(rect.right).toEqual(4);
|
|
31
|
+
})
|
|
32
|
+
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface RectangleDTO {
|
|
2
|
+
top: number;
|
|
3
|
+
left: number;
|
|
4
|
+
right: number;
|
|
5
|
+
bottom: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class Rectangle {
|
|
9
|
+
public static FromDTO(dto: RectangleDTO):Rectangle {
|
|
10
|
+
return new Rectangle(dto.top, dto.right, dto.bottom, dto.left);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
readonly top: number;
|
|
14
|
+
readonly left: number;
|
|
15
|
+
readonly bottom: number;
|
|
16
|
+
readonly right: number;
|
|
17
|
+
|
|
18
|
+
get dto(): RectangleDTO {
|
|
19
|
+
return {
|
|
20
|
+
top: this.top,
|
|
21
|
+
bottom: this.bottom,
|
|
22
|
+
left: this.left,
|
|
23
|
+
right: this.right
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
constructor(top: number, right: number, bottom: number, left: number ) {
|
|
28
|
+
this.top = top;
|
|
29
|
+
this.bottom = bottom;
|
|
30
|
+
this.left = left;
|
|
31
|
+
this.right = right;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { Angle } from ".";
|
|
2
|
+
import { Vector2 } from "./Vector2";
|
|
3
|
+
|
|
4
|
+
describe("Vector 2 value object", () => {
|
|
5
|
+
it("Creates a new vector", () => {
|
|
6
|
+
const v = new Vector2(2, 5);
|
|
7
|
+
expect(v.x).toEqual(2);
|
|
8
|
+
expect(v.y).toEqual(5);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("Returns the magnitude", () => {
|
|
12
|
+
expect(new Vector2(0, 5).magnitued).toEqual(5);
|
|
13
|
+
expect(new Vector2(0, -5).magnitued).toEqual(5);
|
|
14
|
+
expect(new Vector2(5, 0).magnitued).toEqual(5);
|
|
15
|
+
expect(new Vector2(-5, 0).magnitued).toEqual(5);
|
|
16
|
+
expect(new Vector2(-1, -1).magnitued).toBeCloseTo(1.414);
|
|
17
|
+
expect(new Vector2(1, 1).magnitued).toBeCloseTo(1.414);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("Returns the unit", () => {
|
|
21
|
+
expect(new Vector2(0, 5).unit).toEqual(new Vector2(0, 1));
|
|
22
|
+
expect(new Vector2(0, -5).unit).toEqual(new Vector2(0, -1));
|
|
23
|
+
expect(new Vector2(5, 0).unit).toEqual(new Vector2(1, 0));
|
|
24
|
+
expect(new Vector2(-5, 0).unit).toEqual(new Vector2(-1, 0));
|
|
25
|
+
|
|
26
|
+
const unit1 = new Vector2(5, 5).unit;
|
|
27
|
+
expect(unit1.x).toBeCloseTo(0.707);
|
|
28
|
+
expect(unit1.y).toBeCloseTo(0.707);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("Retuns theta", () => {
|
|
32
|
+
expect(new Vector2(0, 5).theta).toBeCloseTo(90);
|
|
33
|
+
expect(new Vector2(0, -5).theta).toBeCloseTo(-90);
|
|
34
|
+
expect(new Vector2(5, 0).theta).toBeCloseTo(0);
|
|
35
|
+
expect(new Vector2(-5, 0).theta).toBeCloseTo(180);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("Returns the vector as an array", () => {
|
|
39
|
+
const v1 = new Vector2(1, 2);
|
|
40
|
+
|
|
41
|
+
expect(v1.array[0]).toEqual(1);
|
|
42
|
+
expect(v1.array[1]).toEqual(2);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe("Vector 2 static actions", () => {
|
|
47
|
+
it("Create a zero vector", () => {
|
|
48
|
+
expect(Vector2.Zero()).toEqual(new Vector2(0, 0));
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("Create a one vector", () => {
|
|
52
|
+
expect(Vector2.One()).toEqual(new Vector2(1, 1));
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("Check for vectors to be Equal", () => {
|
|
56
|
+
const v1 = new Vector2(1, 2);
|
|
57
|
+
const v2 = new Vector2(2, 3);
|
|
58
|
+
const v3 = new Vector2(1, 2);
|
|
59
|
+
|
|
60
|
+
expect(Vector2.Equal(v1, v2)).toEqual(false);
|
|
61
|
+
expect(Vector2.Equal(v1, v3)).toEqual(true);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("Adds vectors", () => {
|
|
65
|
+
const v1 = new Vector2(1, 2);
|
|
66
|
+
const v2 = new Vector2(2, 3);
|
|
67
|
+
const v3 = Vector2.Add(v1, v2);
|
|
68
|
+
|
|
69
|
+
expect(v3).toEqual(new Vector2(3, 5));
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("Subtracts vectors", () => {
|
|
73
|
+
const v1 = new Vector2(1, 2);
|
|
74
|
+
const v2 = new Vector2(2, 3);
|
|
75
|
+
const v3 = Vector2.Subtract(v1, v2);
|
|
76
|
+
|
|
77
|
+
expect(v3).toEqual(new Vector2(-1, -1));
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("Checks to see if vectors are close using a default threshold", () => {
|
|
81
|
+
const v1 = new Vector2(1, 2);
|
|
82
|
+
const v2 = new Vector2(1.001, 2.001);
|
|
83
|
+
const v3 = new Vector2(1.1, 2.1);
|
|
84
|
+
|
|
85
|
+
expect(Vector2.Close(v1, v2)).toEqual(true);
|
|
86
|
+
expect(Vector2.Close(v1, v3)).toEqual(false);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("Checks to see if vectors are close using a passed threshold", () => {
|
|
90
|
+
const v1 = new Vector2(1, 2);
|
|
91
|
+
const v2 = new Vector2(1.1, 2.1);
|
|
92
|
+
const v3 = new Vector2(2, 3);
|
|
93
|
+
|
|
94
|
+
expect(Vector2.Close(v1, v2, 1)).toEqual(true);
|
|
95
|
+
expect(Vector2.Close(v1, v3, 1)).toEqual(false);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("Rotates to a new vector", () => {
|
|
99
|
+
const v1 = new Vector2(1, 2);
|
|
100
|
+
|
|
101
|
+
const r1 = Vector2.Rotate(v1, Angle.FromDegrees(90));
|
|
102
|
+
expect(r1.x).toBeCloseTo(-2);
|
|
103
|
+
expect(r1.y).toBeCloseTo(1);
|
|
104
|
+
|
|
105
|
+
const r2 = Vector2.Rotate(v1, Angle.FromDegrees(-90));
|
|
106
|
+
expect(r2.x).toBeCloseTo(2);
|
|
107
|
+
expect(r2.y).toBeCloseTo(-1);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("Scales a vector", () => {
|
|
111
|
+
const v1 = new Vector2(1, 2);
|
|
112
|
+
const scaled = Vector2.Scale(v1, 3);
|
|
113
|
+
expect(scaled).toEqual(new Vector2(3, 6));
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("Make a new vector of length", () => {
|
|
117
|
+
const v1 = new Vector2(1, 1);
|
|
118
|
+
const lengthened = Vector2.NewVectorOfLength(v1, 3);
|
|
119
|
+
expect(lengthened.x).toBeCloseTo(2.12);
|
|
120
|
+
expect(lengthened.y).toBeCloseTo(2.12);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("Calculates the dot between two vectors", () => {
|
|
124
|
+
// https://onlinemschool.com/math/assistance/vector/multiply/
|
|
125
|
+
const v1 = new Vector2(1, 2);
|
|
126
|
+
const v2 = new Vector2(5, 6);
|
|
127
|
+
|
|
128
|
+
const dot = Vector2.Dot(v1, v2);
|
|
129
|
+
expect(dot).toEqual(17);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("Calculates the angle between two vectors", () => {
|
|
133
|
+
// https://www.omnicalculator.com/math/angle-between-two-vectors
|
|
134
|
+
const v1 = new Vector2(1, 2);
|
|
135
|
+
const v2 = new Vector2(3, 4);
|
|
136
|
+
|
|
137
|
+
const angle = Vector2.AngleBetween(v1, v2);
|
|
138
|
+
expect(angle.degrees).toBeCloseTo(10.305);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("Calculates a Cross product", () => {
|
|
142
|
+
const v1 = new Vector2(1, 2);
|
|
143
|
+
const v2 = new Vector2(3, 4);
|
|
144
|
+
|
|
145
|
+
const cross = Vector2.Cross(v1, v2);
|
|
146
|
+
expect(cross).toEqual(-2);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("Gets the Data Transfer Object", () => {
|
|
150
|
+
const vec = new Vector2(1, 2);
|
|
151
|
+
|
|
152
|
+
expect(vec.dto).toEqual({
|
|
153
|
+
x: 1,
|
|
154
|
+
y: 2
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("Makes a vector from a DTO", () => {
|
|
159
|
+
const vec = Vector2.FromDTO({
|
|
160
|
+
x: 1,
|
|
161
|
+
y: 2
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
expect(vec.x).toEqual(1);
|
|
165
|
+
expect(vec.y).toEqual(2);
|
|
166
|
+
});
|
|
167
|
+
});
|