@ac-kit/math-geometry 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +28 -0
  3. package/README.md +86 -0
  4. package/dist/angles.d.ts +31 -0
  5. package/dist/angles.d.ts.map +1 -0
  6. package/dist/angles.js +53 -0
  7. package/dist/angles.js.map +1 -0
  8. package/dist/box3.d.ts +17 -0
  9. package/dist/box3.d.ts.map +1 -0
  10. package/dist/box3.js +82 -0
  11. package/dist/box3.js.map +1 -0
  12. package/dist/box4.d.ts +9 -0
  13. package/dist/box4.d.ts.map +1 -0
  14. package/dist/box4.js +7 -0
  15. package/dist/box4.js.map +1 -0
  16. package/dist/circle2.d.ts +74 -0
  17. package/dist/circle2.d.ts.map +1 -0
  18. package/dist/circle2.js +100 -0
  19. package/dist/circle2.js.map +1 -0
  20. package/dist/coordinate-spaces.d.ts +39 -0
  21. package/dist/coordinate-spaces.d.ts.map +1 -0
  22. package/dist/coordinate-spaces.js +52 -0
  23. package/dist/coordinate-spaces.js.map +1 -0
  24. package/dist/coordinates-vec2.d.ts +7 -0
  25. package/dist/coordinates-vec2.d.ts.map +1 -0
  26. package/dist/coordinates-vec2.js +35 -0
  27. package/dist/coordinates-vec2.js.map +1 -0
  28. package/dist/coordinates-vec3.d.ts +11 -0
  29. package/dist/coordinates-vec3.d.ts.map +1 -0
  30. package/dist/coordinates-vec3.js +61 -0
  31. package/dist/coordinates-vec3.js.map +1 -0
  32. package/dist/coordinates.d.ts +54 -0
  33. package/dist/coordinates.d.ts.map +1 -0
  34. package/dist/coordinates.js +2 -0
  35. package/dist/coordinates.js.map +1 -0
  36. package/dist/euler-angles-quaternion.d.ts +7 -0
  37. package/dist/euler-angles-quaternion.d.ts.map +1 -0
  38. package/dist/euler-angles-quaternion.js +100 -0
  39. package/dist/euler-angles-quaternion.js.map +1 -0
  40. package/dist/euler-angles.d.ts +33 -0
  41. package/dist/euler-angles.d.ts.map +1 -0
  42. package/dist/euler-angles.js +35 -0
  43. package/dist/euler-angles.js.map +1 -0
  44. package/dist/geometry-vectors.d.ts +11 -0
  45. package/dist/geometry-vectors.d.ts.map +1 -0
  46. package/dist/geometry-vectors.js +19 -0
  47. package/dist/geometry-vectors.js.map +1 -0
  48. package/dist/globals.d.ts +47 -0
  49. package/dist/globals.d.ts.map +1 -0
  50. package/dist/globals.js +29 -0
  51. package/dist/globals.js.map +1 -0
  52. package/dist/index.d.ts +33 -0
  53. package/dist/index.d.ts.map +1 -0
  54. package/dist/index.js +33 -0
  55. package/dist/index.js.map +1 -0
  56. package/dist/line2.d.ts +43 -0
  57. package/dist/line2.d.ts.map +1 -0
  58. package/dist/line2.js +68 -0
  59. package/dist/line2.js.map +1 -0
  60. package/dist/line3.d.ts +30 -0
  61. package/dist/line3.d.ts.map +1 -0
  62. package/dist/line3.js +46 -0
  63. package/dist/line3.js.map +1 -0
  64. package/dist/mesh3.d.ts +32 -0
  65. package/dist/mesh3.d.ts.map +1 -0
  66. package/dist/mesh3.js +142 -0
  67. package/dist/mesh3.js.map +1 -0
  68. package/dist/plane3.d.ts +38 -0
  69. package/dist/plane3.d.ts.map +1 -0
  70. package/dist/plane3.js +60 -0
  71. package/dist/plane3.js.map +1 -0
  72. package/dist/point2.d.ts +41 -0
  73. package/dist/point2.d.ts.map +1 -0
  74. package/dist/point2.js +92 -0
  75. package/dist/point2.js.map +1 -0
  76. package/dist/point3.d.ts +43 -0
  77. package/dist/point3.d.ts.map +1 -0
  78. package/dist/point3.js +103 -0
  79. package/dist/point3.js.map +1 -0
  80. package/dist/point4.d.ts +12 -0
  81. package/dist/point4.d.ts.map +1 -0
  82. package/dist/point4.js +28 -0
  83. package/dist/point4.js.map +1 -0
  84. package/dist/polygon2.d.ts +30 -0
  85. package/dist/polygon2.d.ts.map +1 -0
  86. package/dist/polygon2.js +127 -0
  87. package/dist/polygon2.js.map +1 -0
  88. package/dist/polygon3.d.ts +28 -0
  89. package/dist/polygon3.d.ts.map +1 -0
  90. package/dist/polygon3.js +112 -0
  91. package/dist/polygon3.js.map +1 -0
  92. package/dist/ray2.d.ts +14 -0
  93. package/dist/ray2.d.ts.map +1 -0
  94. package/dist/ray2.js +27 -0
  95. package/dist/ray2.js.map +1 -0
  96. package/dist/ray3.d.ts +30 -0
  97. package/dist/ray3.d.ts.map +1 -0
  98. package/dist/ray3.js +81 -0
  99. package/dist/ray3.js.map +1 -0
  100. package/dist/rect2.d.ts +54 -0
  101. package/dist/rect2.d.ts.map +1 -0
  102. package/dist/rect2.js +149 -0
  103. package/dist/rect2.js.map +1 -0
  104. package/dist/segment2.d.ts +24 -0
  105. package/dist/segment2.d.ts.map +1 -0
  106. package/dist/segment2.js +55 -0
  107. package/dist/segment2.js.map +1 -0
  108. package/dist/segment3.d.ts +13 -0
  109. package/dist/segment3.d.ts.map +1 -0
  110. package/dist/segment3.js +33 -0
  111. package/dist/segment3.js.map +1 -0
  112. package/dist/size2.d.ts +33 -0
  113. package/dist/size2.d.ts.map +1 -0
  114. package/dist/size2.js +81 -0
  115. package/dist/size2.js.map +1 -0
  116. package/dist/size3.d.ts +21 -0
  117. package/dist/size3.d.ts.map +1 -0
  118. package/dist/size3.js +59 -0
  119. package/dist/size3.js.map +1 -0
  120. package/dist/size4.d.ts +10 -0
  121. package/dist/size4.d.ts.map +1 -0
  122. package/dist/size4.js +16 -0
  123. package/dist/size4.js.map +1 -0
  124. package/dist/sphere3.d.ts +13 -0
  125. package/dist/sphere3.d.ts.map +1 -0
  126. package/dist/sphere3.js +26 -0
  127. package/dist/sphere3.js.map +1 -0
  128. package/dist/triangle2.d.ts +17 -0
  129. package/dist/triangle2.d.ts.map +1 -0
  130. package/dist/triangle2.js +31 -0
  131. package/dist/triangle2.js.map +1 -0
  132. package/dist/triangle3.d.ts +20 -0
  133. package/dist/triangle3.d.ts.map +1 -0
  134. package/dist/triangle3.js +43 -0
  135. package/dist/triangle3.js.map +1 -0
  136. package/package.json +67 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0] - 2026-08-26
