@adobe/data 0.5.14 → 0.5.16

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.
Files changed (130) hide show
  1. package/dist/ecs/entity/entity.d.ts +8 -0
  2. package/dist/ecs/entity/entity.js +3 -0
  3. package/dist/ecs/entity/entity.js.map +1 -0
  4. package/dist/ecs/entity/u32.d.ts +8 -0
  5. package/dist/{lit/elements/service-context.js → ecs/entity/u32.js} +3 -3
  6. package/dist/ecs/entity/u32.js.map +1 -0
  7. package/dist/graphics/frame.d.ts +1 -22
  8. package/dist/graphics/frame.js +14 -11
  9. package/dist/graphics/frame.js.map +1 -1
  10. package/dist/graphics/get-web-gpu-device-and-context.d.ts +1 -2
  11. package/dist/graphics/get-web-gpu-device-and-context.js +23 -20
  12. package/dist/graphics/get-web-gpu-device-and-context.js.map +1 -1
  13. package/dist/graphics/graphics-context.d.ts +1 -5
  14. package/dist/graphics/graphics-context.js +5 -0
  15. package/dist/graphics/graphics-context.js.map +1 -1
  16. package/dist/math/aabb/aabb.d.ts +42 -42
  17. package/dist/math/aabb/aabb.js +65 -62
  18. package/dist/math/aabb/aabb.js.map +1 -1
  19. package/dist/math/aabb-face/aabb-face.d.ts +59 -0
  20. package/dist/math/aabb-face/aabb-face.js +145 -0
  21. package/dist/math/aabb-face/aabb-face.js.map +1 -0
  22. package/dist/math/aabb-face/aabb-face.test.d.ts +1 -0
  23. package/dist/math/aabb-face/aabb-face.test.js +54 -0
  24. package/dist/math/aabb-face/aabb-face.test.js.map +1 -0
  25. package/dist/math/aabb-face/face.d.ts +51 -0
  26. package/dist/math/aabb-face/face.js +110 -0
  27. package/dist/math/aabb-face/face.js.map +1 -0
  28. package/dist/math/aabb-face/face.test.d.ts +1 -0
  29. package/dist/math/aabb-face/face.test.js +94 -0
  30. package/dist/math/aabb-face/face.test.js.map +1 -0
  31. package/dist/math/box/box.d.ts +50 -0
  32. package/dist/math/box/box.js +23 -0
  33. package/dist/math/box/box.js.map +1 -0
  34. package/dist/math/f32/f32.d.ts +8 -6
  35. package/dist/math/f32/f32.js +4 -1
  36. package/dist/math/f32/f32.js.map +1 -1
  37. package/dist/math/face/face.d.ts +51 -0
  38. package/dist/math/face/face.js +110 -0
  39. package/dist/math/face/face.js.map +1 -0
  40. package/dist/math/face/face.test.d.ts +1 -0
  41. package/dist/math/face/face.test.js +94 -0
  42. package/dist/math/face/face.test.js.map +1 -0
  43. package/dist/math/i32/i32.d.ts +9 -6
  44. package/dist/math/i32/i32.js +5 -2
  45. package/dist/math/i32/i32.js.map +1 -1
  46. package/dist/math/index.d.ts +13 -22
  47. package/dist/math/index.js +13 -22
  48. package/dist/math/index.js.map +1 -1
  49. package/dist/math/line2/line2.d.ts +36 -36
  50. package/dist/math/line2/line2.js +55 -52
  51. package/dist/math/line2/line2.js.map +1 -1
  52. package/dist/math/line3/line3.d.ts +48 -43
  53. package/dist/math/line3/line3.js +64 -52
  54. package/dist/math/line3/line3.js.map +1 -1
  55. package/dist/math/mat4x4/mat4x4.d.ts +34 -34
  56. package/dist/math/mat4x4/mat4x4.js +216 -213
  57. package/dist/math/mat4x4/mat4x4.js.map +1 -1
  58. package/dist/math/picking/face.d.ts +1 -0
  59. package/dist/math/picking/face.js +2 -0
  60. package/dist/math/picking/face.js.map +1 -0
  61. package/dist/math/picking/get-closest-entity-to-line.d.ts +4 -0
  62. package/dist/math/picking/get-closest-entity-to-line.js +30 -0
  63. package/dist/math/picking/get-closest-entity-to-line.js.map +1 -0
  64. package/dist/math/picking/get-closest-entity-to-point.d.ts +4 -0
  65. package/dist/math/picking/get-closest-entity-to-point.js +27 -0
  66. package/dist/math/picking/get-closest-entity-to-point.js.map +1 -0
  67. package/dist/math/picking/get-intersecting-entities.d.ts +12 -0
  68. package/dist/math/picking/get-intersecting-entities.js +15 -0
  69. package/dist/math/picking/get-intersecting-entities.js.map +1 -0
  70. package/dist/math/picking/getClosestEntityToLine.d.ts +4 -0
  71. package/dist/math/picking/getClosestEntityToLine.js +29 -0
  72. package/dist/math/picking/getClosestEntityToLine.js.map +1 -0
  73. package/dist/math/picking/getClosestEntityToPoint.d.ts +4 -0
  74. package/dist/math/picking/getClosestEntityToPoint.js +27 -0
  75. package/dist/math/picking/getClosestEntityToPoint.js.map +1 -0
  76. package/dist/math/picking/getIntersectingEntities.d.ts +12 -0
  77. package/dist/math/picking/getIntersectingEntities.js +15 -0
  78. package/dist/math/picking/getIntersectingEntities.js.map +1 -0
  79. package/dist/math/picking/index.d.ts +4 -0
  80. package/dist/math/picking/index.js +4 -0
  81. package/dist/math/picking/index.js.map +1 -1
  82. package/dist/math/picking/pick-from-tables.d.ts +1 -0
  83. package/dist/math/picking/pick-from-tables.js +7 -98
  84. package/dist/math/picking/pick-from-tables.js.map +1 -1
  85. package/dist/math/picking/pick-result.d.ts +5 -2
  86. package/dist/math/plane/plane.d.ts +43 -0
  87. package/dist/math/plane/plane.js +70 -0
  88. package/dist/math/plane/plane.js.map +1 -0
  89. package/dist/math/plane/plane.test.d.ts +1 -0
  90. package/dist/math/plane/plane.test.js +132 -0
  91. package/dist/math/plane/plane.test.js.map +1 -0
  92. package/dist/math/quat/quat.d.ts +49 -39
  93. package/dist/math/quat/quat.js +225 -185
  94. package/dist/math/quat/quat.js.map +1 -1
  95. package/dist/math/u32/u32.d.ts +9 -7
  96. package/dist/math/u32/u32.js +4 -1
  97. package/dist/math/u32/u32.js.map +1 -1
  98. package/dist/math/vec2/vec2.d.ts +61 -61
  99. package/dist/math/vec2/vec2.js +93 -90
  100. package/dist/math/vec2/vec2.js.map +1 -1
  101. package/dist/math/vec3/vec3.d.ts +66 -63
  102. package/dist/math/vec3/vec3.js +137 -129
  103. package/dist/math/vec3/vec3.js.map +1 -1
  104. package/dist/math/vec4/vec4.d.ts +61 -61
  105. package/dist/math/vec4/vec4.js +132 -129
  106. package/dist/math/vec4/vec4.js.map +1 -1
  107. package/dist/observe/to-async-generator.js +4 -4
  108. package/dist/observe/to-async-generator.js.map +1 -1
  109. package/dist/old-ecs/action-ecs/action-ecs.test.js +1 -1
  110. package/dist/old-ecs/action-ecs/action-ecs.test.js.map +1 -1
  111. package/dist/old-ecs/action-ecs/action-types.d.ts +7 -0
  112. package/dist/old-ecs/action-ecs/action-types.js.map +1 -1
  113. package/dist/old-ecs/ecs/ecs-types.d.ts +7 -0
  114. package/dist/old-ecs/ecs/ecs.test.js +1 -1
  115. package/dist/old-ecs/ecs/ecs.test.js.map +1 -1
  116. package/dist/old-ecs/transaction-ecs/transaction-ecs.test.js +1 -1
  117. package/dist/old-ecs/transaction-ecs/transaction-ecs.test.js.map +1 -1
  118. package/dist/old-ecs/transaction-ecs/transaction-types.d.ts +7 -0
  119. package/dist/samples/todo/services/state-service/create-todo-database.d.ts +2 -2
  120. package/dist/samples/todo/services/state-service/create-todo-store.d.ts +2 -2
  121. package/dist/tsconfig.tsbuildinfo +1 -1
  122. package/package.json +6 -3
  123. package/dist/lit/elements/service-application.d.ts +0 -9
  124. package/dist/lit/elements/service-application.js +0 -55
  125. package/dist/lit/elements/service-application.js.map +0 -1
  126. package/dist/lit/elements/service-context.d.ts +0 -1
  127. package/dist/lit/elements/service-context.js.map +0 -1
  128. package/dist/lit/elements/service-element.d.ts +0 -6
  129. package/dist/lit/elements/service-element.js +0 -43
  130. package/dist/lit/elements/service-element.js.map +0 -1
