@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.
- package/CHANGELOG.md +7 -0
- package/LICENSE +28 -0
- package/README.md +86 -0
- package/dist/angles.d.ts +31 -0
- package/dist/angles.d.ts.map +1 -0
- package/dist/angles.js +53 -0
- package/dist/angles.js.map +1 -0
- package/dist/box3.d.ts +17 -0
- package/dist/box3.d.ts.map +1 -0
- package/dist/box3.js +82 -0
- package/dist/box3.js.map +1 -0
- package/dist/box4.d.ts +9 -0
- package/dist/box4.d.ts.map +1 -0
- package/dist/box4.js +7 -0
- package/dist/box4.js.map +1 -0
- package/dist/circle2.d.ts +74 -0
- package/dist/circle2.d.ts.map +1 -0
- package/dist/circle2.js +100 -0
- package/dist/circle2.js.map +1 -0
- package/dist/coordinate-spaces.d.ts +39 -0
- package/dist/coordinate-spaces.d.ts.map +1 -0
- package/dist/coordinate-spaces.js +52 -0
- package/dist/coordinate-spaces.js.map +1 -0
- package/dist/coordinates-vec2.d.ts +7 -0
- package/dist/coordinates-vec2.d.ts.map +1 -0
- package/dist/coordinates-vec2.js +35 -0
- package/dist/coordinates-vec2.js.map +1 -0
- package/dist/coordinates-vec3.d.ts +11 -0
- package/dist/coordinates-vec3.d.ts.map +1 -0
- package/dist/coordinates-vec3.js +61 -0
- package/dist/coordinates-vec3.js.map +1 -0
- package/dist/coordinates.d.ts +54 -0
- package/dist/coordinates.d.ts.map +1 -0
- package/dist/coordinates.js +2 -0
- package/dist/coordinates.js.map +1 -0
- package/dist/euler-angles-quaternion.d.ts +7 -0
- package/dist/euler-angles-quaternion.d.ts.map +1 -0
- package/dist/euler-angles-quaternion.js +100 -0
- package/dist/euler-angles-quaternion.js.map +1 -0
- package/dist/euler-angles.d.ts +33 -0
- package/dist/euler-angles.d.ts.map +1 -0
- package/dist/euler-angles.js +35 -0
- package/dist/euler-angles.js.map +1 -0
- package/dist/geometry-vectors.d.ts +11 -0
- package/dist/geometry-vectors.d.ts.map +1 -0
- package/dist/geometry-vectors.js +19 -0
- package/dist/geometry-vectors.js.map +1 -0
- package/dist/globals.d.ts +47 -0
- package/dist/globals.d.ts.map +1 -0
- package/dist/globals.js +29 -0
- package/dist/globals.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/line2.d.ts +43 -0
- package/dist/line2.d.ts.map +1 -0
- package/dist/line2.js +68 -0
- package/dist/line2.js.map +1 -0
- package/dist/line3.d.ts +30 -0
- package/dist/line3.d.ts.map +1 -0
- package/dist/line3.js +46 -0
- package/dist/line3.js.map +1 -0
- package/dist/mesh3.d.ts +32 -0
- package/dist/mesh3.d.ts.map +1 -0
- package/dist/mesh3.js +142 -0
- package/dist/mesh3.js.map +1 -0
- package/dist/plane3.d.ts +38 -0
- package/dist/plane3.d.ts.map +1 -0
- package/dist/plane3.js +60 -0
- package/dist/plane3.js.map +1 -0
- package/dist/point2.d.ts +41 -0
- package/dist/point2.d.ts.map +1 -0
- package/dist/point2.js +92 -0
- package/dist/point2.js.map +1 -0
- package/dist/point3.d.ts +43 -0
- package/dist/point3.d.ts.map +1 -0
- package/dist/point3.js +103 -0
- package/dist/point3.js.map +1 -0
- package/dist/point4.d.ts +12 -0
- package/dist/point4.d.ts.map +1 -0
- package/dist/point4.js +28 -0
- package/dist/point4.js.map +1 -0
- package/dist/polygon2.d.ts +30 -0
- package/dist/polygon2.d.ts.map +1 -0
- package/dist/polygon2.js +127 -0
- package/dist/polygon2.js.map +1 -0
- package/dist/polygon3.d.ts +28 -0
- package/dist/polygon3.d.ts.map +1 -0
- package/dist/polygon3.js +112 -0
- package/dist/polygon3.js.map +1 -0
- package/dist/ray2.d.ts +14 -0
- package/dist/ray2.d.ts.map +1 -0
- package/dist/ray2.js +27 -0
- package/dist/ray2.js.map +1 -0
- package/dist/ray3.d.ts +30 -0
- package/dist/ray3.d.ts.map +1 -0
- package/dist/ray3.js +81 -0
- package/dist/ray3.js.map +1 -0
- package/dist/rect2.d.ts +54 -0
- package/dist/rect2.d.ts.map +1 -0
- package/dist/rect2.js +149 -0
- package/dist/rect2.js.map +1 -0
- package/dist/segment2.d.ts +24 -0
- package/dist/segment2.d.ts.map +1 -0
- package/dist/segment2.js +55 -0
- package/dist/segment2.js.map +1 -0
- package/dist/segment3.d.ts +13 -0
- package/dist/segment3.d.ts.map +1 -0
- package/dist/segment3.js +33 -0
- package/dist/segment3.js.map +1 -0
- package/dist/size2.d.ts +33 -0
- package/dist/size2.d.ts.map +1 -0
- package/dist/size2.js +81 -0
- package/dist/size2.js.map +1 -0
- package/dist/size3.d.ts +21 -0
- package/dist/size3.d.ts.map +1 -0
- package/dist/size3.js +59 -0
- package/dist/size3.js.map +1 -0
- package/dist/size4.d.ts +10 -0
- package/dist/size4.d.ts.map +1 -0
- package/dist/size4.js +16 -0
- package/dist/size4.js.map +1 -0
- package/dist/sphere3.d.ts +13 -0
- package/dist/sphere3.d.ts.map +1 -0
- package/dist/sphere3.js +26 -0
- package/dist/sphere3.js.map +1 -0
- package/dist/triangle2.d.ts +17 -0
- package/dist/triangle2.d.ts.map +1 -0
- package/dist/triangle2.js +31 -0
- package/dist/triangle2.js.map +1 -0
- package/dist/triangle3.d.ts +20 -0
- package/dist/triangle3.d.ts.map +1 -0
- package/dist/triangle3.js +43 -0
- package/dist/triangle3.js.map +1 -0
- package/package.json +67 -0
package/dist/line2.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Vec2 } from "@ac-kit/math-linear";
|
|
2
|
+
import { Point2 } from "./point2.js";
|
|
3
|
+
export type Line2 = {
|
|
4
|
+
point: Point2;
|
|
5
|
+
direction: Vec2;
|
|
6
|
+
};
|
|
7
|
+
/** Returns the closest point on the infinite line to `p`. */
|
|
8
|
+
export declare function line2ClosestPoint(line: Line2, p: Point2): Point2;
|
|
9
|
+
/**
|
|
10
|
+
* Whether `p` lies on `line`, within `tolerance` of it.
|
|
11
|
+
*
|
|
12
|
+
* Tolerant by necessity: a line has zero area, so no constructed point ever
|
|
13
|
+
* lands on one exactly. `tolerance` is a distance in the caller's own units.
|
|
14
|
+
*/
|
|
15
|
+
export declare function line2ContainsPoint(line: Line2, p: Point2, tolerance?: number): boolean;
|
|
16
|
+
export declare function line2DistanceToPoint(line: Line2, p: Point2): number;
|
|
17
|
+
/**
|
|
18
|
+
* Whether `a` and `b` are the same infinite line, within tolerance.
|
|
19
|
+
*
|
|
20
|
+
* Tolerant rather than exact: the same line can be built from any point on it
|
|
21
|
+
* and any scaling of its direction, so exact component equality would answer a
|
|
22
|
+
* question nobody is asking. Directions are compared through their normalised
|
|
23
|
+
* dot product, and opposite directions denote the same line.
|
|
24
|
+
*
|
|
25
|
+
* @param linearTolerance - Distance, in the caller's units, within which a
|
|
26
|
+
* point still counts as lying on the other line.
|
|
27
|
+
* @param angularTolerance - Dimensionless residual on `|dot| - 1`, within which
|
|
28
|
+
* two unit directions still count as collinear.
|
|
29
|
+
*/
|
|
30
|
+
export declare function line2Equals(a: Line2, b: Line2, linearTolerance?: number, angularTolerance?: number): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Returns the intersection point of two infinite lines, or `null` if they are
|
|
33
|
+
* parallel.
|
|
34
|
+
*
|
|
35
|
+
* The parallel test scales the cross product by both direction lengths, so it
|
|
36
|
+
* is an angular threshold rather than a raw one — rescaling either direction
|
|
37
|
+
* leaves the answer unchanged, which a bare bound on `denom` would not.
|
|
38
|
+
*
|
|
39
|
+
* @param tolerance - Dimensionless bound on `sin` of the angle between the two
|
|
40
|
+
* directions, below which they count as parallel.
|
|
41
|
+
*/
|
|
42
|
+
export declare function line2Intersect(a: Line2, b: Line2, tolerance?: number): Point2 | null;
|
|
43
|
+
//# sourceMappingURL=line2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line2.d.ts","sourceRoot":"","sources":["../src/line2.ts"],"names":[],"mappings":"AACA,OAAO,EACN,IAAI,EAKJ,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,MAAM,KAAK,GAAG;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,IAAI,CAAC;CAChB,CAAC;AAEF,6DAA6D;AAC7D,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAKhE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CACjC,IAAI,EAAE,KAAK,EACX,CAAC,EAAE,MAAM,EACT,SAAS,GAAE,MAA8C,GACvD,OAAO,CAET;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAInE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAC1B,CAAC,EAAE,KAAK,EACR,CAAC,EAAE,KAAK,EACR,eAAe,GAAE,MAA8C,EAC/D,gBAAgB,GAAE,MAA+C,GAC/D,OAAO,CAOT;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC7B,CAAC,EAAE,KAAK,EACR,CAAC,EAAE,KAAK,EACR,SAAS,GAAE,MAA+C,GACxD,MAAM,GAAG,IAAI,CAcf"}
|
package/dist/line2.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { isCloseAbsolute } from "@ac-kit/core";
|
|
2
|
+
import { vec2Cross, vec2Dot, vec2Length, vec2Normalize, } from "@ac-kit/math-linear";
|
|
3
|
+
import { diffOfProducts } from "@ac-kit/math-scalar";
|
|
4
|
+
import { geometryConfig } from "./globals.js";
|
|
5
|
+
/** Returns the closest point on the infinite line to `p`. */
|
|
6
|
+
export function line2ClosestPoint(line, p) {
|
|
7
|
+
const d = vec2Normalize(line.direction);
|
|
8
|
+
const v = [p.x - line.point.x, p.y - line.point.y];
|
|
9
|
+
const t = vec2Dot(v, d);
|
|
10
|
+
return { x: line.point.x + d[0] * t, y: line.point.y + d[1] * t };
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Whether `p` lies on `line`, within `tolerance` of it.
|
|
14
|
+
*
|
|
15
|
+
* Tolerant by necessity: a line has zero area, so no constructed point ever
|
|
16
|
+
* lands on one exactly. `tolerance` is a distance in the caller's own units.
|
|
17
|
+
*/
|
|
18
|
+
export function line2ContainsPoint(line, p, tolerance = geometryConfig.defaultLinearTolerance) {
|
|
19
|
+
return line2DistanceToPoint(line, p) <= tolerance;
|
|
20
|
+
}
|
|
21
|
+
export function line2DistanceToPoint(line, p) {
|
|
22
|
+
const d = vec2Normalize(line.direction);
|
|
23
|
+
const v = [p.x - line.point.x, p.y - line.point.y];
|
|
24
|
+
return Math.abs(vec2Cross(v, d));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Whether `a` and `b` are the same infinite line, within tolerance.
|
|
28
|
+
*
|
|
29
|
+
* Tolerant rather than exact: the same line can be built from any point on it
|
|
30
|
+
* and any scaling of its direction, so exact component equality would answer a
|
|
31
|
+
* question nobody is asking. Directions are compared through their normalised
|
|
32
|
+
* dot product, and opposite directions denote the same line.
|
|
33
|
+
*
|
|
34
|
+
* @param linearTolerance - Distance, in the caller's units, within which a
|
|
35
|
+
* point still counts as lying on the other line.
|
|
36
|
+
* @param angularTolerance - Dimensionless residual on `|dot| - 1`, within which
|
|
37
|
+
* two unit directions still count as collinear.
|
|
38
|
+
*/
|
|
39
|
+
export function line2Equals(a, b, linearTolerance = geometryConfig.defaultLinearTolerance, angularTolerance = geometryConfig.defaultAngularTolerance) {
|
|
40
|
+
const dot = vec2Dot(vec2Normalize(a.direction), vec2Normalize(b.direction));
|
|
41
|
+
return (isCloseAbsolute(Math.abs(dot), 1, angularTolerance) &&
|
|
42
|
+
line2ContainsPoint(a, b.point, linearTolerance));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Returns the intersection point of two infinite lines, or `null` if they are
|
|
46
|
+
* parallel.
|
|
47
|
+
*
|
|
48
|
+
* The parallel test scales the cross product by both direction lengths, so it
|
|
49
|
+
* is an angular threshold rather than a raw one — rescaling either direction
|
|
50
|
+
* leaves the answer unchanged, which a bare bound on `denom` would not.
|
|
51
|
+
*
|
|
52
|
+
* @param tolerance - Dimensionless bound on `sin` of the angle between the two
|
|
53
|
+
* directions, below which they count as parallel.
|
|
54
|
+
*/
|
|
55
|
+
export function line2Intersect(a, b, tolerance = geometryConfig.defaultAngularTolerance) {
|
|
56
|
+
const [dx1, dy1] = a.direction;
|
|
57
|
+
const [dx2, dy2] = b.direction;
|
|
58
|
+
const denom = diffOfProducts(dx1, dy2, dy1, dx2);
|
|
59
|
+
const scale = vec2Length(a.direction) * vec2Length(b.direction);
|
|
60
|
+
if (Math.abs(denom) <= tolerance * scale) {
|
|
61
|
+
return null; // parallel, or a degenerate zero-length direction
|
|
62
|
+
}
|
|
63
|
+
const dx = b.point.x - a.point.x;
|
|
64
|
+
const dy = b.point.y - a.point.y;
|
|
65
|
+
const t = diffOfProducts(dx, dy2, dy, dx2) / denom;
|
|
66
|
+
return { x: a.point.x + dx1 * t, y: a.point.y + dy1 * t };
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=line2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line2.js","sourceRoot":"","sources":["../src/line2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAEN,SAAS,EACT,OAAO,EACP,UAAU,EACV,aAAa,GACb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAQ9C,6DAA6D;AAC7D,MAAM,UAAU,iBAAiB,CAAC,IAAW,EAAE,CAAS;IACvD,MAAM,CAAC,GAAG,aAAa,CAAC,IAAI,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AAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,EAAE,CAAC;AAC3D,CAAC"}
|
package/dist/line3.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Vec3 } from "@ac-kit/math-linear";
|
|
2
|
+
import { Point3 } from "./point3.js";
|
|
3
|
+
export type Line3 = {
|
|
4
|
+
point: Point3;
|
|
5
|
+
direction: Vec3;
|
|
6
|
+
};
|
|
7
|
+
/** Returns the closest point on the infinite line to `p`. */
|
|
8
|
+
export declare function line3ClosestPoint(line: Line3, p: Point3): Point3;
|
|
9
|
+
/**
|
|
10
|
+
* Whether `p` lies on `line`, within `tolerance` of it.
|
|
11
|
+
*
|
|
12
|
+
* Tolerant by necessity: a line has zero volume, so no constructed point ever
|
|
13
|
+
* lands on one exactly. `tolerance` is a distance in the caller's own units.
|
|
14
|
+
*/
|
|
15
|
+
export declare function line3ContainsPoint(line: Line3, p: Point3, tolerance?: number): boolean;
|
|
16
|
+
export declare function line3DistanceToPoint(line: Line3, p: Point3): number;
|
|
17
|
+
/**
|
|
18
|
+
* Whether `a` and `b` are the same infinite line, within tolerance.
|
|
19
|
+
*
|
|
20
|
+
* Tolerant rather than exact, for the same reason as `line2Equals`: the same
|
|
21
|
+
* line can be built from any point on it and any scaling of its direction.
|
|
22
|
+
* Opposite directions denote the same line.
|
|
23
|
+
*
|
|
24
|
+
* @param linearTolerance - Distance, in the caller's units, within which a
|
|
25
|
+
* point still counts as lying on the other line.
|
|
26
|
+
* @param angularTolerance - Dimensionless residual on `|dot| - 1`, within which
|
|
27
|
+
* two unit directions still count as collinear.
|
|
28
|
+
*/
|
|
29
|
+
export declare function line3Equals(a: Line3, b: Line3, linearTolerance?: number, angularTolerance?: number): boolean;
|
|
30
|
+
//# sourceMappingURL=line3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line3.d.ts","sourceRoot":"","sources":["../src/line3.ts"],"names":[],"mappings":"AACA,OAAO,EACN,IAAI,EAKJ,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,MAAM,KAAK,GAAG;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,IAAI,CAAC;CAChB,CAAC;AAEF,6DAA6D;AAC7D,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAShE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CACjC,IAAI,EAAE,KAAK,EACX,CAAC,EAAE,MAAM,EACT,SAAS,GAAE,MAA8C,GACvD,OAAO,CAET;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAInE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAC1B,CAAC,EAAE,KAAK,EACR,CAAC,EAAE,KAAK,EACR,eAAe,GAAE,MAA8C,EAC/D,gBAAgB,GAAE,MAA+C,GAC/D,OAAO,CAOT"}
|
package/dist/line3.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { isCloseAbsolute } from "@ac-kit/core";
|
|
2
|
+
import { vec3Cross, vec3Dot, vec3Length, vec3Normalize, } from "@ac-kit/math-linear";
|
|
3
|
+
import { geometryConfig } from "./globals.js";
|
|
4
|
+
/** Returns the closest point on the infinite line to `p`. */
|
|
5
|
+
export function line3ClosestPoint(line, p) {
|
|
6
|
+
const d = vec3Normalize(line.direction);
|
|
7
|
+
const v = [p.x - line.point.x, p.y - line.point.y, p.z - line.point.z];
|
|
8
|
+
const t = vec3Dot(v, d);
|
|
9
|
+
return {
|
|
10
|
+
x: line.point.x + d[0] * t,
|
|
11
|
+
y: line.point.y + d[1] * t,
|
|
12
|
+
z: line.point.z + d[2] * t,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Whether `p` lies on `line`, within `tolerance` of it.
|
|
17
|
+
*
|
|
18
|
+
* Tolerant by necessity: a line has zero volume, so no constructed point ever
|
|
19
|
+
* lands on one exactly. `tolerance` is a distance in the caller's own units.
|
|
20
|
+
*/
|
|
21
|
+
export function line3ContainsPoint(line, p, tolerance = geometryConfig.defaultLinearTolerance) {
|
|
22
|
+
return line3DistanceToPoint(line, p) <= tolerance;
|
|
23
|
+
}
|
|
24
|
+
export function line3DistanceToPoint(line, p) {
|
|
25
|
+
const d = vec3Normalize(line.direction);
|
|
26
|
+
const v = [p.x - line.point.x, p.y - line.point.y, p.z - line.point.z];
|
|
27
|
+
return vec3Length(vec3Cross(v, d));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Whether `a` and `b` are the same infinite line, within tolerance.
|
|
31
|
+
*
|
|
32
|
+
* Tolerant rather than exact, for the same reason as `line2Equals`: the same
|
|
33
|
+
* line can be built from any point on it and any scaling of its direction.
|
|
34
|
+
* Opposite directions denote the same line.
|
|
35
|
+
*
|
|
36
|
+
* @param linearTolerance - Distance, in the caller's units, within which a
|
|
37
|
+
* point still counts as lying on the other line.
|
|
38
|
+
* @param angularTolerance - Dimensionless residual on `|dot| - 1`, within which
|
|
39
|
+
* two unit directions still count as collinear.
|
|
40
|
+
*/
|
|
41
|
+
export function line3Equals(a, b, linearTolerance = geometryConfig.defaultLinearTolerance, angularTolerance = geometryConfig.defaultAngularTolerance) {
|
|
42
|
+
const dot = vec3Dot(vec3Normalize(a.direction), vec3Normalize(b.direction));
|
|
43
|
+
return (isCloseAbsolute(Math.abs(dot), 1, angularTolerance) &&
|
|
44
|
+
line3ContainsPoint(a, b.point, linearTolerance));
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=line3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line3.js","sourceRoot":"","sources":["../src/line3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CA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K,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC7E,OAAO,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACpC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CAC1B,CAAQ,EACR,CAAQ,EACR,eAAe,GAAW,cAAc,CAAC,sBAAsB,EAC/D,gBAAgB,GAAW,cAAc,CAAC,uBAAuB;IAEjE,MAAM,GAAG,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAE5E,OAAO,CACN,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,gBAAgB,CAAC;QACnD,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,eAAe,CAAC,CAC/C,CAAC;AACH,CAAC"}
|
package/dist/mesh3.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Vec3 } from "@ac-kit/math-linear";
|
|
2
|
+
import { Box3 } from "./box3.js";
|
|
3
|
+
import { Point3 } from "./point3.js";
|
|
4
|
+
import { Triangle3 } from "./triangle3.js";
|
|
5
|
+
/**
|
|
6
|
+
* Indexed triangle mesh. Vertices are stored once; faces reference them by
|
|
7
|
+
* index (CCW winding). Maps directly to a GPU vertex buffer + index buffer
|
|
8
|
+
* pair.
|
|
9
|
+
*/
|
|
10
|
+
export type Mesh3 = {
|
|
11
|
+
vertices: readonly Point3[];
|
|
12
|
+
faces: ReadonlyArray<readonly [number, number, number]>;
|
|
13
|
+
};
|
|
14
|
+
export declare function mesh3VertexCount(m: Mesh3): number;
|
|
15
|
+
export declare function mesh3FaceCount(m: Mesh3): number;
|
|
16
|
+
export declare function mesh3FaceTriangle(m: Mesh3, faceIndex: number): Triangle3;
|
|
17
|
+
export declare function mesh3FaceNormal(m: Mesh3, faceIndex: number): Vec3;
|
|
18
|
+
/**
|
|
19
|
+
* Computes per-vertex smooth normals by accumulating area-weighted face normals
|
|
20
|
+
* and normalizing. Returns one unit normal per vertex, in the same order as
|
|
21
|
+
* `m.vertices`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function mesh3VertexNormals(m: Mesh3): Vec3[];
|
|
24
|
+
export declare function mesh3SurfaceArea(m: Mesh3): number;
|
|
25
|
+
export declare function mesh3BoundingBox(m: Mesh3): Box3;
|
|
26
|
+
/**
|
|
27
|
+
* Returns the surface-area-weighted centroid of the mesh. Falls back to the
|
|
28
|
+
* vertex average for degenerate (zero-area) meshes.
|
|
29
|
+
*/
|
|
30
|
+
export declare function mesh3Centroid(m: Mesh3): Point3;
|
|
31
|
+
export declare function mesh3Equals(a: Mesh3, b: Mesh3): boolean;
|
|
32
|
+
//# sourceMappingURL=mesh3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mesh3.d.ts","sourceRoot":"","sources":["../src/mesh3.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAA6B,MAAM,qBAAqB,CAAC;AAEtE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAgB,MAAM,aAAa,CAAC;AACnD,OAAO,EACN,SAAS,EAIT,MAAM,gBAAgB,CAAC;AAExB;;;;GAIG;AACH,MAAM,MAAM,KAAK,GAAG;IACnB,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACxD,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,KAAK,GAAG,MAAM,CAEjD;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,KAAK,GAAG,MAAM,CAE/C;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,GAAG,SAAS,CAOxE;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAEjE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,KAAK,GAAG,IAAI,EAAE,CAqBnD;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,KAAK,GAAG,MAAM,CAUjD;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,KAAK,GAAG,IAAI,CAmB/C;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,GAAG,MAAM,CAoC9C;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,GAAG,OAAO,CAoBvD"}
|
package/dist/mesh3.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { PreciseSum } from "@ac-kit/core";
|
|
2
|
+
import { vec3Length, vec3Normalize } from "@ac-kit/math-linear";
|
|
3
|
+
import { point3Equals } from "./point3.js";
|
|
4
|
+
import { triangle3Area, triangle3Centroid, triangle3Normal, } from "./triangle3.js";
|
|
5
|
+
export function mesh3VertexCount(m) {
|
|
6
|
+
return m.vertices.length;
|
|
7
|
+
}
|
|
8
|
+
export function mesh3FaceCount(m) {
|
|
9
|
+
return m.faces.length;
|
|
10
|
+
}
|
|
11
|
+
export function mesh3FaceTriangle(m, faceIndex) {
|
|
12
|
+
const face = m.faces[faceIndex];
|
|
13
|
+
return {
|
|
14
|
+
a: m.vertices[face[0]],
|
|
15
|
+
b: m.vertices[face[1]],
|
|
16
|
+
c: m.vertices[face[2]],
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function mesh3FaceNormal(m, faceIndex) {
|
|
20
|
+
return triangle3Normal(mesh3FaceTriangle(m, faceIndex));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Computes per-vertex smooth normals by accumulating area-weighted face normals
|
|
24
|
+
* and normalizing. Returns one unit normal per vertex, in the same order as
|
|
25
|
+
* `m.vertices`.
|
|
26
|
+
*/
|
|
27
|
+
export function mesh3VertexNormals(m) {
|
|
28
|
+
const accumulated = m.vertices.map(() => [0, 0, 0]);
|
|
29
|
+
for (const face of m.faces) {
|
|
30
|
+
const tri = {
|
|
31
|
+
a: m.vertices[face[0]],
|
|
32
|
+
b: m.vertices[face[1]],
|
|
33
|
+
c: m.vertices[face[2]],
|
|
34
|
+
};
|
|
35
|
+
const area = triangle3Area(tri);
|
|
36
|
+
const n = triangle3Normal(tri);
|
|
37
|
+
for (const idx of face) {
|
|
38
|
+
const acc = accumulated[idx];
|
|
39
|
+
acc[0] += n[0] * area;
|
|
40
|
+
acc[1] += n[1] * area;
|
|
41
|
+
acc[2] += n[2] * area;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return accumulated.map((n) => {
|
|
45
|
+
const len = vec3Length(n);
|
|
46
|
+
return len > 0 ? vec3Normalize(n) : [0, 1, 0];
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
export function mesh3SurfaceArea(m) {
|
|
50
|
+
let area = 0;
|
|
51
|
+
for (const face of m.faces) {
|
|
52
|
+
area += triangle3Area({
|
|
53
|
+
a: m.vertices[face[0]],
|
|
54
|
+
b: m.vertices[face[1]],
|
|
55
|
+
c: m.vertices[face[2]],
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return area;
|
|
59
|
+
}
|
|
60
|
+
export function mesh3BoundingBox(m) {
|
|
61
|
+
let minX = Infinity, minY = Infinity, minZ = Infinity;
|
|
62
|
+
let maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
|
|
63
|
+
for (const v of m.vertices) {
|
|
64
|
+
if (v.x < minX)
|
|
65
|
+
minX = v.x;
|
|
66
|
+
if (v.y < minY)
|
|
67
|
+
minY = v.y;
|
|
68
|
+
if (v.z < minZ)
|
|
69
|
+
minZ = v.z;
|
|
70
|
+
if (v.x > maxX)
|
|
71
|
+
maxX = v.x;
|
|
72
|
+
if (v.y > maxY)
|
|
73
|
+
maxY = v.y;
|
|
74
|
+
if (v.z > maxZ)
|
|
75
|
+
maxZ = v.z;
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
origin: { x: minX, y: minY, z: minZ },
|
|
79
|
+
size: { width: maxX - minX, height: maxY - minY, depth: maxZ - minZ },
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Returns the surface-area-weighted centroid of the mesh. Falls back to the
|
|
84
|
+
* vertex average for degenerate (zero-area) meshes.
|
|
85
|
+
*/
|
|
86
|
+
export function mesh3Centroid(m) {
|
|
87
|
+
const cx = new PreciseSum();
|
|
88
|
+
const cy = new PreciseSum();
|
|
89
|
+
const cz = new PreciseSum();
|
|
90
|
+
const area = new PreciseSum();
|
|
91
|
+
for (const face of m.faces) {
|
|
92
|
+
const tri = {
|
|
93
|
+
a: m.vertices[face[0]],
|
|
94
|
+
b: m.vertices[face[1]],
|
|
95
|
+
c: m.vertices[face[2]],
|
|
96
|
+
};
|
|
97
|
+
const triArea = triangle3Area(tri);
|
|
98
|
+
const c = triangle3Centroid(tri);
|
|
99
|
+
cx.add(c.x * triArea);
|
|
100
|
+
cy.add(c.y * triArea);
|
|
101
|
+
cz.add(c.z * triArea);
|
|
102
|
+
area.add(triArea);
|
|
103
|
+
}
|
|
104
|
+
const totalArea = area.value;
|
|
105
|
+
if (totalArea === 0) {
|
|
106
|
+
const vx = new PreciseSum();
|
|
107
|
+
const vy = new PreciseSum();
|
|
108
|
+
const vz = new PreciseSum();
|
|
109
|
+
for (const v of m.vertices) {
|
|
110
|
+
vx.add(v.x);
|
|
111
|
+
vy.add(v.y);
|
|
112
|
+
vz.add(v.z);
|
|
113
|
+
}
|
|
114
|
+
const n = m.vertices.length;
|
|
115
|
+
return { x: vx.value / n, y: vy.value / n, z: vz.value / n };
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
x: cx.value / totalArea,
|
|
119
|
+
y: cy.value / totalArea,
|
|
120
|
+
z: cz.value / totalArea,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
export function mesh3Equals(a, b) {
|
|
124
|
+
if (a.vertices.length !== b.vertices.length ||
|
|
125
|
+
a.faces.length !== b.faces.length) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
for (let i = 0; i < a.vertices.length; i++) {
|
|
129
|
+
if (!point3Equals(a.vertices[i], b.vertices[i])) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
for (let i = 0; i < a.faces.length; i++) {
|
|
134
|
+
const fa = a.faces[i];
|
|
135
|
+
const fb = b.faces[i];
|
|
136
|
+
if (fa[0] !== fb[0] || fa[1] !== fb[1] || fa[2] !== fb[2]) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=mesh3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mesh3.js","sourceRoot":"","sources":["../src/mesh3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAQ,UAAU,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGtE,OAAO,EAAU,YAAY,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAEN,aAAa,EACb,iBAAiB,EACjB,eAAe,GACf,MAAM,gBAAgB,CAAC;AAYxB,MAAM,UAAU,gBAAgB,CAAC,CAAQ;IACxC,OAAO,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,CAAQ;IACtC,OAAO,CAAC,CAAC,KAAK,CA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,EAAE,CAAC;YAC3D,OAAO,KAAK,CAAC;QACd,CAAC;IACF,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC"}
|
package/dist/plane3.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Vec3 } from "@ac-kit/math-linear";
|
|
2
|
+
export type Plane3 = {
|
|
3
|
+
/** Unit normal vector pointing away from the plane's surface. */
|
|
4
|
+
normal: Vec3;
|
|
5
|
+
/** Signed distance from the origin to the plane along the normal. */
|
|
6
|
+
distance: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Returns the signed distance from the plane to `p`. Positive if `p` is on the
|
|
10
|
+
* normal side.
|
|
11
|
+
*/
|
|
12
|
+
export declare function plane3DistanceToPoint(plane: Plane3, p: Vec3): number;
|
|
13
|
+
/**
|
|
14
|
+
* Whether `p` lies on `plane`, within `tolerance` of it.
|
|
15
|
+
*
|
|
16
|
+
* Tolerant by necessity: a plane has zero volume, so no constructed point ever
|
|
17
|
+
* lands on one exactly. `tolerance` is a distance in the caller's own units,
|
|
18
|
+
* which is the only form defined here — the signed distance is compared against
|
|
19
|
+
* zero, where a relative or ULP bound degenerates to exact equality.
|
|
20
|
+
*/
|
|
21
|
+
export declare function plane3ContainsPoint(plane: Plane3, p: Vec3, tolerance?: number): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Exact equality of normal and distance.
|
|
24
|
+
*
|
|
25
|
+
* Compares the representation, not the geometry: a plane and its flip describe
|
|
26
|
+
* the same surface but are not equal.
|
|
27
|
+
*/
|
|
28
|
+
export declare function plane3Equals(a: Plane3, b: Plane3): boolean;
|
|
29
|
+
/** Returns a new plane with the normal and distance sign flipped. */
|
|
30
|
+
export declare function plane3Flip(plane: Plane3): Plane3;
|
|
31
|
+
/**
|
|
32
|
+
* Normalizes the plane so that `normal` is a unit vector. If `normal` is
|
|
33
|
+
* already a unit vector, this is a no-op.
|
|
34
|
+
*/
|
|
35
|
+
export declare function plane3Normalize(plane: Plane3): Plane3;
|
|
36
|
+
/** Projects `p` onto the plane (closest point on the plane to `p`). */
|
|
37
|
+
export declare function plane3ProjectPoint(plane: Plane3, p: Vec3): Vec3;
|
|
38
|
+
//# sourceMappingURL=plane3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plane3.d.ts","sourceRoot":"","sources":["../src/plane3.ts"],"names":[],"mappings":"AACA,OAAO,EACN,IAAI,EAMJ,MAAM,qBAAqB,CAAC;AAI7B,MAAM,MAAM,MAAM,GAAG;IACpB,iEAAiE;IACjE,MAAM,EAAE,IAAI,CAAC;IACb,qEAAqE;IACrE,QAAQ,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,GAAG,MAAM,CAEpE;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAClC,KAAK,EAAE,MAAM,EACb,CAAC,EAAE,IAAI,EACP,SAAS,GAAE,MAA8C,GACvD,OAAO,CAET;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAO1D;AAED,qEAAqE;AACrE,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKhD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CASrD;AAED,uEAAuE;AACvE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,GAAG,IAAI,CAG/D"}
|
package/dist/plane3.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { isCloseAbsolute } from "@ac-kit/core";
|
|
2
|
+
import { vec3Dot, vec3Length, vec3MultiplyScalar, vec3Normalize, vec3Sub, } from "@ac-kit/math-linear";
|
|
3
|
+
import { geometryConfig } from "./globals.js";
|
|
4
|
+
/**
|
|
5
|
+
* Returns the signed distance from the plane to `p`. Positive if `p` is on the
|
|
6
|
+
* normal side.
|
|
7
|
+
*/
|
|
8
|
+
export function plane3DistanceToPoint(plane, p) {
|
|
9
|
+
return vec3Dot(plane.normal, p) - plane.distance;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Whether `p` lies on `plane`, within `tolerance` of it.
|
|
13
|
+
*
|
|
14
|
+
* Tolerant by necessity: a plane has zero volume, so no constructed point ever
|
|
15
|
+
* lands on one exactly. `tolerance` is a distance in the caller's own units,
|
|
16
|
+
* which is the only form defined here — the signed distance is compared against
|
|
17
|
+
* zero, where a relative or ULP bound degenerates to exact equality.
|
|
18
|
+
*/
|
|
19
|
+
export function plane3ContainsPoint(plane, p, tolerance = geometryConfig.defaultLinearTolerance) {
|
|
20
|
+
return isCloseAbsolute(plane3DistanceToPoint(plane, p), 0, tolerance);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Exact equality of normal and distance.
|
|
24
|
+
*
|
|
25
|
+
* Compares the representation, not the geometry: a plane and its flip describe
|
|
26
|
+
* the same surface but are not equal.
|
|
27
|
+
*/
|
|
28
|
+
export function plane3Equals(a, b) {
|
|
29
|
+
return (a.normal[0] === b.normal[0] &&
|
|
30
|
+
a.normal[1] === b.normal[1] &&
|
|
31
|
+
a.normal[2] === b.normal[2] &&
|
|
32
|
+
a.distance === b.distance);
|
|
33
|
+
}
|
|
34
|
+
/** Returns a new plane with the normal and distance sign flipped. */
|
|
35
|
+
export function plane3Flip(plane) {
|
|
36
|
+
return {
|
|
37
|
+
normal: [-plane.normal[0], -plane.normal[1], -plane.normal[2]],
|
|
38
|
+
distance: -plane.distance,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Normalizes the plane so that `normal` is a unit vector. If `normal` is
|
|
43
|
+
* already a unit vector, this is a no-op.
|
|
44
|
+
*/
|
|
45
|
+
export function plane3Normalize(plane) {
|
|
46
|
+
const len = vec3Length(plane.normal);
|
|
47
|
+
if (len === 0) {
|
|
48
|
+
throw new Error("Cannot normalize a plane with a zero-length normal.");
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
normal: vec3Normalize(plane.normal),
|
|
52
|
+
distance: plane.distance / len,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** Projects `p` onto the plane (closest point on the plane to `p`). */
|
|
56
|
+
export function plane3ProjectPoint(plane, p) {
|
|
57
|
+
const dist = plane3DistanceToPoint(plane, p);
|
|
58
|
+
return vec3Sub(p, vec3MultiplyScalar(plane.normal, dist));
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=plane3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plane3.js","sourceRoot":"","sources":["../src/plane3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAEN,OAAO,EACP,UAAU,EACV,kBAAkB,EAClB,aAAa,EACb,OAAO,GACP,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAS9C;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAa,EAAE,CAAO;IAC3D,OAAO,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC;AAClD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAClC,KAAa,EACb,CAAO,EACP,SAAS,GAAW,cAAc,CAAC,sBAAsB;IAEzD,OAAO,eAAe,CAAC,qBAAqB,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC;AACvE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,CAAS,EAAE,CAAS;IAChD,OAAO,CACN,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,C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
|
1
|
+
import { type ComparatorResult, type RoundOptions } from "@ac-kit/core";
|
|
2
|
+
import { DistanceType, Vec2 } from "@ac-kit/math-linear";
|
|
3
|
+
export type Point2<T extends bigint | number | string | null = number> = {
|
|
4
|
+
x: T;
|
|
5
|
+
y: T;
|
|
6
|
+
};
|
|
7
|
+
export declare function point2Clamp(p: Point2, min: Point2, max: Point2): Point2;
|
|
8
|
+
export declare function point2DisplacementTo(pA: Point2, pB: Point2): Vec2;
|
|
9
|
+
export declare function point2Distance(pA: Point2, pB: Point2, type?: DistanceType): number;
|
|
10
|
+
/**
|
|
11
|
+
* Exact coordinate equality.
|
|
12
|
+
*
|
|
13
|
+
* Transitive, and therefore the one to use as a set or map key, or to dedupe
|
|
14
|
+
* with. `compare(a, b) === 0` under {@link point2CompareLexicographic} agrees
|
|
15
|
+
* with it exactly. See {@link point2IsClose} for a tolerant test.
|
|
16
|
+
*/
|
|
17
|
+
export declare function point2Equals(pA: Point2, pB: Point2): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Whether both coordinates are within `tolerance` of each other, in the
|
|
20
|
+
* caller's own units.
|
|
21
|
+
*
|
|
22
|
+
* Not transitive, so it is not an equality in the sense a `Set` or `Map` needs,
|
|
23
|
+
* and never a basis for ordering — use {@link point2Equals} there.
|
|
24
|
+
*/
|
|
25
|
+
export declare function point2IsClose(pA: Point2, pB: Point2, tolerance?: number): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Arbitrary but deterministic total order on points, by `x` then `y`.
|
|
28
|
+
*
|
|
29
|
+
* Not a geometric ordering — no such thing exists in the plane. It is the
|
|
30
|
+
* canonical order that sweep-line and hull algorithms sort by, and the way to
|
|
31
|
+
* put points in an ordered container. Exact, so it agrees with
|
|
32
|
+
* {@link point2Equals}.
|
|
33
|
+
*/
|
|
34
|
+
export declare function point2CompareLexicographic(pA: Point2, pB: Point2): ComparatorResult;
|
|
35
|
+
export declare function point2Lerp(pA: Point2, pB: Point2, t: number): Point2;
|
|
36
|
+
export declare function point2Max(pA: Point2, pB: Point2): Point2;
|
|
37
|
+
export declare function point2Midpoint(pA: Point2, pB: Point2): Point2;
|
|
38
|
+
export declare function point2Min(pA: Point2, pB: Point2): Point2;
|
|
39
|
+
export declare function point2Round(p: Point2, options?: RoundOptions): Point2;
|
|
40
|
+
export declare function point2Translate(p: Point2, v: Vec2): Point2;
|
|
41
|
+
//# sourceMappingURL=point2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"point2.d.ts","sourceRoot":"","sources":["../src/point2.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAIzD,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,IAAI;IACxE,CAAC,EAAE,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,CAAC;CACL,CAAC;AAEF,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAKvE;AAED,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAEjE;AAED,wBAAgB,cAAc,CAC7B,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,IAAI,GAAE,YAA0B,GAC9B,MAAM,CAWR;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAE5D;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC5B,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,SAAS,GAAE,MAA8C,GACvD,OAAO,CAKT;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACzC,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,GACR,gBAAgB,CAIlB;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAKpE;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAKxD;AAED,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAK7D;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAKxD;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,MAAM,CAKrE;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,GAAG,MAAM,CAK1D"}
|
package/dist/point2.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { clamp, compareNaturalAscending, isCloseAbsolute, round, } from "@ac-kit/core";
|
|
2
|
+
import { geometryConfig } from "./globals.js";
|
|
3
|
+
export function point2Clamp(p, min, max) {
|
|
4
|
+
return {
|
|
5
|
+
x: clamp(p.x, min.x, max.x),
|
|
6
|
+
y: clamp(p.y, min.y, max.y),
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export function point2DisplacementTo(pA, pB) {
|
|
10
|
+
return [pB.x - pA.x, pB.y - pA.y];
|
|
11
|
+
}
|
|
12
|
+
export function point2Distance(pA, pB, type = "euclidean") {
|
|
13
|
+
const dx = Math.abs(pB.x - pA.x);
|
|
14
|
+
const dy = Math.abs(pB.y - pA.y);
|
|
15
|
+
switch (type) {
|
|
16
|
+
case "manhattan":
|
|
17
|
+
return dx + dy;
|
|
18
|
+
case "chebyshev":
|
|
19
|
+
return Math.max(dx, dy);
|
|
20
|
+
case "euclidean":
|
|
21
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Exact coordinate equality.
|
|
26
|
+
*
|
|
27
|
+
* Transitive, and therefore the one to use as a set or map key, or to dedupe
|
|
28
|
+
* with. `compare(a, b) === 0` under {@link point2CompareLexicographic} agrees
|
|
29
|
+
* with it exactly. See {@link point2IsClose} for a tolerant test.
|
|
30
|
+
*/
|
|
31
|
+
export function point2Equals(pA, pB) {
|
|
32
|
+
return pA.x === pB.x && pA.y === pB.y;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Whether both coordinates are within `tolerance` of each other, in the
|
|
36
|
+
* caller's own units.
|
|
37
|
+
*
|
|
38
|
+
* Not transitive, so it is not an equality in the sense a `Set` or `Map` needs,
|
|
39
|
+
* and never a basis for ordering — use {@link point2Equals} there.
|
|
40
|
+
*/
|
|
41
|
+
export function point2IsClose(pA, pB, tolerance = geometryConfig.defaultLinearTolerance) {
|
|
42
|
+
return (isCloseAbsolute(pA.x, pB.x, tolerance) &&
|
|
43
|
+
isCloseAbsolute(pA.y, pB.y, tolerance));
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Arbitrary but deterministic total order on points, by `x` then `y`.
|
|
47
|
+
*
|
|
48
|
+
* Not a geometric ordering — no such thing exists in the plane. It is the
|
|
49
|
+
* canonical order that sweep-line and hull algorithms sort by, and the way to
|
|
50
|
+
* put points in an ordered container. Exact, so it agrees with
|
|
51
|
+
* {@link point2Equals}.
|
|
52
|
+
*/
|
|
53
|
+
export function point2CompareLexicographic(pA, pB) {
|
|
54
|
+
return (compareNaturalAscending(pA.x, pB.x) || compareNaturalAscending(pA.y, pB.y));
|
|
55
|
+
}
|
|
56
|
+
export function point2Lerp(pA, pB, t) {
|
|
57
|
+
return {
|
|
58
|
+
x: pA.x + (pB.x - pA.x) * t,
|
|
59
|
+
y: pA.y + (pB.y - pA.y) * t,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export function point2Max(pA, pB) {
|
|
63
|
+
return {
|
|
64
|
+
x: Math.max(pA.x, pB.x),
|
|
65
|
+
y: Math.max(pA.y, pB.y),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export function point2Midpoint(pA, pB) {
|
|
69
|
+
return {
|
|
70
|
+
x: (pA.x + pB.x) / 2,
|
|
71
|
+
y: (pA.y + pB.y) / 2,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export function point2Min(pA, pB) {
|
|
75
|
+
return {
|
|
76
|
+
x: Math.min(pA.x, pB.x),
|
|
77
|
+
y: Math.min(pA.y, pB.y),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export function point2Round(p, options) {
|
|
81
|
+
return {
|
|
82
|
+
x: round(p.x, options),
|
|
83
|
+
y: round(p.y, options),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export function point2Translate(p, v) {
|
|
87
|
+
return {
|
|
88
|
+
x: p.x + v[0],
|
|
89
|
+
y: p.y + v[1],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=point2.js.map
|