4
+
5
+ ### Added
6
+
7
+ - Initial release.
package/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024-2026 Anthony Champagne and contributors
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # @ac-kit/math-geometry
2
+
3
+ Computational geometry in 2D, 3D and 4D: shapes, coordinate systems, angles, and
4
+ the predicates and constructions over them.
5
+
6
+ ## Scope
7
+
8
+ Objects defined by a boundary or an extent — points, rectangles, circles,
9
+ polygons, planes, meshes — and the conversions between the coordinate systems
10
+ they are expressed in.
11
+
12
+ Curves parameterised by a scalar belong in `@ac-kit/math-curves`; discrete
13
+ integer lattices belong in `@ac-kit/math-grid`.
14
+
15
+ ## Contents
16
+
17
+ | Group | Types |
18
+ | ----------- | ---------------------------------------------------------------------------------------------------- |
19
+ | 2D shapes | `Point2`, `Rect2`, `Circle2`, `Line2`, `Segment2`, `Ray2`, `Triangle2`, `Polygon2` |
20
+ | 3D shapes | `Point3`, `Box3`, `Sphere3`, `Line3`, `Segment3`, `Ray3`, `Plane3`, `Triangle3`, `Polygon3`, `Mesh3` |
21
+ | 4D | `Point4`, `Box4` |
22
+ | Sizes | `Size2`, `Size3`, `Size4` — including `scaleToFit` and `scaleToFill` |
23
+ | Coordinates | Polar, spherical and cylindrical systems, and the conversions to and from Cartesian |
24
+ | Angles | `EulerAngles`, `EulerOrder`, wrapping, normalisation, angular distance and interpolation |
25
+
26
+ ## Equality and tolerance
27
+
28
+ `*Equals` is always **exact**. It is transitive, so it is safe as a `Set` or
29
+ `Map` key and as a dedupe basis, and it agrees with the matching
30
+ `*CompareLexicographic` — `compare(a, b) === 0` exactly when `equals(a, b)`. The
31
+ tolerant counterpart is `*IsClose`, which is deliberately a different name
32
+ because it is _not_ an equality: `a ≈ b` and `b ≈ c` does not give `a ≈ c`, so
33
+ it must never back an ordering or a container.
34
+
35
+ Which tolerance a predicate takes depends on what it asks:
36
+
37
+ - **Solid predicates** — `circle2ContainsPoint`, `circle2Intersects` — are exact
38
+ and take no tolerance. The boundary is measure-zero, so an epsilon would only
39
+ move it by an arbitrary amount. For deliberate slack, inflate the shape:
40
+ `circle2ContainsPoint({ ...c, radius: c.radius + margin }, p)`. That is a
41
+ length; an epsilon on the squared distance actually compared is not.
42
+ - **Incidence predicates** — `plane3ContainsPoint`, `line2ContainsPoint` — take
43
+ a **linear** tolerance, a distance in your own units. Exact would be useless:
44
+ a constructed point never lands exactly on a plane.
45
+ - **Degeneracy guards** — `line2Intersect`, `segment2Intersect`,
46
+ `ray3IntersectPlane` — take an **angular** tolerance. It is dimensionless and
47
+ compared against a quantity already scaled by the operands' magnitudes, so
48
+ rescaling an input never changes the verdict.
49
+
50
+ Each accepts its tolerance as a final argument and otherwise falls back to
51
+ `geometryConfig`:
52
+
53
+ ```ts
54
+ import { geometryConfig, plane3ContainsPoint } from "@ac-kit/math-geometry";
55
+
56
+ // Per call
57
+ plane3ContainsPoint(plane, point, 1e-6);
58
+
59
+ // Or globally, if you work in millimetres rather than metres
60
+ geometryConfig.defaultLinearTolerance = 1e-6;
61
+ ```
62
+
63
+ The two defaults are separate because the quantities are — the same split CAD
64
+ kernels make between OpenCASCADE's `Precision::Confusion()` and
65
+ `Precision::Angular()`. `geometryConfig` is process-global and mutable, so two
66
+ libraries sharing a process cannot disagree; pass a tolerance explicitly
67
+ wherever that matters.
68
+
69
+ ## Point versus vector
70
+
71
+ `Point2` and `Vec2` have the same representation and different meaning: a point
72
+ is a position, a vector is a displacement. Subtracting two points yields a
73
+ vector; adding a vector to a point yields a point; adding two points is not
74
+ meaningful. The distinction is carried in the type names so that call sites read
75
+ correctly, even though no runtime check enforces it.
76
+
77
+ ## Angles
78
+
79
+ Angles are radians throughout. `DEG_TO_RAD` and `RAD_TO_DEG` from
80
+ `@ac-kit/math-scalar` convert at the boundary; nothing inside the package
81
+ accepts degrees, since a mixed convention is the single most common source of
82
+ geometry bugs.
83
+
84
+ See the
85
+ [generated API docs](https://anthochamp.github.io/node-essentials/api/math-geometry/)
86
+ for the full reference.
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Computes the shortest distance between two angles in degrees, taking into
3
+ * account the circular nature of angles. The result is always in the range [0,
4
+ * 180].
5
+ */
6
+ export declare function angleDistanceDeg(angleA: number, angleB: number): number;
7
+ /**
8
+ * Computes the shortest distance between two angles in radians, taking into
9
+ * account the circular nature of angles. The result is always in the range [0,
10
+ * π].
11
+ */
12
+ export declare function angleDistanceRad(angleA: number, angleB: number): number;
13
+ /** Normalizes an angle in degrees to the range [0, 360). */
14
+ export declare function angleWrapDeg(angle: number): number;
15
+ /** Normalizes an angle in radians to the range [0, 2π). */
16
+ export declare function angleWrapRad(angle: number): number;
17
+ /** Normalizes an angle in degrees to the range (-180, 180]. */
18
+ export declare function angleNormalizeDeg(angle: number): number;
19
+ /** Normalizes an angle in radians to the range (-π, π]. */
20
+ export declare function angleNormalizeRad(angle: number): number;
21
+ /**
22
+ * Linearly interpolates between two angles in degrees, taking the shortest path
23
+ * around the circle.
24
+ */
25
+ export declare function angleLerpDeg(angleA: number, angleB: number, t: number): number;
26
+ /**
27
+ * Linearly interpolates between two angles in radians, taking the shortest path
28
+ * around the circle.
29
+ */
30
+ export declare function angleLerpRad(angleA: number, angleB: number, t: number): number;
31
+ //# sourceMappingURL=angles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"angles.d.ts","sourceRoot":"","sources":["../src/angles.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAGvE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAGvE;AAED,4DAA4D;AAC5D,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,2DAA2D;AAC3D,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,+DAA+D;AAC/D,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,2DAA2D;AAC3D,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC3B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,CAAC,EAAE,MAAM,GACP,MAAM,CAGR;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC3B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,CAAC,EAAE,MAAM,GACP,MAAM,CAGR"}
package/dist/angles.js ADDED
@@ -0,0 +1,53 @@
1
+ import { mod } from "@ac-kit/core";
2
+ import { TWO_PI } from "@ac-kit/math-scalar";
3
+ /**
4
+ * Computes the shortest distance between two angles in degrees, taking into
5
+ * account the circular nature of angles. The result is always in the range [0,
6
+ * 180].
7
+ */
8
+ export function angleDistanceDeg(angleA, angleB) {
9
+ const delta = Math.abs(angleA - angleB);
10
+ return delta > 180 ? 360 - delta : delta;
11
+ }
12
+ /**
13
+ * Computes the shortest distance between two angles in radians, taking into
14
+ * account the circular nature of angles. The result is always in the range [0,
15
+ * π].
16
+ */
17
+ export function angleDistanceRad(angleA, angleB) {
18
+ const delta = Math.abs(angleA - angleB);
19
+ return delta > Math.PI ? TWO_PI - delta : delta;
20
+ }
21
+ /** Normalizes an angle in degrees to the range [0, 360). */
22
+ export function angleWrapDeg(angle) {
23
+ return mod(angle, 360);
24
+ }
25
+ /** Normalizes an angle in radians to the range [0, 2π). */
26
+ export function angleWrapRad(angle) {
27
+ return mod(angle, TWO_PI);
28
+ }
29
+ /** Normalizes an angle in degrees to the range (-180, 180]. */
30
+ export function angleNormalizeDeg(angle) {
31
+ return angleWrapDeg(angle + 180) - 180;
32
+ }
33
+ /** Normalizes an angle in radians to the range (-π, π]. */
34
+ export function angleNormalizeRad(angle) {
35
+ return angleWrapRad(angle + Math.PI) - Math.PI;
36
+ }
37
+ /**
38
+ * Linearly interpolates between two angles in degrees, taking the shortest path
39
+ * around the circle.
40
+ */
41
+ export function angleLerpDeg(angleA, angleB, t) {
42
+ const delta = angleNormalizeDeg(angleB - angleA);
43
+ return angleNormalizeDeg(angleA + delta * t);
44
+ }
45
+ /**
46
+ * Linearly interpolates between two angles in radians, taking the shortest path
47
+ * around the circle.
48
+ */
49
+ export function angleLerpRad(angleA, angleB, t) {
50
+ const delta = angleNormalizeRad(angleB - angleA);
51
+ return angleNormalizeRad(angleA + delta * t);
52
+ }
53
+ //# sourceMappingURL=angles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"angles.js","sourceRoot":"","sources":["../src/angles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAc,EAAE,MAAc;IAC9D,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IACxC,OAAO,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;AAC1C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAc,EAAE,MAAc;IAC9D,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IACxC,OAAO,KAAK,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;AACjD,CAAC;AAED,4DAA4D;AAC5D,MAAM,UAAU,YAAY,CAAC,KAAa;IACzC,OAAO,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACxB,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,YAAY,CAAC,KAAa;IACzC,OAAO,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAC3B,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC9C,OAAO,YAAY,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AACxC,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC9C,OAAO,YAAY,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;AAChD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC3B,MAAc,EACd,MAAc,EACd,CAAS;IAET,MAAM,KAAK,GAAG,iBAAiB,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IACjD,OAAO,iBAAiB,CAAC,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC;AAC9C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC3B,MAAc,EACd,MAAc,EACd,CAAS;IAET,MAAM,KAAK,GAAG,iBAAiB,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IACjD,OAAO,iBAAiB,CAAC,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC;AAC9C,CAAC"}
package/dist/box3.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { Vec3 } from "@ac-kit/math-linear";
2
+ import { Point3 } from "./point3.js";
3
+ import { Size3 } from "./size3.js";
4
+ export type Box3 = {
5
+ origin: Point3;
6
+ size: Size3;
7
+ };
8
+ export declare function box3Center(b: Box3): Point3;
9
+ export declare function box3Contains(container: Box3, contained: Box3): boolean;
10
+ export declare function box3ContainsPoint(b: Box3, p: Point3): boolean;
11
+ export declare function box3Equals(a: Box3, b: Box3): boolean;
12
+ export declare function box3Intersects(a: Box3, b: Box3): boolean;
13
+ export declare function box3Intersection(a: Box3, b: Box3): Box3 | null;
14
+ export declare function box3Translate(b: Box3, offset: Vec3): Box3;
15
+ export declare function box3Union(a: Box3, b: Box3): Box3;
16
+ export declare function box3Volume(b: Box3): number;
17
+ //# sourceMappingURL=box3.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"box3.d.ts","sourceRoot":"","sources":["../src/box3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE3C,OAAO,EAAE,MAAM,EAAgB,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,KAAK,EAA4B,MAAM,YAAY,CAAC;AAE7D,MAAM,MAAM,IAAI,GAAG;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,KAAK,CAAC;CACZ,CAAC;AAEF,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,GAAG,MAAM,CAM1C;AAED,wBAAgB,YAAY,CAAC,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,GAAG,OAAO,CAYtE;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAS7D;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,OAAO,CAEpD;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,OAAO,CASxD;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAkB9D;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAG,IAAI,CASzD;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,IAAI,CAehD;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,GAAG,MAAM,CAE1C"}
package/dist/box3.js ADDED
@@ -0,0 +1,82 @@
1
+ import { point3Equals } from "./point3.js";
2
+ import { size3Equals, size3Volume } from "./size3.js";
3
+ export function box3Center(b) {
4
+ return {
5
+ x: b.origin.x + b.size.width / 2,
6
+ y: b.origin.y + b.size.height / 2,
7
+ z: b.origin.z + b.size.depth / 2,
8
+ };
9
+ }
10
+ export function box3Contains(container, contained) {
11
+ return (contained.origin.x >= container.origin.x &&
12
+ contained.origin.x + contained.size.width <=
13
+ container.origin.x + container.size.width &&
14
+ contained.origin.y >= container.origin.y &&
15
+ contained.origin.y + contained.size.height <=
16
+ container.origin.y + container.size.height &&
17
+ contained.origin.z >= container.origin.z &&
18
+ contained.origin.z + contained.size.depth <=
19
+ container.origin.z + container.size.depth);
20
+ }
21
+ export function box3ContainsPoint(b, p) {
22
+ return (p.x >= b.origin.x &&
23
+ p.x <= b.origin.x + b.size.width &&
24
+ p.y >= b.origin.y &&
25
+ p.y <= b.origin.y + b.size.height &&
26
+ p.z >= b.origin.z &&
27
+ p.z <= b.origin.z + b.size.depth);
28
+ }
29
+ export function box3Equals(a, b) {
30
+ return point3Equals(a.origin, b.origin) && size3Equals(a.size, b.size);
31
+ }
32
+ export function box3Intersects(a, b) {
33
+ return !(a.origin.x + a.size.width < b.origin.x ||
34
+ b.origin.x + b.size.width < a.origin.x ||
35
+ a.origin.y + a.size.height < b.origin.y ||
36
+ b.origin.y + b.size.height < a.origin.y ||
37
+ a.origin.z + a.size.depth < b.origin.z ||
38
+ b.origin.z + b.size.depth < a.origin.z);
39
+ }
40
+ export function box3Intersection(a, b) {
41
+ if (!box3Intersects(a, b)) {
42
+ return null;
43
+ }
44
+ const ox = Math.max(a.origin.x, b.origin.x);
45
+ const oy = Math.max(a.origin.y, b.origin.y);
46
+ const oz = Math.max(a.origin.z, b.origin.z);
47
+ return {
48
+ origin: { x: ox, y: oy, z: oz },
49
+ size: {
50
+ width: Math.min(a.origin.x + a.size.width, b.origin.x + b.size.width) - ox,
51
+ height: Math.min(a.origin.y + a.size.height, b.origin.y + b.size.height) - oy,
52
+ depth: Math.min(a.origin.z + a.size.depth, b.origin.z + b.size.depth) - oz,
53
+ },
54
+ };
55
+ }
56
+ export function box3Translate(b, offset) {
57
+ return {
58
+ origin: {
59
+ x: b.origin.x + offset[0],
60
+ y: b.origin.y + offset[1],
61
+ z: b.origin.z + offset[2],
62
+ },
63
+ size: b.size,
64
+ };
65
+ }
66
+ export function box3Union(a, b) {
67
+ const ox = Math.min(a.origin.x, b.origin.x);
68
+ const oy = Math.min(a.origin.y, b.origin.y);
69
+ const oz = Math.min(a.origin.z, b.origin.z);
70
+ return {
71
+ origin: { x: ox, y: oy, z: oz },
72
+ size: {
73
+ width: Math.max(a.origin.x + a.size.width, b.origin.x + b.size.width) - ox,
74
+ height: Math.max(a.origin.y + a.size.height, b.origin.y + b.size.height) - oy,
75
+ depth: Math.max(a.origin.z + a.size.depth, b.origin.z + b.size.depth) - oz,
76
+ },
77
+ };
78
+ }
79
+ export function box3Volume(b) {
80
+ return size3Volume(b.size);
81
+ }
82
+ //# sourceMappingURL=box3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"box3.js","sourceRoot":"","sources":["../src/box3.ts"],"names":[],"mappings":"AAEA,OAAO,EAAU,YAAY,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAS,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAO7D,MAAM,UAAU,UAAU,CAAC,CAAO;IACjC,OAAO;QACN,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC;QAChC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC;QACjC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC;KAChC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,SAAe,EAAE,SAAe;IAC5D,OAAO,CACN,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,SAAS,CAAC,MAAM,CAAC,CAAC;QACxC,SAAS,CAAC,MAAM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CAAC,CAAO;IACjC,OAAO,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC"}
package/dist/box4.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { Point4 } from "./point4.js";
2
+ import { Size4 } from "./size4.js";
3
+ export type Box4 = {
4
+ origin: Point4;
5
+ size: Size4;
6
+ };
7
+ /** Exact equality of origin and size. */
8
+ export declare function box4Equals(a: Box4, b: Box4): boolean;
9
+ //# sourceMappingURL=box4.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"box4.d.ts","sourceRoot":"","sources":["../src/box4.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAgB,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,KAAK,EAAe,MAAM,YAAY,CAAC;AAEhD,MAAM,MAAM,IAAI,GAAG;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,KAAK,CAAC;CACZ,CAAC;AAEF,yCAAyC;AACzC,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,OAAO,CAEpD"}
package/dist/box4.js ADDED
@@ -0,0 +1,7 @@
1
+ import { point4Equals } from "./point4.js";
2
+ import { size4Equals } from "./size4.js";
3
+ /** Exact equality of origin and size. */
4
+ export function box4Equals(a, b) {
5
+ return point4Equals(a.origin, b.origin) && size4Equals(a.size, b.size);
6
+ }
7
+ //# sourceMappingURL=box4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"box4.js","sourceRoot":"","sources":["../src/box4.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,YAAY,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAS,WAAW,EAAE,MAAM,YAAY,CAAC;AAOhD,yCAAyC;AACzC,MAAM,UAAU,UAAU,CAAC,CAAO,EAAE,CAAO;IAC1C,OAAO,YAAY,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;AACxE,CAAC"}
@@ -0,0 +1,74 @@
1
+ import { Vec2 } from "@ac-kit/math-linear";
2
+ import { Point2 } from "./point2.js";
3
+ export type Circle2 = {
4
+ center: Point2;
5
+ radius: number;
6
+ };
7
+ /**
8
+ * Calculates the area of a 2D circle.
9
+ *
10
+ * @param c - Circle to calculate area for.
11
+ * @returns Area of the circle.
12
+ */
13
+ export declare function circle2Area(c: Circle2): number;
14
+ /**
15
+ * Calculates the circumference of a 2D circle.
16
+ *
17
+ * @param c - Circle to calculate circumference for.
18
+ * @returns Circumference of the circle.
19
+ */
20
+ export declare function circle2Circumference(c: Circle2): number;
21
+ /**
22
+ * Determines whether a point is inside or on the boundary of a 2D circle.
23
+ *
24
+ * Exact: the boundary is measure-zero, so a tolerance would only move it by an
25
+ * arbitrary amount. For deliberate slack, inflate `c.radius` — a length, unlike
26
+ * an epsilon on the squared distance compared here.
27
+ *
28
+ * @param c - Circle to check against.
29
+ * @param p - Point to check.
30
+ * @returns True if the point is inside or on the boundary of the circle, false
31
+ * otherwise.
32
+ */
33
+ export declare function circle2ContainsPoint(c: Circle2, p: Point2): boolean;
34
+ /**
35
+ * Determines whether two 2D circles are equal, considering their centers and
36
+ * radii.
37
+ *
38
+ * @param a - First circle to compare.
39
+ * @param b - Second circle to compare.
40
+ * @returns True if the circles are equal, false otherwise.
41
+ */
42
+ export declare function circle2Equals(a: Circle2, b: Circle2): boolean;
43
+ /**
44
+ * Determines whether two 2D circles are within `tolerance` of each other, in
45
+ * centre and radius.
46
+ *
47
+ * Not transitive, so never a basis for ordering or for a set or map key — use
48
+ * {@link circle2Equals} there.
49
+ *
50
+ * @param a - First circle to compare.
51
+ * @param b - Second circle to compare.
52
+ * @param tolerance - Distance, in the caller's own units.
53
+ * @returns True if the circles are close, false otherwise.
54
+ */
55
+ export declare function circle2IsClose(a: Circle2, b: Circle2, tolerance?: number): boolean;
56
+ /**
57
+ * Determines whether two 2D circles intersect.
58
+ *
59
+ * Exact, for the same reason as {@link circle2ContainsPoint}.
60
+ *
61
+ * @param a - First circle to check for intersection.
62
+ * @param b - Second circle to check for intersection.
63
+ * @returns True if the circles intersect, false otherwise.
64
+ */
65
+ export declare function circle2Intersects(a: Circle2, b: Circle2): boolean;
66
+ /**
67
+ * Translates a 2D circle by a given vector.
68
+ *
69
+ * @param c - Circle to translate.
70
+ * @param v - Vector by which to translate the circle.
71
+ * @returns A new Circle2 object representing the translated circle.
72
+ */
73
+ export declare function circle2Translate(c: Circle2, v: Vec2): Circle2;
74
+ //# sourceMappingURL=circle2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"circle2.d.ts","sourceRoot":"","sources":["../src/circle2.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAgB,MAAM,qBAAqB,CAAC;AAIzD,OAAO,EAAE,MAAM,EAAiB,MAAM,aAAa,CAAC;AAEpD,MAAM,MAAM,OAAO,GAAG;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAE9C;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAEvD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAKnE;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAM7D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAC7B,CAAC,EAAE,OAAO,EACV,CAAC,EAAE,OAAO,EACV,SAAS,GAAE,MAA8C,GACvD,OAAO,CAKT;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAQjE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,GAAG,OAAO,CAK7D"}
@@ -0,0 +1,100 @@
1
+ import { isCloseAbsolute } from "@ac-kit/core";
2
+ import { vec2LengthSq } from "@ac-kit/math-linear";
3
+ import { TWO_PI } from "@ac-kit/math-scalar";
4
+ import { geometryConfig } from "./globals.js";
5
+ import { point2IsClose } from "./point2.js";
6
+ /**
7
+ * Calculates the area of a 2D circle.
8
+ *
9
+ * @param c - Circle to calculate area for.
10
+ * @returns Area of the circle.
11
+ */
12
+ export function circle2Area(c) {
13
+ return Math.PI * c.radius * c.radius;
14
+ }
15
+ /**
16
+ * Calculates the circumference of a 2D circle.
17
+ *
18
+ * @param c - Circle to calculate circumference for.
19
+ * @returns Circumference of the circle.
20
+ */
21
+ export function circle2Circumference(c) {
22
+ return TWO_PI * c.radius;
23
+ }
24
+ /**
25
+ * Determines whether a point is inside or on the boundary of a 2D circle.
26
+ *
27
+ * Exact: the boundary is measure-zero, so a tolerance would only move it by an
28
+ * arbitrary amount. For deliberate slack, inflate `c.radius` — a length, unlike
29
+ * an epsilon on the squared distance compared here.
30
+ *
31
+ * @param c - Circle to check against.
32
+ * @param p - Point to check.
33
+ * @returns True if the point is inside or on the boundary of the circle, false
34
+ * otherwise.
35
+ */
36
+ export function circle2ContainsPoint(c, p) {
37
+ const distSq = vec2LengthSq([p.x - c.center.x, p.y - c.center.y]);
38
+ const radSq = c.radius * c.radius;
39
+ return distSq <= radSq;
40
+ }
41
+ /**
42
+ * Determines whether two 2D circles are equal, considering their centers and
43
+ * radii.
44
+ *
45
+ * @param a - First circle to compare.
46
+ * @param b - Second circle to compare.
47
+ * @returns True if the circles are equal, false otherwise.
48
+ */
49
+ export function circle2Equals(a, b) {
50
+ return (a.center.x === b.center.x &&
51
+ a.center.y === b.center.y &&
52
+ a.radius === b.radius);
53
+ }
54
+ /**
55
+ * Determines whether two 2D circles are within `tolerance` of each other, in
56
+ * centre and radius.
57
+ *
58
+ * Not transitive, so never a basis for ordering or for a set or map key — use
59
+ * {@link circle2Equals} there.
60
+ *
61
+ * @param a - First circle to compare.
62
+ * @param b - Second circle to compare.
63
+ * @param tolerance - Distance, in the caller's own units.
64
+ * @returns True if the circles are close, false otherwise.
65
+ */
66
+ export function circle2IsClose(a, b, tolerance = geometryConfig.defaultLinearTolerance) {
67
+ return (point2IsClose(a.center, b.center, tolerance) &&
68
+ isCloseAbsolute(a.radius, b.radius, tolerance));
69
+ }
70
+ /**
71
+ * Determines whether two 2D circles intersect.
72
+ *
73
+ * Exact, for the same reason as {@link circle2ContainsPoint}.
74
+ *
75
+ * @param a - First circle to check for intersection.
76
+ * @param b - Second circle to check for intersection.
77
+ * @returns True if the circles intersect, false otherwise.
78
+ */
79
+ export function circle2Intersects(a, b) {
80
+ const distSq = vec2LengthSq([
81
+ b.center.x - a.center.x,
82
+ b.center.y - a.center.y,
83
+ ]);
84
+ const radSum = a.radius + b.radius;
85
+ return distSq <= radSum * radSum;
86
+ }
87
+ /**
88
+ * Translates a 2D circle by a given vector.
89
+ *
90
+ * @param c - Circle to translate.
91
+ * @param v - Vector by which to translate the circle.
92
+ * @returns A new Circle2 object representing the translated circle.
93
+ */
94
+ export function circle2Translate(c, v) {
95
+ return {
96
+ center: { x: c.center.x + v[0], y: c.center.y + v[1] },
97
+ radius: c.radius,
98
+ };
99
+ }
100
+ //# sourceMappingURL=circle2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"circle2.js","sourceRoot":"","sources":["../src/circle2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAQ,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO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CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,SAAS,CAAC,CAC9C,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAAC,CAAU,EAAE,CAAU;IACvD,MAAM,MAAM,GAAG,YAAY,CAAC;QAC3B,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;QACvB,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;KACvB,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IAEnC,OAAO,MAAM,IAAI,MAAM,GAAG,MAAM,CAAC;AAClC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,CAAU,EAAE,CAAO;IACnD,OAAO;QACN,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE;QACtD,MAAM,EAAE,CAAC,CAAC,MAAM;KAChB,CAAC;AACH,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { Vec2 } from "@ac-kit/math-linear";
2
+ import { Point2 } from "./point2.js";
3
+ import { Rect2 } from "./rect2.js";
4
+ import { Size2 } from "./size2.js";
5
+ /**
6
+ * Converts a point in pixel coordinates to normalized device coordinates (NDC).
7
+ *
8
+ * @param p The point in pixel coordinates.
9
+ * @param viewport The size of the viewport in pixels.
10
+ * @returns The point in NDC, where x and y are in the range [-1, 1].
11
+ */
12
+ export declare function point2ToNdc(p: Point2, viewport: Size2): Vec2;
13
+ /**
14
+ * Converts a point in normalized device coordinates (NDC) to pixel coordinates.
15
+ *
16
+ * @param ndc The point in NDC, where x and y are in the range [-1, 1].
17
+ * @param viewport The size of the viewport in pixels.
18
+ * @returns The point in pixel coordinates.
19
+ */
20
+ export declare function ndcToPoint2(ndc: Vec2, viewport: Size2): Point2;
21
+ /**
22
+ * Converts a point in pixel coordinates to UV coordinates relative to a given
23
+ * rectangle.
24
+ *
25
+ * @param p The point in pixel coordinates.
26
+ * @param rect The rectangle defining the UV space.
27
+ * @returns The point in UV coordinates, where x and y are in the range [0, 1].
28
+ */
29
+ export declare function point2ToUv(p: Point2, rect: Rect2): Vec2;
30
+ /**
31
+ * Converts UV coordinates to a point in pixel coordinates relative to a given
32
+ * rectangle.
33
+ *
34
+ * @param uv The UV coordinates, where x and y are in the range [0, 1].
35
+ * @param rect The rectangle defining the UV space.
36
+ * @returns The point in pixel coordinates.
37
+ */
38
+ export declare function uvToPoint2(uv: Vec2, rect: Rect2): Point2;
39
+ //# sourceMappingURL=coordinate-spaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coordinate-spaces.d.ts","sourceRoot":"","sources":["../src/coordinate-spaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,GAAG,IAAI,CAE5D;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,GAAG,MAAM,CAK9D;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,GAAG,IAAI,CAKvD;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,GAAG,MAAM,CAKxD"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Converts a point in pixel coordinates to normalized device coordinates (NDC).
3
+ *
4
+ * @param p The point in pixel coordinates.
5
+ * @param viewport The size of the viewport in pixels.
6
+ * @returns The point in NDC, where x and y are in the range [-1, 1].
7
+ */
8
+ export function point2ToNdc(p, viewport) {
9
+ return [(p.x / viewport.width) * 2 - 1, 1 - (p.y / viewport.height) * 2];
10
+ }
11
+ /**
12
+ * Converts a point in normalized device coordinates (NDC) to pixel coordinates.
13
+ *
14
+ * @param ndc The point in NDC, where x and y are in the range [-1, 1].
15
+ * @param viewport The size of the viewport in pixels.
16
+ * @returns The point in pixel coordinates.
17
+ */
18
+ export function ndcToPoint2(ndc, viewport) {
19
+ return {
20
+ x: ((ndc[0] + 1) / 2) * viewport.width,
21
+ y: ((1 - ndc[1]) / 2) * viewport.height,
22
+ };
23
+ }
24
+ /**
25
+ * Converts a point in pixel coordinates to UV coordinates relative to a given
26
+ * rectangle.
27
+ *
28
+ * @param p The point in pixel coordinates.
29
+ * @param rect The rectangle defining the UV space.
30
+ * @returns The point in UV coordinates, where x and y are in the range [0, 1].
31
+ */
32
+ export function point2ToUv(p, rect) {
33
+ return [
34
+ (p.x - rect.origin.x) / rect.size.width,
35
+ (p.y - rect.origin.y) / rect.size.height,
36
+ ];
37
+ }
38
+ /**
39
+ * Converts UV coordinates to a point in pixel coordinates relative to a given
40
+ * rectangle.
41
+ *
42
+ * @param uv The UV coordinates, where x and y are in the range [0, 1].
43
+ * @param rect The rectangle defining the UV space.
44
+ * @returns The point in pixel coordinates.
45
+ */
46
+ export function uvToPoint2(uv, rect) {
47
+ return {
48
+ x: uv[0] * rect.size.width + rect.origin.x,
49
+ y: uv[1] * rect.size.height + rect.origin.y,
50
+ };
51
+ }
52
+ //# sourceMappingURL=coordinate-spaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coordinate-spaces.js","sourceRoot":"","sources":["../src/coordinate-spaces.ts"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