@@ -0,0 +1,8 @@
1
+ import { FromSchema } from "../../schema/schema.js";
2
+ export declare const EntitySchema: {
3
+ readonly type: "integer";
4
+ readonly minimum: 0;
5
+ readonly maximum: 4294967295;
6
+ readonly default: number;
7
+ };
8
+ export type Entity = FromSchema<typeof EntitySchema>;
@@ -0,0 +1,3 @@
1
+ import { U32Schema } from "../../schema/u32.js";
2
+ export const EntitySchema = U32Schema;
3
+ //# sourceMappingURL=entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity.js","sourceRoot":"","sources":["../../../src/ecs/entity/entity.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,MAAM,CAAC,MAAM,YAAY,GAAG,SAAS,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { FromSchema } from "../../schema/index.js";
2
+ export declare const schema: {
3
+ readonly type: "integer";
4
+ readonly minimum: 0;
5
+ readonly maximum: 4294967295;
6
+ readonly default: number;
7
+ };
8
+ export type Type = FromSchema<typeof schema>;
@@ -19,6 +19,6 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.*/
22
- import { createContext } from "@lit/context";
23
- export const serviceContext = createContext(Symbol("service"));
24
- //# sourceMappingURL=service-context.js.map
22
+ import { U32Schema } from "../../schema/index.js";
23
+ export const schema = U32Schema;
24
+ //# sourceMappingURL=u32.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"u32.js","sourceRoot":"","sources":["../../../src/ecs/entity/u32.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;AAEX,OAAO,EAAE,SAAS,EAAc,MAAM,uBAAuB,CAAC;AAC9D,MAAM,CAAC,MAAM,MAAM,GAAG,SAAS,CAAA"}
@@ -1,22 +1 @@
1
- import { FromSchema } from "../schema/schema.js";
2
- export declare const FrameSchema: {
3
- readonly type: "object";
4
- readonly properties: {
5
- readonly count: {
6
- readonly type: "number";
7
- readonly default: 0;
8
- };
9
- readonly deltaTime: {
10
- readonly type: "number";
11
- readonly default: 0;
12
- };
13
- };
14
- readonly required: readonly ["count", "deltaTime"];
15
- readonly additionalProperties: false;
16
- readonly default: {
17
- readonly count: number;
18
- readonly deltaTime: number;
19
- };
20
- readonly transient: true;
21
- };
22
- export type Frame = FromSchema<typeof FrameSchema>;
1
+ export {};
@@ -1,12 +1,15 @@
1
- export const FrameSchema = {
2
- type: "object",
3
- properties: {
4
- count: { type: "number", default: 0 },
5
- deltaTime: { type: "number", default: 0 },
6
- },
7
- required: ["count", "deltaTime"],
8
- additionalProperties: false,
9
- default: { count: 0, deltaTime: 1 / 60 },
10
- transient: true,
11
- };
1
+ // import { FromSchema, Schema } from "../schema/schema.js";
2
+ export {};
3
+ // export const FrameSchema = {
4
+ // type: "object",
5
+ // properties: {
6
+ // count: { type: "number", default: 0 },
7
+ // deltaTime: { type: "number", default: 0 },
8
+ // },
9
+ // required: ["count", "deltaTime"],
10
+ // additionalProperties: false,
11
+ // default: { count: 0 as number, deltaTime: 1 / 60 as number },
12
+ // transient: true,
13
+ // } as const satisfies Schema;
14
+ // export type Frame = FromSchema<typeof FrameSchema>;
12
15
  //# sourceMappingURL=frame.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"frame.js","sourceRoot":"","sources":["../../src/graphics/frame.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,WAAW,GAAG;IACvB,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACR,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,EAAE;QACrC,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,EAAE;KAC5C;IACD,QAAQ,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC;IAChC,oBAAoB,EAAE,KAAK;IAC3B,OAAO,EAAE,EAAE,KAAK,EAAE,CAAW,EAAE,SAAS,EAAE,CAAC,GAAG,EAAY,EAAE;IAC5D,SAAS,EAAE,IAAI;CACQ,CAAC"}
