fluidcad 0.0.3 → 0.0.4
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 +2 -2
- package/lib/dist/common/shape-factory.d.ts +1 -1
- package/lib/dist/oc/boolean-ops.d.ts +2 -2
- package/lib/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/lib/dist/constraints/constraint.d.ts +0 -11
- package/lib/dist/constraints/constraint.js +0 -51
- package/lib/dist/constraints/outside.d.ts +0 -3
- package/lib/dist/constraints/outside.js +0 -4
- package/lib/dist/core/2d/aslot.d.ts +0 -12
- package/lib/dist/core/2d/aslot.js +0 -40
- package/lib/dist/core/2d/crect.d.ts +0 -12
- package/lib/dist/core/2d/crect.js +0 -74
- package/lib/dist/core/2d/face-maker.d.ts +0 -13
- package/lib/dist/core/2d/face-maker.js +0 -119
- package/lib/dist/core/2d/face-maker2.d.ts +0 -6
- package/lib/dist/core/2d/face-maker2.js +0 -54
- package/lib/dist/core/region.d.ts +0 -13
- package/lib/dist/core/region.js +0 -18
- package/lib/dist/features/2d/amove.d.ts +0 -14
- package/lib/dist/features/2d/amove.js +0 -33
- package/lib/dist/features/2d/constraints/constraint.d.ts +0 -11
- package/lib/dist/features/2d/constraints/constraint.js +0 -49
- package/lib/dist/features/2d/constraints/outside.d.ts +0 -3
- package/lib/dist/features/2d/constraints/outside.js +0 -4
- package/lib/dist/features/2d/tarc-two-circles.d.ts +0 -18
- package/lib/dist/features/2d/tarc-two-circles.js +0 -61
- package/lib/dist/features/2d/tcircle-three-tan.d.ts +0 -13
- package/lib/dist/features/2d/tcircle-three-tan.js +0 -33
- package/lib/dist/features/2d/tcircle-two-tan.d.ts +0 -13
- package/lib/dist/features/2d/tcircle-two-tan.js +0 -33
- package/lib/dist/features/Extrude.d.ts +0 -1
- package/lib/dist/features/Extrude.js +0 -1
- package/lib/dist/features/cut-base.d.ts +0 -49
- package/lib/dist/features/cut-base.js +0 -312
- package/lib/dist/features/cut-symmetric.d.ts +0 -23
- package/lib/dist/features/cut-symmetric.js +0 -119
- package/lib/dist/features/cut-two-distances.d.ts +0 -24
- package/lib/dist/features/cut-two-distances.js +0 -110
- package/lib/dist/features/cut.d.ts +0 -27
- package/lib/dist/features/cut.js +0 -101
- package/lib/dist/features/extrude-symmetric.d.ts +0 -28
- package/lib/dist/features/extrude-symmetric.js +0 -177
- package/lib/dist/features/region2d.d.ts +0 -25
- package/lib/dist/features/region2d.js +0 -185
- package/lib/dist/features/repeat-circular2d.d.ts +0 -17
- package/lib/dist/features/repeat-circular2d.js +0 -90
- package/lib/dist/features/repeat-linear2d.d.ts +0 -17
- package/lib/dist/features/repeat-linear2d.js +0 -114
- package/lib/dist/features/revolve-options.d.ts +0 -6
- package/lib/dist/features/revolve-options.js +0 -1
- package/lib/dist/features/split.d.ts +0 -14
- package/lib/dist/features/split.js +0 -74
- package/lib/dist/features/state-scene-object.d.ts +0 -15
- package/lib/dist/features/state-scene-object.js +0 -44
- package/lib/dist/features/state-select.d.ts +0 -21
- package/lib/dist/features/state-select.js +0 -73
- package/lib/dist/features/translate2d.d.ts +0 -16
- package/lib/dist/features/translate2d.js +0 -61
- package/lib/dist/filters/all-filter.d.ts +0 -8
- package/lib/dist/filters/all-filter.js +0 -12
- package/lib/dist/filters/near-point-filter.d.ts +0 -11
- package/lib/dist/filters/near-point-filter.js +0 -33
- package/lib/dist/helpers/resolve-filters.d.ts +0 -6
- package/lib/dist/helpers/resolve-filters.js +0 -25
- package/lib/dist/math/axis.test.d.ts +0 -1
- package/lib/dist/math/axis.test.js +0 -287
- package/lib/dist/math/coordinate-system.test.d.ts +0 -1
- package/lib/dist/math/coordinate-system.test.js +0 -308
- package/lib/dist/math/matrix4.test.d.ts +0 -1
- package/lib/dist/math/matrix4.test.js +0 -357
- package/lib/dist/math/plane.test.d.ts +0 -1
- package/lib/dist/math/plane.test.js +0 -398
- package/lib/dist/math/point.test.d.ts +0 -1
- package/lib/dist/math/point.test.js +0 -385
- package/lib/dist/math/quaternion.test.d.ts +0 -1
- package/lib/dist/math/quaternion.test.js +0 -278
- package/lib/dist/math/vector3d.test.d.ts +0 -1
- package/lib/dist/math/vector3d.test.js +0 -276
- package/lib/dist/oc/constraint-resolver.d.ts +0 -7
- package/lib/dist/oc/constraint-resolver.js +0 -31
- package/lib/dist/oc/constraints/curve-constraint-solver.d.ts +0 -1
- package/lib/dist/oc/constraints/curve-constraint-solver.js +0 -2
- package/lib/dist/oc/constraints/geometric-constraint-solver.d.ts +0 -1
- package/lib/dist/oc/constraints/geometric-constraint-solver.js +0 -5
- package/lib/dist/oc/face-maker.d.ts +0 -14
- package/lib/dist/oc/face-maker.js +0 -191
- package/lib/dist/oc/measure.d.ts +0 -21
- package/lib/dist/oc/measure.js +0 -256
- package/lib/dist/oc/tangent-circle-solver.d.ts +0 -17
- package/lib/dist/oc/tangent-circle-solver.js +0 -72
- package/lib/dist/oc/tangent-line-solver.d.ts +0 -17
- package/lib/dist/oc/tangent-line-solver.js +0 -83
- package/lib/dist/oc/tangent-solver.d.ts +0 -14
- package/lib/dist/oc/tangent-solver.js +0 -199
- package/lib/dist/rendering/builder-context.d.ts +0 -16
- package/lib/dist/rendering/builder-context.js +0 -63
- package/lib/dist/tests/extrude.test.d.ts +0 -1
- package/lib/dist/tests/extrude.test.js +0 -48
- package/lib/dist/tests/features/copy.test.d.ts +0 -1
- package/lib/dist/tests/features/copy.test.js +0 -158
- package/lib/dist/tests/features/dispose.test.d.ts +0 -1
- package/lib/dist/tests/features/dispose.test.js +0 -189
- package/lib/dist/tests/features/part-pick.test.d.ts +0 -1
- package/lib/dist/tests/features/part-pick.test.js +0 -73
- package/lib/dist/tests/features/part-repeat.test.d.ts +0 -1
- package/lib/dist/tests/features/part-repeat.test.js +0 -109
- package/server/dist/fluidcad-server.d.ts +0 -32
- package/server/dist/fluidcad-server.js +0 -150
- package/server/dist/index.d.ts +0 -1
- package/server/dist/index.js +0 -290
- package/server/dist/routes/actions.d.ts +0 -3
- package/server/dist/routes/actions.js +0 -100
- package/server/dist/routes/export.d.ts +0 -3
- package/server/dist/routes/export.js +0 -55
- package/server/dist/routes/properties.d.ts +0 -3
- package/server/dist/routes/properties.js +0 -46
- package/server/dist/routes/screenshot.d.ts +0 -2
- package/server/dist/routes/screenshot.js +0 -76
- package/server/dist/vite-manager.d.ts +0 -10
- package/server/dist/vite-manager.js +0 -64
- package/server/dist/ws-protocol.d.ts +0 -138
- package/server/dist/ws-protocol.js +0 -4
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { Matrix4 } from "./matrix4.js";
|
|
3
|
-
import { Vector3d } from "./vector3d.js";
|
|
4
|
-
import { Point } from "./point.js";
|
|
5
|
-
import { Quaternion } from "./quaternion.js";
|
|
6
|
-
describe("Matrix4", () => {
|
|
7
|
-
describe("constructor", () => {
|
|
8
|
-
it("creates identity matrix by default", () => {
|
|
9
|
-
const m = new Matrix4();
|
|
10
|
-
expect(m.get(0, 0)).toBe(1);
|
|
11
|
-
expect(m.get(1, 1)).toBe(1);
|
|
12
|
-
expect(m.get(2, 2)).toBe(1);
|
|
13
|
-
expect(m.get(3, 3)).toBe(1);
|
|
14
|
-
expect(m.get(0, 1)).toBe(0);
|
|
15
|
-
});
|
|
16
|
-
it("creates matrix from array", () => {
|
|
17
|
-
const elements = [
|
|
18
|
-
1, 2, 3, 4,
|
|
19
|
-
5, 6, 7, 8,
|
|
20
|
-
9, 10, 11, 12,
|
|
21
|
-
13, 14, 15, 16,
|
|
22
|
-
];
|
|
23
|
-
const m = new Matrix4(elements);
|
|
24
|
-
expect(m.get(0, 0)).toBe(1);
|
|
25
|
-
expect(m.get(1, 0)).toBe(2);
|
|
26
|
-
expect(m.get(0, 1)).toBe(5);
|
|
27
|
-
});
|
|
28
|
-
it("throws for wrong array length", () => {
|
|
29
|
-
expect(() => new Matrix4([1, 2, 3])).toThrow();
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
describe("identity", () => {
|
|
33
|
-
it("returns identity matrix", () => {
|
|
34
|
-
const m = Matrix4.identity();
|
|
35
|
-
expect(m.get(0, 0)).toBe(1);
|
|
36
|
-
expect(m.get(1, 1)).toBe(1);
|
|
37
|
-
expect(m.get(2, 2)).toBe(1);
|
|
38
|
-
expect(m.get(3, 3)).toBe(1);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
describe("multiply", () => {
|
|
42
|
-
it("identity * M = M", () => {
|
|
43
|
-
const m = Matrix4.fromTranslation(1, 2, 3);
|
|
44
|
-
const result = Matrix4.identity().multiply(m);
|
|
45
|
-
expect(result.equals(m)).toBe(true);
|
|
46
|
-
});
|
|
47
|
-
it("M * identity = M", () => {
|
|
48
|
-
const m = Matrix4.fromTranslation(1, 2, 3);
|
|
49
|
-
const result = m.multiply(Matrix4.identity());
|
|
50
|
-
expect(result.equals(m)).toBe(true);
|
|
51
|
-
});
|
|
52
|
-
it("combines translations correctly", () => {
|
|
53
|
-
const t1 = Matrix4.fromTranslation(1, 0, 0);
|
|
54
|
-
const t2 = Matrix4.fromTranslation(0, 2, 0);
|
|
55
|
-
const combined = t1.multiply(t2);
|
|
56
|
-
const p = combined.transformPoint(Point.origin());
|
|
57
|
-
expect(p.x).toBeCloseTo(1);
|
|
58
|
-
expect(p.y).toBeCloseTo(2);
|
|
59
|
-
expect(p.z).toBeCloseTo(0);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
describe("determinant", () => {
|
|
63
|
-
it("identity has determinant 1", () => {
|
|
64
|
-
const m = Matrix4.identity();
|
|
65
|
-
expect(m.determinant()).toBe(1);
|
|
66
|
-
});
|
|
67
|
-
it("scale matrix has determinant = product of scales", () => {
|
|
68
|
-
const m = Matrix4.fromScale(2, 3, 4);
|
|
69
|
-
expect(m.determinant()).toBeCloseTo(24);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
describe("inverse", () => {
|
|
73
|
-
it("M * M^-1 = identity", () => {
|
|
74
|
-
const m = Matrix4.fromTranslation(1, 2, 3);
|
|
75
|
-
const inv = m.inverse();
|
|
76
|
-
const result = m.multiply(inv);
|
|
77
|
-
expect(result.equals(Matrix4.identity(), 1e-10)).toBe(true);
|
|
78
|
-
});
|
|
79
|
-
it("inverts rotation matrix", () => {
|
|
80
|
-
const m = Matrix4.fromRotationZ(Math.PI / 4);
|
|
81
|
-
const inv = m.inverse();
|
|
82
|
-
const result = m.multiply(inv);
|
|
83
|
-
expect(result.equals(Matrix4.identity(), 1e-10)).toBe(true);
|
|
84
|
-
});
|
|
85
|
-
it("inverts complex transformation", () => {
|
|
86
|
-
const m = Matrix4.fromTranslation(1, 2, 3)
|
|
87
|
-
.multiply(Matrix4.fromRotationY(Math.PI / 6))
|
|
88
|
-
.multiply(Matrix4.fromScale(2, 2, 2));
|
|
89
|
-
const inv = m.inverse();
|
|
90
|
-
const result = m.multiply(inv);
|
|
91
|
-
expect(result.equals(Matrix4.identity(), 1e-10)).toBe(true);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
describe("transpose", () => {
|
|
95
|
-
it("swaps rows and columns", () => {
|
|
96
|
-
const m = new Matrix4([
|
|
97
|
-
1, 2, 3, 4,
|
|
98
|
-
5, 6, 7, 8,
|
|
99
|
-
9, 10, 11, 12,
|
|
100
|
-
13, 14, 15, 16,
|
|
101
|
-
]);
|
|
102
|
-
const t = m.transpose();
|
|
103
|
-
expect(t.get(0, 1)).toBe(m.get(1, 0));
|
|
104
|
-
expect(t.get(1, 0)).toBe(m.get(0, 1));
|
|
105
|
-
});
|
|
106
|
-
it("double transpose returns original", () => {
|
|
107
|
-
const m = Matrix4.fromRotationZ(Math.PI / 4);
|
|
108
|
-
const result = m.transpose().transpose();
|
|
109
|
-
expect(result.equals(m, 1e-10)).toBe(true);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
describe("fromTranslation", () => {
|
|
113
|
-
it("creates translation matrix", () => {
|
|
114
|
-
const m = Matrix4.fromTranslation(10, 20, 30);
|
|
115
|
-
const p = m.transformPoint(Point.origin());
|
|
116
|
-
expect(p.x).toBe(10);
|
|
117
|
-
expect(p.y).toBe(20);
|
|
118
|
-
expect(p.z).toBe(30);
|
|
119
|
-
});
|
|
120
|
-
it("does not affect vectors", () => {
|
|
121
|
-
const m = Matrix4.fromTranslation(10, 20, 30);
|
|
122
|
-
const v = m.transformVector(new Vector3d(1, 0, 0));
|
|
123
|
-
expect(v.x).toBe(1);
|
|
124
|
-
expect(v.y).toBe(0);
|
|
125
|
-
expect(v.z).toBe(0);
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
describe("fromScale", () => {
|
|
129
|
-
it("creates scale matrix", () => {
|
|
130
|
-
const m = Matrix4.fromScale(2, 3, 4);
|
|
131
|
-
const p = m.transformPoint(new Point(1, 1, 1));
|
|
132
|
-
expect(p.x).toBe(2);
|
|
133
|
-
expect(p.y).toBe(3);
|
|
134
|
-
expect(p.z).toBe(4);
|
|
135
|
-
});
|
|
136
|
-
it("scales vectors", () => {
|
|
137
|
-
const m = Matrix4.fromScale(2, 3, 4);
|
|
138
|
-
const v = m.transformVector(new Vector3d(1, 1, 1));
|
|
139
|
-
expect(v.x).toBe(2);
|
|
140
|
-
expect(v.y).toBe(3);
|
|
141
|
-
expect(v.z).toBe(4);
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
describe("fromUniformScale", () => {
|
|
145
|
-
it("scales uniformly", () => {
|
|
146
|
-
const m = Matrix4.fromUniformScale(3);
|
|
147
|
-
const p = m.transformPoint(new Point(1, 2, 3));
|
|
148
|
-
expect(p.x).toBe(3);
|
|
149
|
-
expect(p.y).toBe(6);
|
|
150
|
-
expect(p.z).toBe(9);
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
describe("fromRotationX", () => {
|
|
154
|
-
it("rotates around X axis", () => {
|
|
155
|
-
const m = Matrix4.fromRotationX(Math.PI / 2);
|
|
156
|
-
const p = m.transformPoint(new Point(0, 1, 0));
|
|
157
|
-
expect(p.x).toBeCloseTo(0);
|
|
158
|
-
expect(p.y).toBeCloseTo(0);
|
|
159
|
-
expect(p.z).toBeCloseTo(1);
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
describe("fromRotationY", () => {
|
|
163
|
-
it("rotates around Y axis", () => {
|
|
164
|
-
const m = Matrix4.fromRotationY(Math.PI / 2);
|
|
165
|
-
const p = m.transformPoint(new Point(1, 0, 0));
|
|
166
|
-
expect(p.x).toBeCloseTo(0);
|
|
167
|
-
expect(p.y).toBeCloseTo(0);
|
|
168
|
-
expect(p.z).toBeCloseTo(-1);
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
describe("fromRotationZ", () => {
|
|
172
|
-
it("rotates around Z axis", () => {
|
|
173
|
-
const m = Matrix4.fromRotationZ(Math.PI / 2);
|
|
174
|
-
const p = m.transformPoint(new Point(1, 0, 0));
|
|
175
|
-
expect(p.x).toBeCloseTo(0);
|
|
176
|
-
expect(p.y).toBeCloseTo(1);
|
|
177
|
-
expect(p.z).toBeCloseTo(0);
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
describe("fromAxisAngle", () => {
|
|
181
|
-
it("rotates around arbitrary axis", () => {
|
|
182
|
-
const m = Matrix4.fromAxisAngle(Vector3d.unitZ(), Math.PI / 2);
|
|
183
|
-
const p = m.transformPoint(new Point(1, 0, 0));
|
|
184
|
-
expect(p.x).toBeCloseTo(0);
|
|
185
|
-
expect(p.y).toBeCloseTo(1);
|
|
186
|
-
expect(p.z).toBeCloseTo(0);
|
|
187
|
-
});
|
|
188
|
-
it("rotates around diagonal axis", () => {
|
|
189
|
-
const axis = new Vector3d(1, 1, 0).normalize();
|
|
190
|
-
const m = Matrix4.fromAxisAngle(axis, Math.PI);
|
|
191
|
-
const p = m.transformPoint(new Point(1, 0, 0));
|
|
192
|
-
expect(p.x).toBeCloseTo(0);
|
|
193
|
-
expect(p.y).toBeCloseTo(1);
|
|
194
|
-
expect(p.z).toBeCloseTo(0);
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
describe("fromQuaternion", () => {
|
|
198
|
-
it("creates rotation matrix from quaternion", () => {
|
|
199
|
-
const q = Quaternion.fromAxisAngle(Vector3d.unitZ(), Math.PI / 2);
|
|
200
|
-
const m = Matrix4.fromQuaternion(q);
|
|
201
|
-
const p = m.transformPoint(new Point(1, 0, 0));
|
|
202
|
-
expect(p.x).toBeCloseTo(0);
|
|
203
|
-
expect(p.y).toBeCloseTo(1);
|
|
204
|
-
expect(p.z).toBeCloseTo(0);
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
describe("fromEulerAngles", () => {
|
|
208
|
-
it("creates rotation from euler angles", () => {
|
|
209
|
-
const m = Matrix4.fromEulerAngles(0, 0, Math.PI / 2);
|
|
210
|
-
const p = m.transformPoint(new Point(1, 0, 0));
|
|
211
|
-
expect(p.x).toBeCloseTo(0);
|
|
212
|
-
expect(p.y).toBeCloseTo(1);
|
|
213
|
-
expect(p.z).toBeCloseTo(0);
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
describe("mirrorPoint", () => {
|
|
217
|
-
it("mirrors through a point", () => {
|
|
218
|
-
const m = Matrix4.mirrorPoint(new Point(5, 0, 0));
|
|
219
|
-
const p = m.transformPoint(new Point(3, 0, 0));
|
|
220
|
-
expect(p.x).toBeCloseTo(7);
|
|
221
|
-
expect(p.y).toBeCloseTo(0);
|
|
222
|
-
expect(p.z).toBeCloseTo(0);
|
|
223
|
-
});
|
|
224
|
-
it("mirrors through origin", () => {
|
|
225
|
-
const m = Matrix4.mirrorPoint(Point.origin());
|
|
226
|
-
const p = m.transformPoint(new Point(1, 2, 3));
|
|
227
|
-
expect(p.x).toBeCloseTo(-1);
|
|
228
|
-
expect(p.y).toBeCloseTo(-2);
|
|
229
|
-
expect(p.z).toBeCloseTo(-3);
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
describe("mirrorPlane", () => {
|
|
233
|
-
it("mirrors through XY plane", () => {
|
|
234
|
-
const m = Matrix4.mirrorPlane(Vector3d.unitZ(), Point.origin());
|
|
235
|
-
const p = m.transformPoint(new Point(1, 2, 3));
|
|
236
|
-
expect(p.x).toBeCloseTo(1);
|
|
237
|
-
expect(p.y).toBeCloseTo(2);
|
|
238
|
-
expect(p.z).toBeCloseTo(-3);
|
|
239
|
-
});
|
|
240
|
-
it("mirrors through YZ plane", () => {
|
|
241
|
-
const m = Matrix4.mirrorPlane(Vector3d.unitX(), Point.origin());
|
|
242
|
-
const p = m.transformPoint(new Point(1, 2, 3));
|
|
243
|
-
expect(p.x).toBeCloseTo(-1);
|
|
244
|
-
expect(p.y).toBeCloseTo(2);
|
|
245
|
-
expect(p.z).toBeCloseTo(3);
|
|
246
|
-
});
|
|
247
|
-
it("mirrors through offset plane", () => {
|
|
248
|
-
const m = Matrix4.mirrorPlane(Vector3d.unitX(), new Point(5, 0, 0));
|
|
249
|
-
const p = m.transformPoint(new Point(3, 0, 0));
|
|
250
|
-
expect(p.x).toBeCloseTo(7);
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
describe("mirrorAxis", () => {
|
|
254
|
-
it("mirrors through Z axis", () => {
|
|
255
|
-
const m = Matrix4.mirrorAxis(Point.origin(), Vector3d.unitZ());
|
|
256
|
-
const p = m.transformPoint(new Point(1, 0, 0));
|
|
257
|
-
expect(p.x).toBeCloseTo(-1);
|
|
258
|
-
expect(p.y).toBeCloseTo(0);
|
|
259
|
-
expect(p.z).toBeCloseTo(0);
|
|
260
|
-
});
|
|
261
|
-
it("mirrors through offset axis", () => {
|
|
262
|
-
const m = Matrix4.mirrorAxis(new Point(5, 0, 0), Vector3d.unitZ());
|
|
263
|
-
const p = m.transformPoint(new Point(3, 0, 0));
|
|
264
|
-
expect(p.x).toBeCloseTo(7);
|
|
265
|
-
expect(p.y).toBeCloseTo(0);
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
describe("transformPoint", () => {
|
|
269
|
-
it("applies translation", () => {
|
|
270
|
-
const m = Matrix4.fromTranslation(10, 20, 30);
|
|
271
|
-
const p = m.transformPoint(new Point(1, 2, 3));
|
|
272
|
-
expect(p.x).toBe(11);
|
|
273
|
-
expect(p.y).toBe(22);
|
|
274
|
-
expect(p.z).toBe(33);
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
describe("transformVector", () => {
|
|
278
|
-
it("applies rotation but not translation", () => {
|
|
279
|
-
const m = Matrix4.fromTranslation(10, 20, 30)
|
|
280
|
-
.multiply(Matrix4.fromRotationZ(Math.PI / 2));
|
|
281
|
-
const v = m.transformVector(new Vector3d(1, 0, 0));
|
|
282
|
-
expect(v.x).toBeCloseTo(0);
|
|
283
|
-
expect(v.y).toBeCloseTo(1);
|
|
284
|
-
expect(v.z).toBeCloseTo(0);
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
describe("transformDirection", () => {
|
|
288
|
-
it("returns normalized result", () => {
|
|
289
|
-
const m = Matrix4.fromScale(2, 2, 2);
|
|
290
|
-
const d = m.transformDirection(new Vector3d(1, 0, 0));
|
|
291
|
-
expect(d.length()).toBeCloseTo(1);
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
describe("decompose", () => {
|
|
295
|
-
it("extracts translation", () => {
|
|
296
|
-
const m = Matrix4.fromTranslation(1, 2, 3);
|
|
297
|
-
const { translation } = m.decompose();
|
|
298
|
-
expect(translation.x).toBeCloseTo(1);
|
|
299
|
-
expect(translation.y).toBeCloseTo(2);
|
|
300
|
-
expect(translation.z).toBeCloseTo(3);
|
|
301
|
-
});
|
|
302
|
-
it("extracts scale", () => {
|
|
303
|
-
const m = Matrix4.fromScale(2, 3, 4);
|
|
304
|
-
const { scale } = m.decompose();
|
|
305
|
-
expect(scale.x).toBeCloseTo(2);
|
|
306
|
-
expect(scale.y).toBeCloseTo(3);
|
|
307
|
-
expect(scale.z).toBeCloseTo(4);
|
|
308
|
-
});
|
|
309
|
-
it("extracts rotation", () => {
|
|
310
|
-
const m = Matrix4.fromRotationZ(Math.PI / 4);
|
|
311
|
-
const { rotation } = m.decompose();
|
|
312
|
-
const v = rotation.rotateVector(new Vector3d(1, 0, 0));
|
|
313
|
-
expect(v.x).toBeCloseTo(Math.cos(Math.PI / 4));
|
|
314
|
-
expect(v.y).toBeCloseTo(Math.sin(Math.PI / 4));
|
|
315
|
-
});
|
|
316
|
-
});
|
|
317
|
-
describe("compose", () => {
|
|
318
|
-
it("creates matrix from translation, rotation, scale", () => {
|
|
319
|
-
const translation = new Vector3d(10, 20, 30);
|
|
320
|
-
const rotation = Quaternion.fromAxisAngle(Vector3d.unitZ(), Math.PI / 2);
|
|
321
|
-
const scale = new Vector3d(2, 2, 2);
|
|
322
|
-
const m = Matrix4.compose(translation, rotation, scale);
|
|
323
|
-
const p = m.transformPoint(new Point(1, 0, 0));
|
|
324
|
-
// First scale (1,0,0) -> (2,0,0)
|
|
325
|
-
// Then rotate 90° around Z -> (0,2,0)
|
|
326
|
-
// Then translate -> (10,22,30)
|
|
327
|
-
expect(p.x).toBeCloseTo(10);
|
|
328
|
-
expect(p.y).toBeCloseTo(22);
|
|
329
|
-
expect(p.z).toBeCloseTo(30);
|
|
330
|
-
});
|
|
331
|
-
});
|
|
332
|
-
describe("equals", () => {
|
|
333
|
-
it("returns true for identical matrices", () => {
|
|
334
|
-
const m1 = Matrix4.fromTranslation(1, 2, 3);
|
|
335
|
-
const m2 = Matrix4.fromTranslation(1, 2, 3);
|
|
336
|
-
expect(m1.equals(m2)).toBe(true);
|
|
337
|
-
});
|
|
338
|
-
it("returns false for different matrices", () => {
|
|
339
|
-
const m1 = Matrix4.fromTranslation(1, 2, 3);
|
|
340
|
-
const m2 = Matrix4.fromTranslation(1, 2, 4);
|
|
341
|
-
expect(m1.equals(m2)).toBe(false);
|
|
342
|
-
});
|
|
343
|
-
it("supports tolerance", () => {
|
|
344
|
-
const m1 = Matrix4.fromTranslation(1, 2, 3);
|
|
345
|
-
const m2 = Matrix4.fromTranslation(1.001, 2.001, 3.001);
|
|
346
|
-
expect(m1.equals(m2, 0.01)).toBe(true);
|
|
347
|
-
});
|
|
348
|
-
});
|
|
349
|
-
describe("clone", () => {
|
|
350
|
-
it("creates independent copy", () => {
|
|
351
|
-
const m = Matrix4.fromTranslation(1, 2, 3);
|
|
352
|
-
const clone = m.clone();
|
|
353
|
-
expect(clone.equals(m)).toBe(true);
|
|
354
|
-
expect(clone).not.toBe(m);
|
|
355
|
-
});
|
|
356
|
-
});
|
|
357
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|