@shopware-ag/dive 1.19.1-beta.0 → 1.19.1-beta.2
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/build/dive.cjs +362 -199
- package/build/dive.cjs.map +1 -1
- package/build/dive.js +330 -167
- package/build/dive.js.map +1 -1
- package/build/dive.mjs +10803 -8714
- package/build/dive.mjs.map +1 -1
- package/build/src/converter/Converter.d.ts +3 -12
- package/build/src/dive.d.ts +1 -0
- package/build/src/exporter/Exporter.d.ts +20 -2
- package/build/src/loader/Loader.d.ts +0 -4
- package/build/src/types/error/index.d.ts +12 -0
- package/build/src/types/file/FileTypes.d.ts +17 -0
- package/build/src/types/file/index.d.ts +1 -0
- package/build/src/types/index.d.ts +5 -8
- package/package.json +2 -3
- package/build/src/types/ExporterOptions.d.ts +0 -15
- package/build/src/types/FileTypes.d.ts +0 -27
- package/src/__test__/DIVE.test.ts +0 -274
- package/src/animation/AnimationSystem.ts +0 -34
- package/src/animation/__test__/AnimationSystem.test.ts +0 -40
- package/src/ar/AR.ts +0 -101
- package/src/ar/__test__/AR.test.ts +0 -276
- package/src/ar/arquicklook/ARQuickLook.ts +0 -53
- package/src/ar/arquicklook/__test__/ARQuickLook.test.ts +0 -144
- package/src/ar/sceneviewer/SceneViewer.ts +0 -119
- package/src/ar/sceneviewer/__test__/SceneViewer.test.ts +0 -190
- package/src/ar/webxr/WebXR.ts +0 -177
- package/src/ar/webxr/controller/WebXRController.ts +0 -340
- package/src/ar/webxr/crosshair/WebXRCrosshair.ts +0 -35
- package/src/ar/webxr/origin/WebXROrigin.ts +0 -192
- package/src/ar/webxr/overlay/Overlay.ts +0 -50
- package/src/ar/webxr/raycaster/WebXRRaycaster.ts +0 -131
- package/src/ar/webxr/raycaster/ar/WebXRRaycasterAR.ts +0 -102
- package/src/ar/webxr/raycaster/three/WebXRRaycasterTHREE.ts +0 -49
- package/src/ar/webxr/touchscreencontrols/WebXRTouchscreenControls.ts +0 -356
- package/src/axiscamera/AxisCamera.ts +0 -108
- package/src/axiscamera/__test__/AxisCamera.test.ts +0 -150
- package/src/camera/PerspectiveCamera.ts +0 -63
- package/src/camera/__test__/PerspectiveCamera.test.ts +0 -36
- package/src/com/Communication.ts +0 -806
- package/src/com/__test__/Communication.test.ts +0 -1030
- package/src/com/actions/camera/computeencompassingview.ts +0 -10
- package/src/com/actions/camera/getcameratransform.ts +0 -10
- package/src/com/actions/camera/movecamera.ts +0 -18
- package/src/com/actions/camera/resetcamera.ts +0 -5
- package/src/com/actions/camera/setcameralayer.ts +0 -5
- package/src/com/actions/camera/setcameratransform.ts +0 -10
- package/src/com/actions/camera/zoomcamera.ts +0 -5
- package/src/com/actions/index.ts +0 -61
- package/src/com/actions/media/generatemedia.ts +0 -18
- package/src/com/actions/object/addobject.ts +0 -7
- package/src/com/actions/object/deleteobject.ts +0 -7
- package/src/com/actions/object/deselectobject.ts +0 -7
- package/src/com/actions/object/getallobjects.ts +0 -7
- package/src/com/actions/object/getobjects.ts +0 -7
- package/src/com/actions/object/model/dropit.ts +0 -5
- package/src/com/actions/object/model/modelloaded.ts +0 -5
- package/src/com/actions/object/model/placeonfloor.ts +0 -5
- package/src/com/actions/object/selectobject.ts +0 -7
- package/src/com/actions/object/setparent.ts +0 -10
- package/src/com/actions/object/updateobject.ts +0 -7
- package/src/com/actions/renderer/startrender.ts +0 -5
- package/src/com/actions/scene/exportscene.ts +0 -7
- package/src/com/actions/scene/getallscenedata.ts +0 -7
- package/src/com/actions/scene/launchar.ts +0 -7
- package/src/com/actions/scene/setbackground.ts +0 -5
- package/src/com/actions/scene/updatescene.ts +0 -11
- package/src/com/actions/toolbox/select/setgizmomode.ts +0 -5
- package/src/com/actions/toolbox/transform/setgizmoscalelinked.ts +0 -5
- package/src/com/actions/toolbox/transform/setgizmovisible.ts +0 -5
- package/src/com/actions/toolbox/usetool.ts +0 -7
- package/src/com/types/COMBaseEntity.ts +0 -9
- package/src/com/types/COMEntity.ts +0 -7
- package/src/com/types/COMEntityType.ts +0 -1
- package/src/com/types/COMGeometry.ts +0 -8
- package/src/com/types/COMGeometryType.ts +0 -9
- package/src/com/types/COMGroup.ts +0 -9
- package/src/com/types/COMLight.ts +0 -11
- package/src/com/types/COMMaterial.ts +0 -12
- package/src/com/types/COMModel.ts +0 -12
- package/src/com/types/COMPov.ts +0 -8
- package/src/com/types/COMPrimitive.ts +0 -12
- package/src/com/types/index.ts +0 -23
- package/src/constant/AxisHelperColors.ts +0 -7
- package/src/constant/GridColors.ts +0 -2
- package/src/constant/VisibilityLayerMask.ts +0 -5
- package/src/controls/OrbitControls.ts +0 -211
- package/src/controls/__test__/OrbitControls.test.ts +0 -256
- package/src/converter/Converter.ts +0 -117
- package/src/dive.ts +0 -363
- package/src/events/EventExecutor.ts +0 -35
- package/src/exporter/Exporter.ts +0 -75
- package/src/gizmo/Gizmo.ts +0 -144
- package/src/gizmo/handles/AxisHandle.ts +0 -153
- package/src/gizmo/handles/RadialHandle.ts +0 -149
- package/src/gizmo/handles/ScaleHandle.ts +0 -195
- package/src/gizmo/plane/GizmoPlane.ts +0 -84
- package/src/gizmo/rotate/RotateGizmo.ts +0 -143
- package/src/gizmo/scale/ScaleGizmo.ts +0 -125
- package/src/gizmo/translate/TranslateGizmo.ts +0 -114
- package/src/grid/Grid.ts +0 -34
- package/src/grid/__test__/Grid.test.ts +0 -28
- package/src/group/Group.ts +0 -184
- package/src/group/__test__/Group.test.ts +0 -212
- package/src/helper/applyMixins/__test__/applyMixins.test.ts +0 -30
- package/src/helper/applyMixins/applyMixins.ts +0 -70
- package/src/helper/findInterface/__test__/findInterface.test.ts +0 -63
- package/src/helper/findInterface/findInterface.ts +0 -13
- package/src/helper/findSceneRecursive/__test__/findSceneRecursive.test.ts +0 -40
- package/src/helper/findSceneRecursive/findSceneRecursive.ts +0 -16
- package/src/helper/getObjectDelta/__test__/getObjectDelta.test.ts +0 -186
- package/src/helper/getObjectDelta/getObjectDelta.ts +0 -105
- package/src/helper/isInterface/__test__/implementsInterface.test.ts +0 -19
- package/src/helper/isInterface/implementsInterface.ts +0 -9
- package/src/info/Info.ts +0 -178
- package/src/info/__test__/Info.test.ts +0 -346
- package/src/interface/Draggable.ts +0 -14
- package/src/interface/Hoverable.ts +0 -14
- package/src/interface/Movable.ts +0 -12
- package/src/interface/Rotatable.ts +0 -10
- package/src/interface/Scalable.ts +0 -10
- package/src/interface/Selectable.ts +0 -11
- package/src/io/IO.ts +0 -62
- package/src/io/__test__/IO.test.ts +0 -116
- package/src/io/gltf/GLTFIO.ts +0 -56
- package/src/io/gltf/__test__/GLTFIO.test.ts +0 -108
- package/src/light/AmbientLight.ts +0 -39
- package/src/light/PointLight.ts +0 -115
- package/src/light/SceneLight.ts +0 -63
- package/src/light/__test__/AmbientLight.test.ts +0 -29
- package/src/light/__test__/PointLight.test.ts +0 -74
- package/src/light/__test__/SceneLight.test.ts +0 -47
- package/src/loader/Loader.ts +0 -48
- package/src/math/__test__/DIVEMath.test.ts +0 -12
- package/src/math/ceil/__test__/ceilExp.test.ts +0 -12
- package/src/math/ceil/ceilExp.ts +0 -6
- package/src/math/degToRad/__test__/degToRad.test.ts +0 -172
- package/src/math/degToRad/degToRad.ts +0 -5
- package/src/math/floor/__test__/floorExp.test.ts +0 -14
- package/src/math/floor/floorExp.ts +0 -6
- package/src/math/helper/__test__/shift.test.ts +0 -12
- package/src/math/helper/shift.ts +0 -4
- package/src/math/index.ts +0 -28
- package/src/math/radToDeg/__test__/radToDeg.test.ts +0 -155
- package/src/math/radToDeg/radToDeg.ts +0 -5
- package/src/math/round/__test__/roundExp.test.ts +0 -14
- package/src/math/round/roundExp.ts +0 -10
- package/src/math/signedAngleTo/__test__/signedAngleTo.test.ts +0 -20
- package/src/math/signedAngleTo/signedAngleTo.ts +0 -20
- package/src/math/toFixed/__test__/toFixedExp.test.ts +0 -14
- package/src/math/toFixed/toFixedExp.ts +0 -9
- package/src/math/truncate/__test__/truncateExp.test.ts +0 -14
- package/src/math/truncate/truncateExp.ts +0 -9
- package/src/mediacreator/MediaCreator.ts +0 -75
- package/src/mediacreator/__test__/MediaCreator.test.ts +0 -155
- package/src/model/Model.ts +0 -190
- package/src/model/__test__/Model.test.ts +0 -215
- package/src/module/Module.ts +0 -45
- package/src/module/__test__/Module.test.ts +0 -54
- package/src/node/Node.ts +0 -100
- package/src/node/__test__/Node.test.ts +0 -120
- package/src/primitive/Primitive.ts +0 -299
- package/src/primitive/__test__/Primitive.test.ts +0 -281
- package/src/primitive/floor/Floor.ts +0 -45
- package/src/primitive/floor/__test__/Floor.test.ts +0 -24
- package/src/renderer/Renderer.ts +0 -215
- package/src/renderer/__test__/Renderer.test.ts +0 -228
- package/src/scene/Scene.ts +0 -106
- package/src/scene/__test__/Scene.test.ts +0 -124
- package/src/scene/root/Root.ts +0 -426
- package/src/scene/root/__test__/Root.test.ts +0 -903
- package/src/scene/xrroot/XRRoot.ts +0 -56
- package/src/scene/xrroot/xrlightroot/XRLightRoot.ts +0 -80
- package/src/toolbox/BaseTool.ts +0 -319
- package/src/toolbox/Toolbox.ts +0 -129
- package/src/toolbox/__test__/BaseTool.test.ts +0 -627
- package/src/toolbox/__test__/Toolbox.test.ts +0 -143
- package/src/toolbox/select/SelectTool.ts +0 -92
- package/src/toolbox/select/__test__/SelectTool.test.ts +0 -237
- package/src/toolbox/transform/TransformTool.ts +0 -166
- package/src/toolbox/transform/__test__/TransformTool.test.ts +0 -147
- package/src/types/ExporterOptions.ts +0 -14
- package/src/types/FileTypes.ts +0 -37
- package/src/types/SceneData.ts +0 -26
- package/src/types/SceneObjects.ts +0 -14
- package/src/types/SceneType.ts +0 -14
- package/src/types/index.ts +0 -31
- package/src/types/info/index.ts +0 -76
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import DIVEPointLight from '../PointLight.ts';
|
|
2
|
-
import { DIVECommunication } from '../../com/Communication.ts';
|
|
3
|
-
import { Color, MeshBasicMaterial, Object3D, PointLight } from 'three';
|
|
4
|
-
|
|
5
|
-
jest.mock('../../com/Communication.ts', () => {
|
|
6
|
-
return {
|
|
7
|
-
DIVECommunication: {
|
|
8
|
-
get: jest.fn(() => {
|
|
9
|
-
return {
|
|
10
|
-
PerformAction: jest.fn(),
|
|
11
|
-
};
|
|
12
|
-
}),
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe('dive/light/DIVEPointLight', () => {
|
|
18
|
-
it('should instantiate', () => {
|
|
19
|
-
const testLight = new DIVEPointLight();
|
|
20
|
-
testLight.userData.id = 'something';
|
|
21
|
-
expect(testLight).toBeDefined();
|
|
22
|
-
expect(testLight.userData.id).toBe('something');
|
|
23
|
-
expect(testLight.children).toHaveLength(2);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('should set intensity', () => {
|
|
27
|
-
const testLight = new DIVEPointLight();
|
|
28
|
-
testLight.SetIntensity(1.0);
|
|
29
|
-
expect((testLight.children[0] as PointLight).intensity).toBe(1.0);
|
|
30
|
-
testLight.SetIntensity(0.6);
|
|
31
|
-
expect((testLight.children[0] as PointLight).intensity).toBe(0.6);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should set color', () => {
|
|
35
|
-
const testLight = new DIVEPointLight();
|
|
36
|
-
testLight.SetColor({ test: true } as unknown as Color);
|
|
37
|
-
expect((testLight.children[0] as PointLight).color).toEqual({
|
|
38
|
-
test: true,
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should set enabled', () => {
|
|
43
|
-
const testLight = new DIVEPointLight();
|
|
44
|
-
testLight.SetEnabled(false);
|
|
45
|
-
expect(testLight.children[0].visible).toBe(false);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should onMove', () => {
|
|
49
|
-
const testLight = new DIVEPointLight();
|
|
50
|
-
testLight.userData.id = 'something';
|
|
51
|
-
expect(() => testLight.onMove()).not.toThrow();
|
|
52
|
-
|
|
53
|
-
jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
|
|
54
|
-
expect(() => testLight.onMove()).not.toThrow();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('should onSelect', () => {
|
|
58
|
-
const testLight = new DIVEPointLight();
|
|
59
|
-
testLight.userData.id = 'something';
|
|
60
|
-
expect(() => testLight.onSelect()).not.toThrow();
|
|
61
|
-
|
|
62
|
-
jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
|
|
63
|
-
expect(() => testLight.onSelect()).not.toThrow();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('should onDeselect', () => {
|
|
67
|
-
const testLight = new DIVEPointLight();
|
|
68
|
-
testLight.userData.id = 'something';
|
|
69
|
-
expect(() => testLight.onDeselect()).not.toThrow();
|
|
70
|
-
|
|
71
|
-
jest.spyOn(DIVECommunication, 'get').mockReturnValueOnce(undefined);
|
|
72
|
-
expect(() => testLight.onDeselect()).not.toThrow();
|
|
73
|
-
});
|
|
74
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import DIVESceneLight from '../SceneLight';
|
|
2
|
-
import { DIVECommunication } from '../../com/Communication';
|
|
3
|
-
import { Color, Object3D } from 'three';
|
|
4
|
-
|
|
5
|
-
jest.mock('../../com/Communication.ts', () => {
|
|
6
|
-
return {
|
|
7
|
-
DIVECommunication: {
|
|
8
|
-
get: jest.fn(() => {
|
|
9
|
-
return {
|
|
10
|
-
PerformAction: jest.fn(),
|
|
11
|
-
};
|
|
12
|
-
}),
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
jest.spyOn(DIVECommunication, 'get').mockReturnValue({
|
|
18
|
-
PerformAction: jest.fn(),
|
|
19
|
-
} as unknown as DIVECommunication);
|
|
20
|
-
|
|
21
|
-
describe('dive/light/DIVESceneLight', () => {
|
|
22
|
-
it('should instantiate', () => {
|
|
23
|
-
const testLight = new DIVESceneLight();
|
|
24
|
-
expect(testLight).toBeDefined();
|
|
25
|
-
expect(testLight.children).toHaveLength(2);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should set intensity', () => {
|
|
29
|
-
const testLight = new DIVESceneLight();
|
|
30
|
-
expect(() => testLight.SetIntensity(1.0)).not.toThrow();
|
|
31
|
-
expect(() => testLight.SetIntensity(0.6)).not.toThrow();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should set color', () => {
|
|
35
|
-
const testLight = new DIVESceneLight();
|
|
36
|
-
expect(() =>
|
|
37
|
-
testLight.SetColor({ test: true } as unknown as Color),
|
|
38
|
-
).not.toThrow();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should set enabled', () => {
|
|
42
|
-
const testLight = new DIVESceneLight();
|
|
43
|
-
testLight.SetEnabled(false);
|
|
44
|
-
expect(testLight.children[0].visible).toBe(false);
|
|
45
|
-
expect(testLight.children[1].visible).toBe(false);
|
|
46
|
-
});
|
|
47
|
-
});
|
package/src/loader/Loader.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
|
|
2
|
-
import { USDZLoader } from 'three/examples/jsm/loaders/USDZLoader';
|
|
3
|
-
import { Object3D } from 'three';
|
|
4
|
-
import { type FileType, SUPPORTED_FILE_TYPES } from '../types';
|
|
5
|
-
|
|
6
|
-
export class Loader {
|
|
7
|
-
private _gltfLoader: GLTFLoader;
|
|
8
|
-
private _usdzLoader: USDZLoader;
|
|
9
|
-
|
|
10
|
-
constructor() {
|
|
11
|
-
this._gltfLoader = new GLTFLoader();
|
|
12
|
-
this._usdzLoader = new USDZLoader();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public async load(uri: string): Promise<Object3D> {
|
|
16
|
-
const type = this._getFileTypeFromUri(uri);
|
|
17
|
-
return this._load(uri, type);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
private _getFileTypeFromUri(uri: string): FileType {
|
|
21
|
-
const extension = uri.split('.').pop()?.toLowerCase() as FileType;
|
|
22
|
-
if (!extension || !SUPPORTED_FILE_TYPES.includes(extension)) {
|
|
23
|
-
throw new Error(`Unsupported file type: ${extension}`);
|
|
24
|
-
}
|
|
25
|
-
return extension;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
private async _load(uri: string, type: FileType): Promise<Object3D> {
|
|
29
|
-
switch (type) {
|
|
30
|
-
case 'glb':
|
|
31
|
-
case 'gltf': {
|
|
32
|
-
return this._loadGltf(uri);
|
|
33
|
-
}
|
|
34
|
-
case 'usdz': {
|
|
35
|
-
return this._loadUsdz(uri);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
private async _loadGltf(uri: string): Promise<Object3D> {
|
|
41
|
-
const gltf = await this._gltfLoader.loadAsync(uri);
|
|
42
|
-
return gltf.scene;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
private async _loadUsdz(uri: string): Promise<Object3D> {
|
|
46
|
-
return this._usdzLoader.loadAsync(uri);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { DIVEMath } from '../index';
|
|
2
|
-
|
|
3
|
-
describe('dive/math', () => {
|
|
4
|
-
it('should be defined', () => {
|
|
5
|
-
expect(DIVEMath).toBeDefined();
|
|
6
|
-
expect(DIVEMath.ceilExp).toBeDefined();
|
|
7
|
-
expect(DIVEMath.floorExp).toBeDefined();
|
|
8
|
-
expect(DIVEMath.roundExp).toBeDefined();
|
|
9
|
-
expect(DIVEMath.toFixedExp).toBeDefined();
|
|
10
|
-
expect(DIVEMath.truncateExp).toBeDefined();
|
|
11
|
-
});
|
|
12
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import ceilExp from '../ceilExp';
|
|
2
|
-
|
|
3
|
-
describe('dive/math/ceil/ceilExp', () => {
|
|
4
|
-
it('should ceilExp', () => {
|
|
5
|
-
expect(ceilExp(-0.5)).toBe(0);
|
|
6
|
-
expect(ceilExp(0.5)).toBe(1);
|
|
7
|
-
expect(ceilExp(0.55)).toBe(1);
|
|
8
|
-
expect(ceilExp(0.49)).toBe(1);
|
|
9
|
-
expect(ceilExp(0.49, 2)).toBe(0.49);
|
|
10
|
-
expect(ceilExp(-1.49, 2)).toBe(-1.49);
|
|
11
|
-
});
|
|
12
|
-
});
|
package/src/math/ceil/ceilExp.ts
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import degToRad from '../degToRad';
|
|
2
|
-
import { MathUtils } from 'three';
|
|
3
|
-
|
|
4
|
-
// Type assertion for the mocked MathUtils.degToRad
|
|
5
|
-
const mockedDegToRad = MathUtils.degToRad as jest.Mock;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Test Suite for degToRad Function
|
|
9
|
-
*/
|
|
10
|
-
describe('degToRad', () => {
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
// Clear all previous mock calls and implementations before each test
|
|
13
|
-
mockedDegToRad.mockClear();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('should convert 0 degrees to 0 radians', () => {
|
|
17
|
-
// Arrange
|
|
18
|
-
mockedDegToRad.mockReturnValue(0);
|
|
19
|
-
|
|
20
|
-
// Act
|
|
21
|
-
const result = degToRad(0);
|
|
22
|
-
|
|
23
|
-
// Assert
|
|
24
|
-
expect(MathUtils.degToRad).toHaveBeenCalledWith(0);
|
|
25
|
-
expect(result).toBe(0);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should convert 180 degrees to π radians', () => {
|
|
29
|
-
// Arrange
|
|
30
|
-
const degrees = 180;
|
|
31
|
-
const radians = Math.PI;
|
|
32
|
-
mockedDegToRad.mockReturnValue(radians);
|
|
33
|
-
|
|
34
|
-
// Act
|
|
35
|
-
const result = degToRad(degrees);
|
|
36
|
-
|
|
37
|
-
// Assert
|
|
38
|
-
expect(MathUtils.degToRad).toHaveBeenCalledWith(degrees);
|
|
39
|
-
expect(result).toBe(radians);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should convert 360 degrees to 2π radians', () => {
|
|
43
|
-
// Arrange
|
|
44
|
-
const degrees = 360;
|
|
45
|
-
const radians = 2 * Math.PI;
|
|
46
|
-
mockedDegToRad.mockReturnValue(radians);
|
|
47
|
-
|
|
48
|
-
// Act
|
|
49
|
-
const result = degToRad(degrees);
|
|
50
|
-
|
|
51
|
-
// Assert
|
|
52
|
-
expect(MathUtils.degToRad).toHaveBeenCalledWith(degrees);
|
|
53
|
-
expect(result).toBe(radians);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should convert 90 degrees to π/2 radians', () => {
|
|
57
|
-
// Arrange
|
|
58
|
-
const degrees = 90;
|
|
59
|
-
const radians = Math.PI / 2;
|
|
60
|
-
mockedDegToRad.mockReturnValue(radians);
|
|
61
|
-
|
|
62
|
-
// Act
|
|
63
|
-
const result = degToRad(degrees);
|
|
64
|
-
|
|
65
|
-
// Assert
|
|
66
|
-
expect(MathUtils.degToRad).toHaveBeenCalledWith(degrees);
|
|
67
|
-
expect(result).toBe(radians);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('should convert 45 degrees to π/4 radians', () => {
|
|
71
|
-
// Arrange
|
|
72
|
-
const degrees = 45;
|
|
73
|
-
const radians = Math.PI / 4;
|
|
74
|
-
mockedDegToRad.mockReturnValue(radians);
|
|
75
|
-
|
|
76
|
-
// Act
|
|
77
|
-
const result = degToRad(degrees);
|
|
78
|
-
|
|
79
|
-
// Assert
|
|
80
|
-
expect(MathUtils.degToRad).toHaveBeenCalledWith(degrees);
|
|
81
|
-
expect(result).toBe(radians);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('should handle multiple calls with different degrees', () => {
|
|
85
|
-
// Arrange
|
|
86
|
-
const degrees1 = 30;
|
|
87
|
-
const radians1 = Math.PI / 6;
|
|
88
|
-
const degrees2 = 60;
|
|
89
|
-
const radians2 = Math.PI / 3;
|
|
90
|
-
const degrees3 = 120;
|
|
91
|
-
const radians3 = (2 * Math.PI) / 3;
|
|
92
|
-
|
|
93
|
-
mockedDegToRad
|
|
94
|
-
.mockReturnValueOnce(radians1)
|
|
95
|
-
.mockReturnValueOnce(radians2)
|
|
96
|
-
.mockReturnValueOnce(radians3);
|
|
97
|
-
|
|
98
|
-
// Act
|
|
99
|
-
const result1 = degToRad(degrees1);
|
|
100
|
-
const result2 = degToRad(degrees2);
|
|
101
|
-
const result3 = degToRad(degrees3);
|
|
102
|
-
|
|
103
|
-
// Assert
|
|
104
|
-
expect(MathUtils.degToRad).toHaveBeenNthCalledWith(1, degrees1);
|
|
105
|
-
expect(MathUtils.degToRad).toHaveBeenNthCalledWith(2, degrees2);
|
|
106
|
-
expect(MathUtils.degToRad).toHaveBeenNthCalledWith(3, degrees3);
|
|
107
|
-
|
|
108
|
-
expect(result1).toBe(radians1);
|
|
109
|
-
expect(result2).toBe(radians2);
|
|
110
|
-
expect(result3).toBe(radians3);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('should handle edge case of degrees just below 360', () => {
|
|
114
|
-
// Arrange
|
|
115
|
-
const degrees = 359.999;
|
|
116
|
-
const radians = MathUtils.degToRad(degrees);
|
|
117
|
-
mockedDegToRad.mockReturnValue(radians);
|
|
118
|
-
|
|
119
|
-
// Act
|
|
120
|
-
const result = degToRad(degrees);
|
|
121
|
-
|
|
122
|
-
// Assert
|
|
123
|
-
expect(MathUtils.degToRad).toHaveBeenCalledWith(degrees);
|
|
124
|
-
expect(result).toBe(radians);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('should not allow negative degrees', () => {
|
|
128
|
-
// Arrange
|
|
129
|
-
const degrees = -45;
|
|
130
|
-
const radians = MathUtils.degToRad(degrees);
|
|
131
|
-
mockedDegToRad.mockReturnValue(radians);
|
|
132
|
-
|
|
133
|
-
// Act
|
|
134
|
-
const result = degToRad(degrees);
|
|
135
|
-
|
|
136
|
-
// Assert
|
|
137
|
-
expect(MathUtils.degToRad).toHaveBeenCalledWith(degrees);
|
|
138
|
-
expect(result).toBe(radians);
|
|
139
|
-
// Depending on implementation, you might want to expect an error
|
|
140
|
-
// or handle negative degrees differently. Adjust assertions accordingly.
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('should handle undefined degrees gracefully', () => {
|
|
144
|
-
// Arrange
|
|
145
|
-
const degrees = undefined;
|
|
146
|
-
// Since the function expects a number, this might throw an error or pass undefined
|
|
147
|
-
mockedDegToRad.mockReturnValue(NaN);
|
|
148
|
-
|
|
149
|
-
// Act
|
|
150
|
-
// @ts-ignore: Testing undefined input
|
|
151
|
-
const result = degToRad(degrees);
|
|
152
|
-
|
|
153
|
-
// Assert
|
|
154
|
-
expect(MathUtils.degToRad).toHaveBeenCalledWith(degrees);
|
|
155
|
-
expect(result).toBe(NaN);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('should handle null degrees gracefully', () => {
|
|
159
|
-
// Arrange
|
|
160
|
-
const degrees = null;
|
|
161
|
-
// Depending on implementation, this might throw an error or pass null
|
|
162
|
-
mockedDegToRad.mockReturnValue(NaN);
|
|
163
|
-
|
|
164
|
-
// Act
|
|
165
|
-
// @ts-ignore: Testing null input
|
|
166
|
-
const result = degToRad(degrees);
|
|
167
|
-
|
|
168
|
-
// Assert
|
|
169
|
-
expect(MathUtils.degToRad).toHaveBeenCalledWith(degrees);
|
|
170
|
-
expect(result).toBe(NaN);
|
|
171
|
-
});
|
|
172
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import floorExp from '../floorExp';
|
|
2
|
-
|
|
3
|
-
describe('dive/math/floor/floorExp', () => {
|
|
4
|
-
it('should floorExp', () => {
|
|
5
|
-
expect(floorExp(-0.5)).toBe(-1);
|
|
6
|
-
expect(floorExp(0.5)).toBe(0);
|
|
7
|
-
expect(floorExp(0.55)).toBe(0);
|
|
8
|
-
expect(floorExp(0.49)).toBe(0);
|
|
9
|
-
expect(floorExp(1.49)).toBe(1);
|
|
10
|
-
expect(floorExp(0.49, 2)).toBe(0.49);
|
|
11
|
-
expect(floorExp(1.49, 2)).toBe(1.49);
|
|
12
|
-
expect(floorExp(-1.49, 2)).toBe(-1.49);
|
|
13
|
-
});
|
|
14
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import shift from '../shift';
|
|
2
|
-
|
|
3
|
-
describe('dive/math/helper/shift', () => {
|
|
4
|
-
it('should shift', () => {
|
|
5
|
-
expect(shift(0.5, 2)).toBe(50);
|
|
6
|
-
expect(shift(0.55, 2)).toBe(55);
|
|
7
|
-
expect(shift(0.49, 2)).toBe(49);
|
|
8
|
-
expect(shift(1.49, 2)).toBe(149);
|
|
9
|
-
expect(shift(0.49, 2)).toBe(49);
|
|
10
|
-
expect(shift(1.49, 2)).toBe(149);
|
|
11
|
-
});
|
|
12
|
-
});
|
package/src/math/helper/shift.ts
DELETED
package/src/math/index.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import ceilExp from './ceil/ceilExp.ts';
|
|
2
|
-
import floorExp from './floor/floorExp.ts';
|
|
3
|
-
import roundExp from './round/roundExp.ts';
|
|
4
|
-
import signedAngleTo from './signedAngleTo/signedAngleTo.ts';
|
|
5
|
-
import toFixedExp from './toFixed/toFixedExp.ts';
|
|
6
|
-
import truncateExp from './truncate/truncateExp.ts';
|
|
7
|
-
import radToDeg from './radToDeg/radToDeg.ts';
|
|
8
|
-
import degToRad from './degToRad/degToRad.ts';
|
|
9
|
-
|
|
10
|
-
export const DIVEMath: {
|
|
11
|
-
ceilExp: typeof ceilExp;
|
|
12
|
-
floorExp: typeof floorExp;
|
|
13
|
-
roundExp: typeof roundExp;
|
|
14
|
-
toFixedExp: typeof toFixedExp;
|
|
15
|
-
truncateExp: typeof truncateExp;
|
|
16
|
-
signedAngleTo: typeof signedAngleTo;
|
|
17
|
-
radToDeg: typeof radToDeg;
|
|
18
|
-
degToRad: typeof degToRad;
|
|
19
|
-
} = {
|
|
20
|
-
ceilExp,
|
|
21
|
-
floorExp,
|
|
22
|
-
roundExp,
|
|
23
|
-
toFixedExp,
|
|
24
|
-
truncateExp,
|
|
25
|
-
signedAngleTo,
|
|
26
|
-
radToDeg,
|
|
27
|
-
degToRad,
|
|
28
|
-
};
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import radToDeg from '../radToDeg';
|
|
2
|
-
import { MathUtils } from 'three';
|
|
3
|
-
|
|
4
|
-
// Type assertion for the mocked MathUtils.radToDeg
|
|
5
|
-
const mockedRadToDeg = MathUtils.radToDeg as jest.Mock;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Test Suite for radToDeg Function
|
|
9
|
-
*/
|
|
10
|
-
describe('radToDeg', () => {
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
// Clear all previous mock calls and implementations before each test
|
|
13
|
-
mockedRadToDeg.mockClear();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('should convert 0 radians to 0 degrees', () => {
|
|
17
|
-
// Arrange
|
|
18
|
-
mockedRadToDeg.mockReturnValue(0);
|
|
19
|
-
|
|
20
|
-
// Act
|
|
21
|
-
const result = radToDeg(0);
|
|
22
|
-
|
|
23
|
-
// Assert
|
|
24
|
-
expect(MathUtils.radToDeg).toHaveBeenCalledWith(0);
|
|
25
|
-
expect(result).toBe(0);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should convert π radians to 180 degrees', () => {
|
|
29
|
-
// Arrange
|
|
30
|
-
const pi = Math.PI;
|
|
31
|
-
mockedRadToDeg.mockReturnValue(180);
|
|
32
|
-
|
|
33
|
-
// Act
|
|
34
|
-
const result = radToDeg(pi);
|
|
35
|
-
|
|
36
|
-
// Assert
|
|
37
|
-
expect(MathUtils.radToDeg).toHaveBeenCalledWith(pi);
|
|
38
|
-
expect(result).toBe(180);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should convert 2π radians to 0 degrees (wrapped)', () => {
|
|
42
|
-
// Arrange
|
|
43
|
-
const twoPi = 2 * Math.PI;
|
|
44
|
-
mockedRadToDeg.mockReturnValue(360);
|
|
45
|
-
|
|
46
|
-
// Act
|
|
47
|
-
const result = radToDeg(twoPi);
|
|
48
|
-
|
|
49
|
-
// Assert
|
|
50
|
-
expect(MathUtils.radToDeg).toHaveBeenCalledWith(twoPi);
|
|
51
|
-
expect(result).toBe(0);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should convert 3π/2 radians to 270 degrees', () => {
|
|
55
|
-
// Arrange
|
|
56
|
-
const threePiOver2 = (3 * Math.PI) / 2;
|
|
57
|
-
mockedRadToDeg.mockReturnValue(270);
|
|
58
|
-
|
|
59
|
-
// Act
|
|
60
|
-
const result = radToDeg(threePiOver2);
|
|
61
|
-
|
|
62
|
-
// Assert
|
|
63
|
-
expect(MathUtils.radToDeg).toHaveBeenCalledWith(threePiOver2);
|
|
64
|
-
expect(result).toBe(270);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('should handle angles greater than 2π radians correctly', () => {
|
|
68
|
-
// Arrange
|
|
69
|
-
const sevenPi = 7 * Math.PI; // 1260 degrees
|
|
70
|
-
const expectedDegrees = (1260 + 360) % 360; // 180 degrees
|
|
71
|
-
mockedRadToDeg.mockReturnValue(1260);
|
|
72
|
-
|
|
73
|
-
// Act
|
|
74
|
-
const result = radToDeg(sevenPi);
|
|
75
|
-
|
|
76
|
-
// Assert
|
|
77
|
-
expect(MathUtils.radToDeg).toHaveBeenCalledWith(sevenPi);
|
|
78
|
-
expect(result).toBe(expectedDegrees);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should handle fractional radians correctly', () => {
|
|
82
|
-
// Arrange
|
|
83
|
-
const fractionalRadians = Math.PI / 4; // 45 degrees
|
|
84
|
-
mockedRadToDeg.mockReturnValue(45);
|
|
85
|
-
|
|
86
|
-
// Act
|
|
87
|
-
const result = radToDeg(fractionalRadians);
|
|
88
|
-
|
|
89
|
-
// Assert
|
|
90
|
-
expect(MathUtils.radToDeg).toHaveBeenCalledWith(fractionalRadians);
|
|
91
|
-
expect(result).toBe(45);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('should wrap negative angles correctly', () => {
|
|
95
|
-
// Since the function does not handle negative inputs, this test ensures it behaves as expected
|
|
96
|
-
// However, based on initial requirements, negative degrees are not allowed and inputs are non-negative
|
|
97
|
-
// This test is optional and based on how you want the function to behave
|
|
98
|
-
const negativeRadians = -Math.PI / 2; // -90 degrees
|
|
99
|
-
mockedRadToDeg.mockReturnValue(-90);
|
|
100
|
-
const expectedDegrees = (-90 + 360) % 360; // 270 degrees
|
|
101
|
-
|
|
102
|
-
const result = radToDeg(negativeRadians);
|
|
103
|
-
|
|
104
|
-
expect(MathUtils.radToDeg).toHaveBeenCalledWith(negativeRadians);
|
|
105
|
-
expect(result).toBe(expectedDegrees);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('should handle multiple full rotations correctly', () => {
|
|
109
|
-
// Arrange
|
|
110
|
-
const multipleRotations = 5 * 2 * Math.PI; // 360 * 5 = 1800 degrees
|
|
111
|
-
const expectedDegrees = (1800 + 360) % 360; // 0 degrees
|
|
112
|
-
mockedRadToDeg.mockReturnValue(1800);
|
|
113
|
-
|
|
114
|
-
// Act
|
|
115
|
-
const result = radToDeg(multipleRotations);
|
|
116
|
-
|
|
117
|
-
// Assert
|
|
118
|
-
expect(MathUtils.radToDeg).toHaveBeenCalledWith(multipleRotations);
|
|
119
|
-
expect(result).toBe(0);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('should handle mixed angles', () => {
|
|
123
|
-
// Arrange
|
|
124
|
-
const angles = [
|
|
125
|
-
Math.PI / 6,
|
|
126
|
-
Math.PI,
|
|
127
|
-
(5 * Math.PI) / 3,
|
|
128
|
-
];
|
|
129
|
-
const mockReturns = [
|
|
130
|
-
30,
|
|
131
|
-
180,
|
|
132
|
-
300,
|
|
133
|
-
];
|
|
134
|
-
const expectedDegrees = [
|
|
135
|
-
(30 + 360) % 360,
|
|
136
|
-
(180 + 360) % 360,
|
|
137
|
-
(300 + 360) % 360,
|
|
138
|
-
]; // [30, 180, 300]
|
|
139
|
-
|
|
140
|
-
mockedRadToDeg
|
|
141
|
-
.mockReturnValueOnce(mockReturns[0])
|
|
142
|
-
.mockReturnValueOnce(mockReturns[1])
|
|
143
|
-
.mockReturnValueOnce(mockReturns[2]);
|
|
144
|
-
|
|
145
|
-
// Act & Assert for each angle
|
|
146
|
-
angles.forEach((angle, index) => {
|
|
147
|
-
const result = radToDeg(angle);
|
|
148
|
-
expect(MathUtils.radToDeg).toHaveBeenNthCalledWith(
|
|
149
|
-
index + 1,
|
|
150
|
-
angle,
|
|
151
|
-
);
|
|
152
|
-
expect(result).toBe(expectedDegrees[index]);
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import roundExp from '../roundExp';
|
|
2
|
-
|
|
3
|
-
describe('dive/math/round/roundExp', () => {
|
|
4
|
-
it('should roundExp', () => {
|
|
5
|
-
expect(roundExp(-0.5)).toBe(-1);
|
|
6
|
-
expect(roundExp(0.5)).toBe(1);
|
|
7
|
-
expect(roundExp(0.55)).toBe(1);
|
|
8
|
-
expect(roundExp(0.49)).toBe(0);
|
|
9
|
-
expect(roundExp(1.49)).toBe(1);
|
|
10
|
-
expect(roundExp(0.49, 2)).toBe(0.49);
|
|
11
|
-
expect(roundExp(1.49, 2)).toBe(1.49);
|
|
12
|
-
expect(roundExp(-1.49, 2)).toBe(-1.49);
|
|
13
|
-
});
|
|
14
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import shift from '../helper/shift.ts';
|
|
2
|
-
|
|
3
|
-
export default function roundExponential(
|
|
4
|
-
number: number,
|
|
5
|
-
decimals: number = 0,
|
|
6
|
-
): number {
|
|
7
|
-
if (number < 0) return -roundExponential(-number, decimals);
|
|
8
|
-
const n = shift(number, +decimals);
|
|
9
|
-
return shift(Math.round(n), -decimals);
|
|
10
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Vector3 } from 'three';
|
|
2
|
-
import signedAngleTo from '../signedAngleTo';
|
|
3
|
-
|
|
4
|
-
describe('dive/math/signedAngleTo', () => {
|
|
5
|
-
it('should signedAngleTo', () => {
|
|
6
|
-
const planeNormal = new Vector3(0, 0, 1);
|
|
7
|
-
const a = new Vector3(1, 0, 0);
|
|
8
|
-
expect(signedAngleTo(a, new Vector3(1, 0, 0), planeNormal)).toBe(0);
|
|
9
|
-
expect(signedAngleTo(a, new Vector3(0, 1, 0), planeNormal)).toBe(
|
|
10
|
-
Math.PI / 2,
|
|
11
|
-
);
|
|
12
|
-
expect(signedAngleTo(a, new Vector3(-1, 0, 0), planeNormal)).toBe(
|
|
13
|
-
Math.PI,
|
|
14
|
-
);
|
|
15
|
-
expect(signedAngleTo(a, new Vector3(0, -1, 0), planeNormal)).toBe(
|
|
16
|
-
-Math.PI / 2,
|
|
17
|
-
);
|
|
18
|
-
expect(signedAngleTo(a, planeNormal, planeNormal)).toBe(0);
|
|
19
|
-
});
|
|
20
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Vector3 } from 'three';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Calculate the signed angle between two vectors. Only works when the vectors are on the same plane.
|
|
5
|
-
* @param vecB Start Vector
|
|
6
|
-
* @param vecA Target Vector
|
|
7
|
-
* @param planeNormal The vector's plane normal
|
|
8
|
-
* @returns Signed angle in radians
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export default function signedAngleTo(
|
|
12
|
-
vecA: Vector3,
|
|
13
|
-
vecB: Vector3,
|
|
14
|
-
planeNormal: Vector3,
|
|
15
|
-
): number {
|
|
16
|
-
return Math.atan2(
|
|
17
|
-
vecA.clone().cross(vecB).dot(planeNormal),
|
|
18
|
-
vecB.clone().dot(vecA),
|
|
19
|
-
);
|
|
20
|
-
}
|