1
+ {"version":3,"file":"frame.js","sourceRoot":"","sources":["../../src/graphics/frame.ts"],"names":[],"mappings":"AAAA,4DAA4D;;AAE5D,+BAA+B;AAC/B,sBAAsB;AACtB,oBAAoB;AACpB,iDAAiD;AACjD,qDAAqD;AACrD,SAAS;AACT,wCAAwC;AACxC,mCAAmC;AACnC,oEAAoE;AACpE,uBAAuB;AACvB,+BAA+B;AAE/B,sDAAsD"}
@@ -1,2 +1 @@
1
- import { GraphicsContext } from "./graphics-context.js";
2
- export declare const getWebGPUGraphicsContext: (canvas: HTMLCanvasElement) => Promise<GraphicsContext>;
1
+ export {};
@@ -1,21 +1,24 @@
1
- export const getWebGPUGraphicsContext = async (canvas) => {
2
- if (!canvas) {
3
- throw new Error('Canvas not found');
4
- }
5
- const adapter = await navigator.gpu?.requestAdapter();
6
- if (!adapter) {
7
- throw new Error('No GPU adapter found');
8
- }
9
- const device = await adapter.requestDevice();
10
- const context = canvas.getContext('webgpu');
11
- if (!context) {
12
- throw new Error('No WebGPU context');
13
- }
14
- context.configure({
15
- device,
16
- format: navigator.gpu.getPreferredCanvasFormat(),
17
- alphaMode: 'premultiplied',
18
- });
19
- return { context, device, canvas };
20
- };
1
+ // import { GraphicsContext } from "./graphics-context.js";
2
+ export {};
3
+ // export const getWebGPUGraphicsContext = async (canvas: HTMLCanvasElement)
4
+ // : Promise<GraphicsContext> => {
5
+ // if (!canvas) {
6
+ // throw new Error('Canvas not found');
7
+ // }
8
+ // const adapter = await navigator.gpu?.requestAdapter();
9
+ // if (!adapter) {
10
+ // throw new Error('No GPU adapter found');
11
+ // }
12
+ // const device = await adapter.requestDevice();
13
+ // const context = canvas.getContext('webgpu');
14
+ // if (!context) {
15
+ // throw new Error('No WebGPU context');
16
+ // }
17
+ // context.configure({
18
+ // device,
19
+ // format: navigator.gpu.getPreferredCanvasFormat(),
20
+ // alphaMode: 'premultiplied',
21
+ // });
22
+ // return { context, device, canvas }
23
+ // }
21
24
  //# sourceMappingURL=get-web-gpu-device-and-context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-web-gpu-device-and-context.js","sourceRoot":"","sources":["../../src/graphics/get-web-gpu-device-and-context.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,EAAE,MAAyB,EAC7C,EAAE;IACzB,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,GAAG,EAAE,cAAc,EAAE,CAAC;IACtD,IAAI,CAAC,OAAO,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,aAAa,EAAE,CAAC;IAE7C,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAC5C,IAAI,CAAC,OAAO,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,CAAC,SAAS,CAAC;QACd,MAAM;QACN,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,wBAAwB,EAAE;QAChD,SAAS,EAAE,eAAe;KAC7B,CAAC,CAAC;IACH,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAA;AACtC,CAAC,CAAA"}
