@adobe/data 0.5.14 → 0.5.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ecs/database/create-database.test.js +11 -0
- package/dist/ecs/database/create-database.test.js.map +1 -1
- package/dist/math/aabb/aabb.d.ts +42 -42
- package/dist/math/aabb/aabb.js +65 -62
- package/dist/math/aabb/aabb.js.map +1 -1
- package/dist/math/aabb-face/aabb-face.d.ts +59 -0
- package/dist/math/aabb-face/aabb-face.js +145 -0
- package/dist/math/aabb-face/aabb-face.js.map +1 -0
- package/dist/math/aabb-face/aabb-face.test.d.ts +1 -0
- package/dist/math/aabb-face/aabb-face.test.js +54 -0
- package/dist/math/aabb-face/aabb-face.test.js.map +1 -0
- package/dist/math/f32/f32.d.ts +8 -6
- package/dist/math/f32/f32.js +4 -1
- package/dist/math/f32/f32.js.map +1 -1
- package/dist/math/i32/i32.d.ts +9 -6
- package/dist/math/i32/i32.js +5 -2
- package/dist/math/i32/i32.js.map +1 -1
- package/dist/math/index.d.ts +13 -22
- package/dist/math/index.js +13 -22
- package/dist/math/index.js.map +1 -1
- package/dist/math/line2/line2.d.ts +36 -36
- package/dist/math/line2/line2.js +55 -52
- package/dist/math/line2/line2.js.map +1 -1
- package/dist/math/line3/line3.d.ts +48 -43
- package/dist/math/line3/line3.js +64 -52
- package/dist/math/line3/line3.js.map +1 -1
- package/dist/math/mat4x4/mat4x4.d.ts +34 -34
- package/dist/math/mat4x4/mat4x4.js +216 -213
- package/dist/math/mat4x4/mat4x4.js.map +1 -1
- package/dist/math/picking/get-closest-entity-to-line.d.ts +4 -0
- package/dist/math/picking/get-closest-entity-to-line.js +30 -0
- package/dist/math/picking/get-closest-entity-to-line.js.map +1 -0
- package/dist/math/picking/get-closest-entity-to-point.d.ts +4 -0
- package/dist/math/picking/get-closest-entity-to-point.js +27 -0
- package/dist/math/picking/get-closest-entity-to-point.js.map +1 -0
- package/dist/math/picking/get-intersecting-entities.d.ts +12 -0
- package/dist/math/picking/get-intersecting-entities.js +15 -0
- package/dist/math/picking/get-intersecting-entities.js.map +1 -0
- package/dist/math/picking/index.d.ts +4 -0
- package/dist/math/picking/index.js +4 -0
- package/dist/math/picking/index.js.map +1 -1
- package/dist/math/picking/pick-from-tables.d.ts +1 -0
- package/dist/math/picking/pick-from-tables.js +7 -98
- package/dist/math/picking/pick-from-tables.js.map +1 -1
- package/dist/math/picking/pick-result.d.ts +5 -2
- package/dist/math/plane/plane.d.ts +43 -0
- package/dist/math/plane/plane.js +70 -0
- package/dist/math/plane/plane.js.map +1 -0
- package/dist/math/plane/plane.test.d.ts +1 -0
- package/dist/math/plane/plane.test.js +132 -0
- package/dist/math/plane/plane.test.js.map +1 -0
- package/dist/math/quat/quat.d.ts +49 -39
- package/dist/math/quat/quat.js +225 -185
- package/dist/math/quat/quat.js.map +1 -1
- package/dist/math/u32/u32.d.ts +9 -7
- package/dist/math/u32/u32.js +4 -1
- package/dist/math/u32/u32.js.map +1 -1
- package/dist/math/vec2/vec2.d.ts +61 -61
- package/dist/math/vec2/vec2.js +93 -90
- package/dist/math/vec2/vec2.js.map +1 -1
- package/dist/math/vec3/vec3.d.ts +66 -63
- package/dist/math/vec3/vec3.js +137 -129
- package/dist/math/vec3/vec3.js.map +1 -1
- package/dist/math/vec4/vec4.d.ts +61 -61
- package/dist/math/vec4/vec4.js +132 -129
- package/dist/math/vec4/vec4.js.map +1 -1
- package/dist/observe/to-async-generator.js +4 -4
- package/dist/observe/to-async-generator.js.map +1 -1
- package/dist/old-ecs/action-ecs/action-ecs.test.js +1 -1
- package/dist/old-ecs/action-ecs/action-ecs.test.js.map +1 -1
- package/dist/old-ecs/action-ecs/action-types.d.ts +7 -0
- package/dist/old-ecs/action-ecs/action-types.js.map +1 -1
- package/dist/old-ecs/core-ecs/core-ecs-serialization.test.js +205 -1
- package/dist/old-ecs/core-ecs/core-ecs-serialization.test.js.map +1 -1
- package/dist/old-ecs/core-ecs/core-ecs-types.d.ts +4 -1
- package/dist/old-ecs/core-ecs/core-ecs.d.ts +2 -0
- package/dist/old-ecs/core-ecs/core-ecs.js +23 -9
- package/dist/old-ecs/core-ecs/core-ecs.js.map +1 -1
- package/dist/old-ecs/ecs/ecs-types.d.ts +7 -0
- package/dist/old-ecs/ecs/ecs.test.js +1 -1
- package/dist/old-ecs/ecs/ecs.test.js.map +1 -1
- package/dist/old-ecs/privacy/helper-functions.d.ts +43 -0
- package/dist/old-ecs/privacy/helper-functions.js +76 -0
- package/dist/old-ecs/privacy/helper-functions.js.map +1 -0
- package/dist/old-ecs/privacy/helper-functions.test.d.ts +1 -0
- package/dist/old-ecs/privacy/helper-functions.test.js +173 -0
- package/dist/old-ecs/privacy/helper-functions.test.js.map +1 -0
- package/dist/old-ecs/transaction-ecs/transaction-ecs.test.js +1 -1
- package/dist/old-ecs/transaction-ecs/transaction-ecs.test.js.map +1 -1
- package/dist/old-ecs/transaction-ecs/transaction-types.d.ts +7 -0
- package/dist/samples/todo/services/state-service/create-todo-database.d.ts +2 -2
- package/dist/samples/todo/services/state-service/create-todo-store.d.ts +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -3
|
@@ -21,104 +21,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
21
21
|
SOFTWARE.*/
|
|
22
22
|
import { Aabb } from "../index.js";
|
|
23
23
|
import { Line3 } from "../index.js";
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* @param position World position of the intersection
|
|
28
|
-
* @param aabb Bounding box of the cube
|
|
29
|
-
* @returns Face index: 0=POS_Z, 1=POS_X, 2=NEG_Z, 3=NEG_X, 4=POS_Y, 5=NEG_Y
|
|
30
|
-
*/
|
|
31
|
-
function determineFaceFromPosition(position, aabb) {
|
|
32
|
-
const aabbCenter = Aabb.center(aabb);
|
|
33
|
-
const localPos = [
|
|
34
|
-
position[0] - aabbCenter[0],
|
|
35
|
-
position[1] - aabbCenter[1],
|
|
36
|
-
position[2] - aabbCenter[2]
|
|
37
|
-
];
|
|
38
|
-
// Find the face with the largest absolute coordinate (closest to cube surface)
|
|
39
|
-
const absX = Math.abs(localPos[0]);
|
|
40
|
-
const absY = Math.abs(localPos[1]);
|
|
41
|
-
const absZ = Math.abs(localPos[2]);
|
|
42
|
-
if (absX >= absY && absX >= absZ) {
|
|
43
|
-
// X-axis face (NEG_X or POS_X)
|
|
44
|
-
return localPos[0] > 0 ? 1 : 3; // 1=POS_X, 3=NEG_X
|
|
45
|
-
}
|
|
46
|
-
else if (absY >= absZ) {
|
|
47
|
-
// Y-axis face (NEG_Y or POS_Y)
|
|
48
|
-
return localPos[1] > 0 ? 4 : 5; // 4=POS_Y, 5=NEG_Y
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
// Z-axis face (NEG_Z or POS_Z)
|
|
52
|
-
return localPos[2] > 0 ? 0 : 2; // 0=POS_Z, 2=NEG_Z
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
function getIntersectingEntities(options) {
|
|
56
|
-
const { tables, line, radius = 0, predicate } = options;
|
|
57
|
-
const rows = new Map();
|
|
58
|
-
for (const table of tables) {
|
|
59
|
-
for (let row = 0; row < table.rowCount; row++) {
|
|
60
|
-
const boundingBox = table.columns.boundingBox.get(row);
|
|
61
|
-
if (Aabb.lineIntersection(boundingBox, line, radius) !== -1 && (predicate?.(table, row) ?? true)) {
|
|
62
|
-
rows.set(table.columns.id.get(row), boundingBox);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return rows;
|
|
67
|
-
}
|
|
68
|
-
function getClosestEntityToPoint(rows, point) {
|
|
69
|
-
let closestRow = -1;
|
|
70
|
-
let closestDistanceSquared = Infinity;
|
|
71
|
-
let closestAabb = null;
|
|
72
|
-
for (const [row, aabb] of rows) {
|
|
73
|
-
const distSquared = Vec3.distanceSquared(point, Aabb.center(aabb));
|
|
74
|
-
if (distSquared < closestDistanceSquared) {
|
|
75
|
-
closestDistanceSquared = distSquared;
|
|
76
|
-
closestRow = row;
|
|
77
|
-
closestAabb = aabb;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (closestRow !== -1 && closestAabb) {
|
|
81
|
-
// For direct intersection, use the intersection point if possible
|
|
82
|
-
// We'll use the intersection alpha from Aabb.lineIntersection
|
|
83
|
-
// If the line starts inside, alpha=0, so position is line.a
|
|
84
|
-
// Otherwise, Line3.interpolate at alpha
|
|
85
|
-
return {
|
|
86
|
-
entity: closestRow,
|
|
87
|
-
position: point,
|
|
88
|
-
face: determineFaceFromPosition(point, closestAabb),
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
function getClosestEntityToLine(rows, line) {
|
|
94
|
-
let closestEntity = null;
|
|
95
|
-
let closestDistanceSquared = Infinity;
|
|
96
|
-
let closestAlpha = Infinity;
|
|
97
|
-
let pickedPosition = null;
|
|
98
|
-
for (const [id, aabb] of rows) {
|
|
99
|
-
const aabbCenter = Aabb.center(aabb);
|
|
100
|
-
const alpha = Line3.closestPointOnLine(line, aabbCenter);
|
|
101
|
-
const closestPointOnLineSegment = Line3.interpolate(line, alpha);
|
|
102
|
-
const distSquared = Vec3.distanceSquared(aabbCenter, closestPointOnLineSegment);
|
|
103
|
-
if (distSquared < closestDistanceSquared ||
|
|
104
|
-
(distSquared === closestDistanceSquared && alpha < closestAlpha)) {
|
|
105
|
-
closestDistanceSquared = distSquared;
|
|
106
|
-
closestAlpha = alpha;
|
|
107
|
-
closestEntity = id;
|
|
108
|
-
pickedPosition = closestPointOnLineSegment;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (closestEntity !== null && pickedPosition) {
|
|
112
|
-
return {
|
|
113
|
-
entity: closestEntity,
|
|
114
|
-
position: pickedPosition,
|
|
115
|
-
face: determineFaceFromPosition(pickedPosition, rows.get(closestEntity)),
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
24
|
+
import { getIntersectingEntities } from "./get-intersecting-entities.js";
|
|
25
|
+
import { getClosestEntityToPoint } from "./get-closest-entity-to-point.js";
|
|
26
|
+
import { getClosestEntityToLine } from "./get-closest-entity-to-line.js";
|
|
120
27
|
/**
|
|
121
28
|
* Picks the closest intersecting row from a table.
|
|
29
|
+
* This would be the broad phase picking step.
|
|
122
30
|
* @returns The entity id and picked position, or null if no entity is found.
|
|
123
31
|
*/
|
|
124
32
|
export function pickFromTables(options) {
|
|
@@ -136,8 +44,9 @@ export function pickFromTables(options) {
|
|
|
136
44
|
if (best) {
|
|
137
45
|
return {
|
|
138
46
|
entity: best.id,
|
|
139
|
-
|
|
140
|
-
|
|
47
|
+
lineAlpha: best.alpha,
|
|
48
|
+
entityPosition: Line3.interpolate(line, best.alpha),
|
|
49
|
+
// face: AabbFace.fromPosition(Line3.interpolate(line, best.alpha), rows.get(best.id)!),
|
|
141
50
|
};
|
|
142
51
|
}
|
|
143
52
|
// fallback (should not happen):
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pick-from-tables.js","sourceRoot":"","sources":["../../../src/math/picking/pick-from-tables.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;
|
|
1
|
+
{"version":3,"file":"pick-from-tables.js","sourceRoot":"","sources":["../../../src/math/picking/pick-from-tables.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;AAGX,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEzE;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAA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sB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC9C,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { Entity } from "../../ecs/index.js";
|
|
2
2
|
import { Vec3 } from "../index.js";
|
|
3
3
|
export interface PickResult {
|
|
4
|
+
/** The entity that was picked. */
|
|
4
5
|
entity: Entity;
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
/** Alpha value (0-1) along the picking line where the intersection/closest point occurs. */
|
|
7
|
+
lineAlpha: number;
|
|
8
|
+
/** World-space position of the entity or closest point on the AABB. */
|
|
9
|
+
entityPosition: Vec3;
|
|
7
10
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { FromSchema } from "../../schema/index.js";
|
|
2
|
+
import { Vec3, Line3 } from "../index.js";
|
|
3
|
+
export type Plane = FromSchema<typeof Plane.schema>;
|
|
4
|
+
export declare namespace Plane {
|
|
5
|
+
const schema: {
|
|
6
|
+
readonly type: "object";
|
|
7
|
+
readonly properties: {
|
|
8
|
+
readonly normal: {
|
|
9
|
+
readonly type: "array";
|
|
10
|
+
readonly items: {
|
|
11
|
+
readonly type: "number";
|
|
12
|
+
readonly precision: 1;
|
|
13
|
+
readonly default: number;
|
|
14
|
+
};
|
|
15
|
+
readonly minItems: 3;
|
|
16
|
+
readonly maxItems: 3;
|
|
17
|
+
readonly default: readonly [0, 0, 0];
|
|
18
|
+
};
|
|
19
|
+
readonly distance: {
|
|
20
|
+
readonly type: "number";
|
|
21
|
+
readonly precision: 1;
|
|
22
|
+
readonly default: number;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
readonly layout: "std140";
|
|
26
|
+
readonly required: readonly ["normal", "distance"];
|
|
27
|
+
readonly additionalProperties: false;
|
|
28
|
+
};
|
|
29
|
+
const layout: import("../../typed-buffer/index.js").StructLayout;
|
|
30
|
+
function is(value: any): value is Plane;
|
|
31
|
+
const signedDistance: (plane: Plane, point: Vec3) => number;
|
|
32
|
+
const distance: (plane: Plane, point: Vec3) => number;
|
|
33
|
+
const containsPoint: (plane: Plane, point: Vec3) => boolean;
|
|
34
|
+
const isPointInFront: (plane: Plane, point: Vec3) => boolean;
|
|
35
|
+
const isPointBehind: (plane: Plane, point: Vec3) => boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Find the intersection alpha between a line and a plane.
|
|
38
|
+
* @param plane The plane to intersect with
|
|
39
|
+
* @param line The line to intersect
|
|
40
|
+
* @returns The alpha parameter (0-1 = within segment, <0 or >1 = outside segment), or null if line is parallel to plane
|
|
41
|
+
*/
|
|
42
|
+
const lineIntersection: (plane: Plane, line: Line3) => number | null;
|
|
43
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/*MIT License
|
|
2
|
+
|
|
3
|
+
© Copyright 2025 Adobe. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.*/
|
|
22
|
+
import { getStructLayout } from "../../typed-buffer/index.js";
|
|
23
|
+
import { Vec3, F32, epsilon } from "../index.js";
|
|
24
|
+
export var Plane;
|
|
25
|
+
(function (Plane) {
|
|
26
|
+
Plane.schema = {
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties: {
|
|
29
|
+
normal: Vec3.schema,
|
|
30
|
+
distance: F32.schema,
|
|
31
|
+
},
|
|
32
|
+
layout: 'std140',
|
|
33
|
+
required: ['normal', 'distance'],
|
|
34
|
+
additionalProperties: false,
|
|
35
|
+
};
|
|
36
|
+
Plane.layout = getStructLayout(Plane.schema);
|
|
37
|
+
function is(value) {
|
|
38
|
+
return value && typeof value === 'object' && 'normal' in value && 'distance' in value;
|
|
39
|
+
}
|
|
40
|
+
Plane.is = is;
|
|
41
|
+
// Plane utility functions
|
|
42
|
+
Plane.signedDistance = (plane, point) => Vec3.dot(plane.normal, point) - plane.distance;
|
|
43
|
+
Plane.distance = (plane, point) => Math.abs(Plane.signedDistance(plane, point));
|
|
44
|
+
Plane.containsPoint = (plane, point) => Math.abs(Plane.signedDistance(plane, point)) < epsilon;
|
|
45
|
+
Plane.isPointInFront = (plane, point) => Plane.signedDistance(plane, point) > 0;
|
|
46
|
+
Plane.isPointBehind = (plane, point) => Plane.signedDistance(plane, point) < 0;
|
|
47
|
+
/**
|
|
48
|
+
* Find the intersection alpha between a line and a plane.
|
|
49
|
+
* @param plane The plane to intersect with
|
|
50
|
+
* @param line The line to intersect
|
|
51
|
+
* @returns The alpha parameter (0-1 = within segment, <0 or >1 = outside segment), or null if line is parallel to plane
|
|
52
|
+
*/
|
|
53
|
+
Plane.lineIntersection = (plane, line) => {
|
|
54
|
+
const { a, b } = line;
|
|
55
|
+
// Calculate line direction vector
|
|
56
|
+
const direction = Vec3.subtract(b, a);
|
|
57
|
+
// Calculate denominator: dot(normal, direction)
|
|
58
|
+
const denominator = Vec3.dot(plane.normal, direction);
|
|
59
|
+
// If denominator is close to zero, line is parallel to plane
|
|
60
|
+
if (Math.abs(denominator) < epsilon) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
// Calculate numerator: dot(normal, a) - distance
|
|
64
|
+
const numerator = Vec3.dot(plane.normal, a) - plane.distance;
|
|
65
|
+
// Calculate parameter t (alpha)
|
|
66
|
+
const alpha = -numerator / denominator;
|
|
67
|
+
return alpha;
|
|
68
|
+
};
|
|
69
|
+
})(Plane || (Plane = {}));
|
|
70
|
+
//# sourceMappingURL=plane.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plane.js","sourceRoot":"","sources":["../../../src/math/plane/plane.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;AAGX,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,GAAG,EAAS,OAAO,EAAE,MAAM,aAAa,CAAC;AAIxD,MAAM,KAAW,KAAK,CA8DrB;AA9DD,WAAiB,KAAK;IACL,YAAM,GAAG;QAClB,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACR,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,QAAQ,EAAE,GAAG,CAAC,MAAM;SACvB;QACD,MAAM,EAAE,QAAQ;QAChB,QAAQ,EAAE,CAAC,QAAQ,EAAE,UAAU,CAAC;QAChC,oBAAoB,EAAE,KAAK;KACJ,CAAC;IAEf,YAAM,GAAG,eAAe,CAAC,MAAA,MAAM,CAAC,CAAC;IAE9C,SAAgB,EAAE,CAAC,KAAU;QACzB,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,QAAQ,IAAI,KAAK,IAAI,UAAU,IAAI,KAAK,CAAC;IAC1F,CAAC;IAFe,QAAE,KAEjB,CAAA;IAED,0BAA0B;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E,CAAC,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC;QAE7D,gCAAgC;QAChC,MAAM,KAAK,GAAG,CAAC,SAAS,GAAG,WAAW,CAAC;QAEvC,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC;AACN,CAAC,EA9DgB,KAAK,KAAL,KAAK,QA8DrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/*MIT License
|
|
2
|
+
|
|
3
|
+
© Copyright 2025 Adobe. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.*/
|
|
22
|
+
import { describe, it, expect } from "vitest";
|
|
23
|
+
import { Plane } from "../index.js";
|
|
24
|
+
describe("Plane", () => {
|
|
25
|
+
const xyPlane = {
|
|
26
|
+
normal: [0, 0, 1], // pointing up
|
|
27
|
+
distance: 0 // plane at origin
|
|
28
|
+
};
|
|
29
|
+
const xyPlaneOffset = {
|
|
30
|
+
normal: [0, 0, 1], // pointing up
|
|
31
|
+
distance: 5 // plane 5 units above origin
|
|
32
|
+
};
|
|
33
|
+
describe("signedDistance", () => {
|
|
34
|
+
it("should return 0 for points on the plane", () => {
|
|
35
|
+
expect(Plane.signedDistance(xyPlane, [0, 0, 0])).toBe(0);
|
|
36
|
+
expect(Plane.signedDistance(xyPlane, [5, 3, 0])).toBe(0);
|
|
37
|
+
});
|
|
38
|
+
it("should return positive distance for points in front of plane", () => {
|
|
39
|
+
expect(Plane.signedDistance(xyPlane, [0, 0, 1])).toBe(1);
|
|
40
|
+
expect(Plane.signedDistance(xyPlane, [0, 0, 5])).toBe(5);
|
|
41
|
+
});
|
|
42
|
+
it("should return negative distance for points behind plane", () => {
|
|
43
|
+
expect(Plane.signedDistance(xyPlane, [0, 0, -1])).toBe(-1);
|
|
44
|
+
expect(Plane.signedDistance(xyPlane, [0, 0, -3])).toBe(-3);
|
|
45
|
+
});
|
|
46
|
+
it("should work with offset planes", () => {
|
|
47
|
+
expect(Plane.signedDistance(xyPlaneOffset, [0, 0, 5])).toBe(0); // on plane
|
|
48
|
+
expect(Plane.signedDistance(xyPlaneOffset, [0, 0, 7])).toBe(2); // 2 units above
|
|
49
|
+
expect(Plane.signedDistance(xyPlaneOffset, [0, 0, 3])).toBe(-2); // 2 units below
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
describe("distance", () => {
|
|
53
|
+
it("should return absolute distance", () => {
|
|
54
|
+
expect(Plane.distance(xyPlane, [0, 0, 3])).toBe(3);
|
|
55
|
+
expect(Plane.distance(xyPlane, [0, 0, -3])).toBe(3);
|
|
56
|
+
expect(Plane.distance(xyPlane, [0, 0, 0])).toBe(0);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe("containsPoint", () => {
|
|
60
|
+
it("should return true for points on the plane", () => {
|
|
61
|
+
expect(Plane.containsPoint(xyPlane, [0, 0, 0])).toBe(true);
|
|
62
|
+
expect(Plane.containsPoint(xyPlane, [5, 3, 0])).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
it("should return false for points off the plane", () => {
|
|
65
|
+
expect(Plane.containsPoint(xyPlane, [0, 0, 0.001])).toBe(false);
|
|
66
|
+
expect(Plane.containsPoint(xyPlane, [0, 0, -0.001])).toBe(false);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe("isPointInFront", () => {
|
|
70
|
+
it("should return true for points in front of plane", () => {
|
|
71
|
+
expect(Plane.isPointInFront(xyPlane, [0, 0, 1])).toBe(true);
|
|
72
|
+
expect(Plane.isPointInFront(xyPlane, [0, 0, 5])).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
it("should return false for points behind or on plane", () => {
|
|
75
|
+
expect(Plane.isPointInFront(xyPlane, [0, 0, 0])).toBe(false);
|
|
76
|
+
expect(Plane.isPointInFront(xyPlane, [0, 0, -1])).toBe(false);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe("isPointBehind", () => {
|
|
80
|
+
it("should return true for points behind plane", () => {
|
|
81
|
+
expect(Plane.isPointBehind(xyPlane, [0, 0, -1])).toBe(true);
|
|
82
|
+
expect(Plane.isPointBehind(xyPlane, [0, 0, -5])).toBe(true);
|
|
83
|
+
});
|
|
84
|
+
it("should return false for points in front or on plane", () => {
|
|
85
|
+
expect(Plane.isPointBehind(xyPlane, [0, 0, 0])).toBe(false);
|
|
86
|
+
expect(Plane.isPointBehind(xyPlane, [0, 0, 1])).toBe(false);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
describe("lineIntersection", () => {
|
|
90
|
+
it("should find intersection alpha for line crossing plane", () => {
|
|
91
|
+
const line = { a: [0, 0, -1], b: [0, 0, 1] }; // vertical line
|
|
92
|
+
const alpha = Plane.lineIntersection(xyPlane, line);
|
|
93
|
+
expect(alpha).toBe(0.5); // intersects at midpoint
|
|
94
|
+
});
|
|
95
|
+
it("should find intersection alpha for diagonal line", () => {
|
|
96
|
+
const line = { a: [1, 1, -1], b: [1, 1, 1] }; // diagonal line
|
|
97
|
+
const alpha = Plane.lineIntersection(xyPlane, line);
|
|
98
|
+
expect(alpha).toBe(0.5); // intersects at midpoint
|
|
99
|
+
});
|
|
100
|
+
it("should find intersection alpha for offset plane", () => {
|
|
101
|
+
const line = { a: [0, 0, 3], b: [0, 0, 7] }; // line above offset plane
|
|
102
|
+
const alpha = Plane.lineIntersection(xyPlaneOffset, line);
|
|
103
|
+
expect(alpha).toBe(0.5); // intersects at midpoint (z=5)
|
|
104
|
+
});
|
|
105
|
+
it("should return null for line parallel to plane", () => {
|
|
106
|
+
const line = { a: [0, 0, 1], b: [1, 0, 1] }; // horizontal line
|
|
107
|
+
const alpha = Plane.lineIntersection(xyPlane, line);
|
|
108
|
+
expect(alpha).toBeNull();
|
|
109
|
+
});
|
|
110
|
+
it("should return null for line in the plane", () => {
|
|
111
|
+
const line = { a: [0, 0, 0], b: [1, 0, 0] }; // line in xy plane
|
|
112
|
+
const alpha = Plane.lineIntersection(xyPlane, line);
|
|
113
|
+
expect(alpha).toBeNull();
|
|
114
|
+
});
|
|
115
|
+
it("should handle line that doesn't intersect within segment", () => {
|
|
116
|
+
const line = { a: [0, 0, 2], b: [0, 0, 4] }; // line above plane
|
|
117
|
+
const alpha = Plane.lineIntersection(xyPlane, line);
|
|
118
|
+
expect(alpha).toBe(-1); // intersection exists but before segment start
|
|
119
|
+
});
|
|
120
|
+
it("should handle alpha values outside segment", () => {
|
|
121
|
+
const line = { a: [0, 0, 2], b: [0, 0, 6] }; // line from z=2 to z=6
|
|
122
|
+
const alpha = Plane.lineIntersection(xyPlane, line);
|
|
123
|
+
expect(alpha).toBe(-0.5); // intersects at z=0, which is before segment start
|
|
124
|
+
});
|
|
125
|
+
it("should handle alpha values after segment end", () => {
|
|
126
|
+
const line = { a: [0, 0, -2], b: [0, 0, -1] }; // line from z=-2 to z=-1
|
|
127
|
+
const alpha = Plane.lineIntersection(xyPlane, line);
|
|
128
|
+
expect(alpha).toBe(2); // intersects at z=0, which is after segment end
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
//# sourceMappingURL=plane.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plane.test.js","sourceRoot":"","sources":["../../../src/math/plane/plane.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;AAEX,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAe,MAAM,aAAa,CAAC;AAEjD,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;IACnB,MAAM,OAAO,GAAU;QACnB,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc;QACjC,QAAQ,EAAE,CAAC,CAAC,kBAAkB;KACjC,CAAC;IAEF,MAAM,aAAa,GAAU;QACzB,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc;QACjC,QAAQ,EAAE,CAAC,CAAC,6BAA6B;KAC5C,CAAC;IAEF,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;QAC5B,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;YAC/C,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACzD,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC7D,CAAC,CAAC,CAA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AAO,EAAE,IAAI,CAAC,CAAC;YACpD,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,gDAAgD;QAC3E,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
package/dist/math/quat/quat.d.ts
CHANGED
|
@@ -1,42 +1,52 @@
|
|
|
1
1
|
import { FromSchema } from "../../schema/index.js";
|
|
2
2
|
import { Vec3, Mat4x4 } from "../index.js";
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
readonly type: "
|
|
7
|
-
readonly
|
|
8
|
-
|
|
3
|
+
export type Quat = FromSchema<typeof Quat.schema>;
|
|
4
|
+
export declare namespace Quat {
|
|
5
|
+
const schema: {
|
|
6
|
+
readonly type: "array";
|
|
7
|
+
readonly items: {
|
|
8
|
+
readonly type: "number";
|
|
9
|
+
readonly precision: 1;
|
|
10
|
+
readonly default: number;
|
|
11
|
+
};
|
|
12
|
+
readonly minItems: 4;
|
|
13
|
+
readonly maxItems: 4;
|
|
14
|
+
readonly default: readonly [0, 0, 0, 1];
|
|
9
15
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
16
|
+
const layout: import("../../typed-buffer/index.js").StructLayout;
|
|
17
|
+
const add: ([x1, y1, z1, w1]: Quat, [x2, y2, z2, w2]: Quat) => Quat;
|
|
18
|
+
const subtract: ([x1, y1, z1, w1]: Quat, [x2, y2, z2, w2]: Quat) => Quat;
|
|
19
|
+
const scale: ([x, y, z, w]: Quat, s: number) => Quat;
|
|
20
|
+
const negate: ([x, y, z, w]: Quat) => Quat;
|
|
21
|
+
const conjugate: ([x, y, z, w]: Quat) => Quat;
|
|
22
|
+
const multiply: ([x1, y1, z1, w1]: Quat, [x2, y2, z2, w2]: Quat) => Quat;
|
|
23
|
+
const length: ([x, y, z, w]: Quat) => number;
|
|
24
|
+
const lengthSquared: ([x, y, z, w]: Quat) => number;
|
|
25
|
+
const normalize: (q: Quat) => Quat;
|
|
26
|
+
const dot: ([x1, y1, z1, w1]: Quat, [x2, y2, z2, w2]: Quat) => number;
|
|
27
|
+
const distance: (a: Quat, b: Quat) => number;
|
|
28
|
+
const fromAxisAngle: (axis: Vec3, angle: number) => Quat;
|
|
29
|
+
const toAxisAngle: ([x, y, z, w]: Quat) => {
|
|
30
|
+
axis: Vec3;
|
|
31
|
+
angle: number;
|
|
32
|
+
};
|
|
33
|
+
const fromEuler: (x: number, y: number, z: number) => Quat;
|
|
34
|
+
const toEuler: ([x, y, z, w]: Quat) => Vec3;
|
|
35
|
+
const rotateVec3: ([x, y, z, w]: Quat, v: Vec3) => Vec3;
|
|
36
|
+
const slerp: (q1: Quat, q2: Quat, t: number) => Quat;
|
|
37
|
+
const lerp: (q1: Quat, q2: Quat, t: number) => Quat;
|
|
38
|
+
const toMat4: ([x, y, z, w]: Quat) => Mat4x4;
|
|
39
|
+
const identity: Quat;
|
|
40
|
+
const inverse: (q: Quat) => Quat;
|
|
41
|
+
const lookAt: (forward: Vec3, up: Vec3) => Quat;
|
|
42
|
+
/**
|
|
43
|
+
* Returns a quaternion that aligns the local Z-axis to the given direction via the shortest arc,
|
|
44
|
+
* then applies an additional twist around that aligned Z-axis.
|
|
45
|
+
*
|
|
46
|
+
* Note: This aligns the Z axis.
|
|
47
|
+
*
|
|
48
|
+
* @param direction - Target world-space direction for local Z. If zero-length, returns identity.
|
|
49
|
+
* @param twistRadians - Extra rotation around the aligned Z-axis, in radians. Defaults to 0.
|
|
50
|
+
*/
|
|
51
|
+
const alignTo: (direction: Vec3, twistRadians?: number) => Quat;
|
|
52
|
+
}
|