1
+ {"version":3,"file":"get-web-gpu-device-and-context.js","sourceRoot":"","sources":["../../src/graphics/get-web-gpu-device-and-context.ts"],"names":[],"mappings":"AAAA,2DAA2D;;AAE3D,4EAA4E;AAC5E,kCAAkC;AAClC,qBAAqB;AACrB,+CAA+C;AAC/C,QAAQ;AAER,6DAA6D;AAC7D,sBAAsB;AACtB,mDAAmD;AACnD,QAAQ;AAER,oDAAoD;AAEpD,mDAAmD;AACnD,sBAAsB;AACtB,gDAAgD;AAChD,QAAQ;AAER,0BAA0B;AAC1B,kBAAkB;AAClB,4DAA4D;AAC5D,sCAAsC;AACtC,UAAU;AACV,yCAAyC;AACzC,IAAI"}
@@ -1,5 +1 @@
1
- export type GraphicsContext = {
2
- readonly canvas: HTMLCanvasElement;
3
- readonly device: GPUDevice;
4
- readonly context: GPUCanvasContext;
5
- };
1
+ export {};
@@ -1,2 +1,7 @@
1
1
  export {};
2
+ // export type GraphicsContext = {
3
+ // readonly canvas: HTMLCanvasElement;
4
+ // readonly device: GPUDevice;
5
+ // readonly context: GPUCanvasContext;
6
+ // }
2
7
  //# sourceMappingURL=graphics-context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"graphics-context.js","sourceRoot":"","sources":["../../src/graphics/graphics-context.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"graphics-context.js","sourceRoot":"","sources":["../../src/graphics/graphics-context.ts"],"names":[],"mappings":";AACA,kCAAkC;AAClC,0CAA0C;AAC1C,kCAAkC;AAClC,0CAA0C;AAC1C,IAAI"}
@@ -1,48 +1,48 @@
1
1
  import { FromSchema } from "../../schema/index.js";
2
2
  import { Vec3 } from "../index.js";
3
- export declare const schema: {
4
- readonly type: "object";
5
- readonly properties: {
6
- readonly min: {
7
- readonly type: "array";
8
- readonly items: {
9
- readonly type: "number";
10
- readonly precision: 1;
11
- readonly default: number;
3
+ export type Aabb = FromSchema<typeof Aabb.schema>;
4
+ export declare namespace Aabb {
5
+ const schema: {
6
+ readonly type: "object";
7
+ readonly properties: {
8
+ readonly min: {
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];
12
18
  };
13
- readonly minItems: 3;
14
- readonly maxItems: 3;
15
- readonly default: readonly [0, 0, 0];
16
- };
17
- readonly max: {
18
- readonly type: "array";
19
- readonly items: {
20
- readonly type: "number";
21
- readonly precision: 1;
22
- readonly default: number;
19
+ readonly max: {
20
+ readonly type: "array";
21
+ readonly items: {
22
+ readonly type: "number";
23
+ readonly precision: 1;
24
+ readonly default: number;
25
+ };
26
+ readonly minItems: 3;
27
+ readonly maxItems: 3;
28
+ readonly default: readonly [0, 0, 0];
23
29
  };
24
- readonly minItems: 3;
25
- readonly maxItems: 3;
26
- readonly default: readonly [0, 0, 0];
30
+ };
31
+ readonly required: readonly ["min", "max"];
32
+ readonly additionalProperties: false;
33
+ readonly default: {
34
+ readonly min: readonly [0, 0, 0];
35
+ readonly max: readonly [0, 0, 0];
27
36
  };
28
37
  };
29
- readonly required: readonly ["min", "max"];
30
- readonly additionalProperties: false;
31
- readonly default: {
32
- readonly min: readonly [0, 0, 0];
33
- readonly max: readonly [0, 0, 0];
34
- };
35
- };
36
- export type Type = FromSchema<typeof schema>;
37
- type Aabb = Type;
38
- export declare const layout: import("../../typed-buffer/index.js").StructLayout;
39
- export declare const center: (aabb: Aabb) => Vec3;
40
- /**
41
- * @returns the alpha distance along the line (0-1) where the line intersects the box or -1 if it does not.
42
- * @param radius - The radius of the line (treats line as a cylinder). Defaults to 0.
43
- */
44
- export declare const lineIntersection: (box: Aabb, line: {
45
- a: Vec3;
46
- b: Vec3;
47
- }, radius?: number) => number;
48
- export {};
38
+ const layout: import("../../typed-buffer/index.js").StructLayout;
39
+ const center: (aabb: Aabb) => Vec3;
40
+ /**
41
+ * @returns the alpha distance along the line (0-1) where the line intersects the box or -1 if it does not.
42
+ * @param radius - The radius of the line (treats line as a cylinder). Defaults to 0.
43
+ */
44
+ const lineIntersection: (box: Aabb, line: {
45
+ a: Vec3;
46
+ b: Vec3;
47
+ }, radius?: number) => number;
48
+ }
@@ -21,66 +21,69 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.*/
22
22
  import { getStructLayout } from "../../typed-buffer/index.js";
23
23
  import { Vec3 } from "../index.js";
24
- const { schema: Vec3Schema } = Vec3;
25
- export const schema = {
26
- type: 'object',
27
- properties: {
28
- min: Vec3Schema,
29
- max: Vec3Schema,
30
- },
31
- required: ['min', 'max'],
32
- additionalProperties: false,
33
- default: {
34
- min: Vec3Schema.default,
35
- max: Vec3Schema.default,
36
- }
37
- };
38
- export const layout = getStructLayout(schema);
39
- // AABB utility functions
40
- export const center = (aabb) => [
41
- (aabb.min[0] + aabb.max[0]) / 2,
42
- (aabb.min[1] + aabb.max[1]) / 2,
43
- (aabb.min[2] + aabb.max[2]) / 2,
44
- ];
45
- /**
46
- * @returns the alpha distance along the line (0-1) where the line intersects the box or -1 if it does not.
47
- * @param radius - The radius of the line (treats line as a cylinder). Defaults to 0.
48
- */
49
- export const lineIntersection = (box, line, radius = 0) => {
50
- const { min, max } = box;
51
- const { a, b } = line;
52
- // Expand the box by the radius to treat the line as a cylinder
53
- const expandedMin = [min[0] - radius, min[1] - radius, min[2] - radius];
54
- const expandedMax = [max[0] + radius, max[1] + radius, max[2] + radius];
55
- // Calculate line direction vector
56
- const dir = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
57
- // Calculate intersection parameters for each axis
58
- const tMinX = (expandedMin[0] - a[0]) / dir[0];
59
- const tMaxX = (expandedMax[0] - a[0]) / dir[0];
60
- const tMinY = (expandedMin[1] - a[1]) / dir[1];
61
- const tMaxY = (expandedMax[1] - a[1]) / dir[1];
62
- const tMinZ = (expandedMin[2] - a[2]) / dir[2];
63
- const tMaxZ = (expandedMax[2] - a[2]) / dir[2];
64
- // Handle division by zero (line parallel to axis)
65
- const tMinXFinal = dir[0] >= 0 ? tMinX : tMaxX;
66
- const tMaxXFinal = dir[0] >= 0 ? tMaxX : tMinX;
67
- const tMinYFinal = dir[1] >= 0 ? tMinY : tMaxY;
68
- const tMaxYFinal = dir[1] >= 0 ? tMaxY : tMinY;
69
- const tMinZFinal = dir[2] >= 0 ? tMinZ : tMaxZ;
70
- const tMaxZFinal = dir[2] >= 0 ? tMaxZ : tMinZ;
71
- // Find the largest minimum and smallest maximum
72
- const tMin = Math.max(tMinXFinal, tMinYFinal, tMinZFinal);
73
- const tMax = Math.min(tMaxXFinal, tMaxYFinal, tMaxZFinal);
74
- // Check if intersection exists
75
- if (tMax < tMin || tMax < 0) {
76
- return -1;
77
- }
78
- // If tMin is negative, the line starts inside the box
79
- const alpha = tMin < 0 ? 0 : tMin;
80
- // Check if the intersection point is within the line segment (0-1)
81
- if (alpha > 1) {
82
- return -1;
83
- }
84
- return alpha;
85
- };
24
+ export var Aabb;
25
+ (function (Aabb) {
26
+ const { schema: Vec3Schema } = Vec3;
27
+ Aabb.schema = {
28
+ type: 'object',
29
+ properties: {
30
+ min: Vec3Schema,
31
+ max: Vec3Schema,
32
+ },
33
+ required: ['min', 'max'],
34
+ additionalProperties: false,
35
+ default: {
36
+ min: Vec3Schema.default,
37
+ max: Vec3Schema.default,
38
+ }
39
+ };
40
+ Aabb.layout = getStructLayout(Aabb.schema);
41
+ // AABB utility functions
42
+ Aabb.center = (aabb) => [
43
+ (aabb.min[0] + aabb.max[0]) / 2,
44
+ (aabb.min[1] + aabb.max[1]) / 2,
45
+ (aabb.min[2] + aabb.max[2]) / 2,
46
+ ];
47
+ /**
48
+ * @returns the alpha distance along the line (0-1) where the line intersects the box or -1 if it does not.
49
+ * @param radius - The radius of the line (treats line as a cylinder). Defaults to 0.
50
+ */
51
+ Aabb.lineIntersection = (box, line, radius = 0) => {
52
+ const { min, max } = box;
53
+ const { a, b } = line;
54
+ // Expand the box by the radius to treat the line as a cylinder
55
+ const expandedMin = [min[0] - radius, min[1] - radius, min[2] - radius];
56
+ const expandedMax = [max[0] + radius, max[1] + radius, max[2] + radius];
57
+ // Calculate line direction vector
58
+ const dir = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
59
+ // Calculate intersection parameters for each axis
60
+ const tMinX = (expandedMin[0] - a[0]) / dir[0];
61
+ const tMaxX = (expandedMax[0] - a[0]) / dir[0];
62
+ const tMinY = (expandedMin[1] - a[1]) / dir[1];
63
+ const tMaxY = (expandedMax[1] - a[1]) / dir[1];
64
+ const tMinZ = (expandedMin[2] - a[2]) / dir[2];
65
+ const tMaxZ = (expandedMax[2] - a[2]) / dir[2];
66
+ // Handle division by zero (line parallel to axis)
67
+ const tMinXFinal = dir[0] >= 0 ? tMinX : tMaxX;
68
+ const tMaxXFinal = dir[0] >= 0 ? tMaxX : tMinX;
69
+ const tMinYFinal = dir[1] >= 0 ? tMinY : tMaxY;
70
+ const tMaxYFinal = dir[1] >= 0 ? tMaxY : tMinY;
71
+ const tMinZFinal = dir[2] >= 0 ? tMinZ : tMaxZ;
72
+ const tMaxZFinal = dir[2] >= 0 ? tMaxZ : tMinZ;
73
+ // Find the largest minimum and smallest maximum
74
+ const tMin = Math.max(tMinXFinal, tMinYFinal, tMinZFinal);
75
+ const tMax = Math.min(tMaxXFinal, tMaxYFinal, tMaxZFinal);
76
+ // Check if intersection exists
77
+ if (tMax < tMin || tMax < 0) {
78
+ return -1;
79
+ }
80
+ // If tMin is negative, the line starts inside the box
81
+ const alpha = tMin < 0 ? 0 : tMin;
82
+ // Check if the intersection point is within the line segment (0-1)
83
+ if (alpha > 1) {
84
+ return -1;
85
+ }
86
+ return alpha;
87
+ };
88
+ })(Aabb || (Aabb = {}));
86
89
  //# sourceMappingURL=aabb.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"aabb.js","sourceRoot":"","sources":["../../../src/math/aabb/aabb.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;AAGX,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;AAEpC,MAAM,CAAC,MAAM,MAAM,GAAG;IAClB,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACR,GAAG,EAAE,UAAU;QACf,GAAG,EAAE,UAAU;KAClB;IACD,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;IACxB,oBAAoB,EAAE,KAAK;IAC3B,OAAO,EAAE;QACL,GAAG,EAAE,UAAU,CAAC,OAAO;QACvB,GAAG,EAAE,UAAU,CAAC,OAAO;KAC1B;CACsB,CAAC;AAI5B,MAAM,CAAC,MAAM,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,CAA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,KAAK,CAAC;QAC/C,MAAM,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;QAC/C,MAAM,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;QAC/C,MAAM,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;QAC/C,MAAM,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;QAE/C,gDAAgD;QAChD,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;QAC1D,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;QAE1D,+BAA+B;QAC/B,IAAI,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;YAC1B,OAAO,CAAC,CAAC,CAAC;QACd,CAAC;QAED,sDAAsD;QACtD,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAElC,mEAAmE;QACnE,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACZ,OAAO,CAAC,CAAC,CAAC;QACd,CAAC;QAED,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC;AACN,CAAC,EA3EgB,IAAI,KAAJ,IAAI,QA2EpB"}
@@ -0,0 +1,59 @@
1
+ import { FromSchema } from "../../schema/index.js";
2
+ import { Vec3, Aabb } from "../index.js";
3
+ export type AabbFace = FromSchema<typeof AabbFace.schema>;
4
+ export declare namespace AabbFace {
5
+ const schema: {
6
+ readonly type: "number";
7
+ readonly minimum: 0;
8
+ readonly maximum: 5;
9
+ };
10
+ /**
11
+ * AABB face direction constants for cube faces
12
+ */
13
+ const POS_Z: 0;
14
+ const POS_X: 1;
15
+ const NEG_Z: 2;
16
+ const NEG_X: 3;
17
+ const POS_Y: 4;
18
+ const NEG_Y: 5;
19
+ /**
20
+ * Array of all face directions
21
+ */
22
+ const ALL_FACES: readonly [0, 1, 2, 3, 4, 5];
23
+ /**
24
+ * AABB face direction names for debugging/logging
25
+ */
26
+ const FACE_NAMES: readonly ["POS_Z", "POS_X", "NEG_Z", "NEG_X", "POS_Y", "NEG_Y"];
27
+ /**
28
+ * Get the AABB face name for debugging/logging
29
+ */
30
+ const getName: (face: AabbFace) => string;
31
+ /**
32
+ * Get the normal vector for a given AABB face
33
+ */
34
+ const getNormal: (face: AabbFace) => Vec3;
35
+ /**
36
+ * Get the opposite AABB face
37
+ */
38
+ const getOpposite: (face: AabbFace) => AabbFace;
39
+ /**
40
+ * Check if two AABB faces are opposite
41
+ */
42
+ const isOpposite: (face1: AabbFace, face2: AabbFace) => boolean;
43
+ /**
44
+ * Get all AABB faces adjacent to the given face (faces that share an edge)
45
+ */
46
+ const getAdjacent: (face: AabbFace) => readonly AabbFace[];
47
+ /**
48
+ * Check if two AABB faces are adjacent (share an edge)
49
+ */
50
+ const isAdjacent: (face1: AabbFace, face2: AabbFace) => boolean;
51
+ /**
52
+ * Determines which AABB face a position is closest to.
53
+ * Assumes the position is in normalized coordinate space - a cube with size 1 centered on the origin.
54
+ * @param position World position of the intersection point
55
+ * @param aabb Bounding box of the cube
56
+ * @returns AabbFace index: 0=POS_Z, 1=POS_X, 2=NEG_Z, 3=NEG_X, 4=POS_Y, 5=NEG_Y
57
+ */
58
+ const fromPosition: (position: Vec3, aabb: Aabb) => AabbFace;
59
+ }
@@ -0,0 +1,145 @@
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 { Aabb } from "../index.js";
23
+ export var AabbFace;
24
+ (function (AabbFace) {
25
+ AabbFace.schema = {
26
+ type: 'number',
27
+ minimum: 0,
28
+ maximum: 5,
29
+ };
30
+ /**
31
+ * AABB face direction constants for cube faces
32
+ */
33
+ AabbFace.POS_Z = 0;
34
+ AabbFace.POS_X = 1;
35
+ AabbFace.NEG_Z = 2;
36
+ AabbFace.NEG_X = 3;
37
+ AabbFace.POS_Y = 4;
38
+ AabbFace.NEG_Y = 5;
39
+ /**
40
+ * Array of all face directions
41
+ */
42
+ AabbFace.ALL_FACES = [AabbFace.POS_Z, AabbFace.POS_X, AabbFace.NEG_Z, AabbFace.NEG_X, AabbFace.POS_Y, AabbFace.NEG_Y];
43
+ /**
44
+ * AABB face direction names for debugging/logging
45
+ */
46
+ AabbFace.FACE_NAMES = [
47
+ 'POS_Z', 'POS_X', 'NEG_Z', 'NEG_X', 'POS_Y', 'NEG_Y'
48
+ ];
49
+ /**
50
+ * Get the AABB face name for debugging/logging
51
+ */
52
+ AabbFace.getName = (face) => {
53
+ return AabbFace.FACE_NAMES[face];
54
+ };
55
+ /**
56
+ * Get the normal vector for a given AABB face
57
+ */
58
+ AabbFace.getNormal = (face) => {
59
+ switch (face) {
60
+ case AabbFace.POS_Z: return [0, 0, 1];
61
+ case AabbFace.NEG_Z: return [0, 0, -1];
62
+ case AabbFace.POS_X: return [1, 0, 0];
63
+ case AabbFace.NEG_X: return [-1, 0, 0];
64
+ case AabbFace.POS_Y: return [0, 1, 0];
65
+ case AabbFace.NEG_Y: return [0, -1, 0];
66
+ default: throw new Error(`Invalid face index: ${face}`);
67
+ }
68
+ };
69
+ /**
70
+ * Get the opposite AABB face
71
+ */
72
+ AabbFace.getOpposite = (face) => {
73
+ switch (face) {
74
+ case AabbFace.POS_Z: return AabbFace.NEG_Z;
75
+ case AabbFace.NEG_Z: return AabbFace.POS_Z;
76
+ case AabbFace.POS_X: return AabbFace.NEG_X;
77
+ case AabbFace.NEG_X: return AabbFace.POS_X;
78
+ case AabbFace.POS_Y: return AabbFace.NEG_Y;
79
+ case AabbFace.NEG_Y: return AabbFace.POS_Y;
80
+ default: throw new Error(`Invalid face index: ${face}`);
81
+ }
82
+ };
83
+ /**
84
+ * Check if two AABB faces are opposite
85
+ */
86
+ AabbFace.isOpposite = (face1, face2) => {
87
+ return AabbFace.getOpposite(face1) === face2;
88
+ };
89
+ /**
90
+ * Get all AABB faces adjacent to the given face (faces that share an edge)
91
+ */
92
+ AabbFace.getAdjacent = (face) => {
93
+ switch (face) {
94
+ case AabbFace.POS_Z:
95
+ case AabbFace.NEG_Z:
96
+ return [AabbFace.POS_X, AabbFace.NEG_X, AabbFace.POS_Y, AabbFace.NEG_Y];
97
+ case AabbFace.POS_X:
98
+ case AabbFace.NEG_X:
99
+ return [AabbFace.POS_Z, AabbFace.NEG_Z, AabbFace.POS_Y, AabbFace.NEG_Y];
100
+ case AabbFace.POS_Y:
101
+ case AabbFace.NEG_Y:
102
+ return [AabbFace.POS_Z, AabbFace.NEG_Z, AabbFace.POS_X, AabbFace.NEG_X];
103
+ default:
104
+ throw new Error(`Invalid face index: ${face}`);
105
+ }
106
+ };
107
+ /**
108
+ * Check if two AABB faces are adjacent (share an edge)
109
+ */
110
+ AabbFace.isAdjacent = (face1, face2) => {
111
+ return AabbFace.getAdjacent(face1).includes(face2);
112
+ };
113
+ /**
114
+ * Determines which AABB face a position is closest to.
115
+ * Assumes the position is in normalized coordinate space - a cube with size 1 centered on the origin.
116
+ * @param position World position of the intersection point
117
+ * @param aabb Bounding box of the cube
118
+ * @returns AabbFace index: 0=POS_Z, 1=POS_X, 2=NEG_Z, 3=NEG_X, 4=POS_Y, 5=NEG_Y
119
+ */
120
+ AabbFace.fromPosition = (position, aabb) => {
121
+ const aabbCenter = Aabb.center(aabb);
122
+ const localPos = [
123
+ position[0] - aabbCenter[0],
124
+ position[1] - aabbCenter[1],
125
+ position[2] - aabbCenter[2]
126
+ ];
127
+ // Find the face with the largest absolute coordinate (closest to cube surface)
128
+ const absX = Math.abs(localPos[0]);
129
+ const absY = Math.abs(localPos[1]);
130
+ const absZ = Math.abs(localPos[2]);
131
+ if (absX >= absY && absX >= absZ) {
132
+ // X-axis face (NEG_X or POS_X)
133
+ return localPos[0] > 0 ? AabbFace.POS_X : AabbFace.NEG_X;
134
+ }
135
+ else if (absY >= absZ) {
136
+ // Y-axis face (NEG_Y or POS_Y)
137
+ return localPos[1] > 0 ? AabbFace.POS_Y : AabbFace.NEG_Y;
138
+ }
139
+ else {
140
+ // Z-axis face (NEG_Z or POS_Z)
141
+ return localPos[2] > 0 ? AabbFace.POS_Z : AabbFace.NEG_Z;
142
+ }
143
+ };
144
+ })(AabbFace || (AabbFace = {}));
145
+ //# sourceMappingURL=aabb-face.js.map