@thi.ng/geom 6.0.41 → 6.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 +17 -1
- package/README.md +1 -1
- package/intersects.d.ts +22 -3
- package/intersects.js +62 -3
- package/package.json +23 -23
- package/point-at.d.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-03-
|
|
3
|
+
- **Last updated**: 2024-03-21T16:11:49Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,22 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [6.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/geom@6.1.0) (2024-03-21)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- update intersects(), support more shape types ([21ce0d4](https://github.com/thi-ng/umbrella/commit/21ce0d4))
|
|
17
|
+
- add IntersectOpts & as optional arg
|
|
18
|
+
- update impl for ray-poly/ray-polyline
|
|
19
|
+
- add support for new shape pairings:
|
|
20
|
+
- line-polygon
|
|
21
|
+
- line-polyline
|
|
22
|
+
- ray-line
|
|
23
|
+
- ray-group
|
|
24
|
+
- update intersects(), add line-group support ([1e270fa](https://github.com/thi-ng/umbrella/commit/1e270fa))
|
|
25
|
+
- add line-group impl
|
|
26
|
+
- refactor/simplify ray-group impl
|
|
27
|
+
|
|
12
28
|
### [6.0.6](https://github.com/thi-ng/umbrella/tree/@thi.ng/geom@6.0.6) (2023-12-03)
|
|
13
29
|
|
|
14
30
|
#### 🩹 Bug fixes
|
package/README.md
CHANGED
package/intersects.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { MultiFn2O } from "@thi.ng/defmulti";
|
|
2
|
+
import type { IShape, IntersectionResult } from "@thi.ng/geom-api";
|
|
3
|
+
export interface IntersectOpts {
|
|
4
|
+
/**
|
|
5
|
+
* Force returning all intersections, if possible (and supported).
|
|
6
|
+
*/
|
|
7
|
+
all: boolean;
|
|
8
|
+
}
|
|
3
9
|
/**
|
|
4
10
|
* Performs intersection tests on given 2 shapes and returns
|
|
5
11
|
* [`IntersectionResult`](https://docs.thi.ng/umbrella/geom-api/interfaces/IntersectionResult.html).
|
|
@@ -8,10 +14,14 @@ import type { IntersectionResult, IShape } from "@thi.ng/geom-api";
|
|
|
8
14
|
* Currently supported pairs:
|
|
9
15
|
*
|
|
10
16
|
* - {@link Circle} / {@link Circle}
|
|
17
|
+
* - {@link Line} / {@link Group}
|
|
11
18
|
* - {@link Line} / {@link Line}
|
|
19
|
+
* - {@link Line} / {@link Polygon}
|
|
20
|
+
* - {@link Line} / {@link Polyline}
|
|
12
21
|
* - {@link Plane} / {@link Plane}
|
|
13
22
|
* - {@link Ray} / {@link AABB}
|
|
14
23
|
* - {@link Ray} / {@link Circle}
|
|
24
|
+
* - {@link Ray} / {@link Line}
|
|
15
25
|
* - {@link Ray} / {@link Plane}
|
|
16
26
|
* - {@link Ray} / {@link Polygon}
|
|
17
27
|
* - {@link Ray} / {@link Polyline}
|
|
@@ -22,8 +32,17 @@ import type { IntersectionResult, IShape } from "@thi.ng/geom-api";
|
|
|
22
32
|
* - {@link Rect} / {@link Rect}
|
|
23
33
|
* - {@link Sphere} / {@link Sphere}
|
|
24
34
|
*
|
|
35
|
+
* If {@link IntersectOpts.all} is enabled (default: false) and if the
|
|
36
|
+
* intersection pair supports it, all possible intersections will be returned
|
|
37
|
+
* (for some implementations this always the case anyway). Currently, this is
|
|
38
|
+
* option is only implemented for the following pairings:
|
|
39
|
+
*
|
|
40
|
+
* - {@link Ray} / {@link Polygon}
|
|
41
|
+
* - {@link Ray} / {@link Polyline}
|
|
42
|
+
*
|
|
25
43
|
* @param a
|
|
26
44
|
* @param b
|
|
45
|
+
* @param opts
|
|
27
46
|
*/
|
|
28
|
-
export declare const intersects:
|
|
47
|
+
export declare const intersects: MultiFn2O<IShape, IShape, Partial<IntersectOpts>, IntersectionResult>;
|
|
29
48
|
//# sourceMappingURL=intersects.d.ts.map
|
package/intersects.js
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
2
2
|
import { IntersectionType } from "@thi.ng/geom-api/isec";
|
|
3
|
+
import { NONE } from "@thi.ng/geom-isec/api";
|
|
3
4
|
import { intersectCircleCircle } from "@thi.ng/geom-isec/circle-circle";
|
|
4
5
|
import { intersectLineLine } from "@thi.ng/geom-isec/line-line";
|
|
6
|
+
import { intersectLinePolylineAll } from "@thi.ng/geom-isec/line-poly";
|
|
5
7
|
import { intersectPlanePlane } from "@thi.ng/geom-isec/plane-plane";
|
|
6
8
|
import { intersectRayCircle } from "@thi.ng/geom-isec/ray-circle";
|
|
7
9
|
import { intersectRayPlane } from "@thi.ng/geom-isec/ray-plane";
|
|
8
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
intersectRayPolyline,
|
|
12
|
+
intersectRayPolylineAll
|
|
13
|
+
} from "@thi.ng/geom-isec/ray-poly";
|
|
9
14
|
import { intersectRayAABB, intersectRayRect } from "@thi.ng/geom-isec/ray-rect";
|
|
10
15
|
import { testRectCircle } from "@thi.ng/geom-isec/rect-circle";
|
|
11
16
|
import { testAabbAabb, testRectRect } from "@thi.ng/geom-isec/rect-rect";
|
|
17
|
+
import { dist2 } from "@thi.ng/vectors/dist";
|
|
18
|
+
import { distSq2 } from "@thi.ng/vectors/distsq";
|
|
19
|
+
import { magSq2 } from "@thi.ng/vectors/magsq";
|
|
20
|
+
import { normalize2 } from "@thi.ng/vectors/normalize";
|
|
21
|
+
import { sub2 } from "@thi.ng/vectors/sub";
|
|
22
|
+
import { Ray } from "./api/ray.js";
|
|
12
23
|
import { __dispatch2 } from "./internal/dispatch.js";
|
|
13
24
|
const intersects = defmulti(
|
|
14
25
|
__dispatch2,
|
|
15
26
|
{
|
|
27
|
+
"ray-line": "ray-polyline",
|
|
16
28
|
"ray-sphere": "ray-circle",
|
|
17
29
|
"ray-quad": "ray-poly",
|
|
18
30
|
"ray-tri": "ray-poly",
|
|
@@ -23,13 +35,60 @@ const intersects = defmulti(
|
|
|
23
35
|
type: testAabbAabb(a.pos, a.size, b.pos, b.size) ? IntersectionType.INTERSECT : IntersectionType.NONE
|
|
24
36
|
}),
|
|
25
37
|
"circle-circle": (a, b) => intersectCircleCircle(a.pos, b.pos, a.r, b.r),
|
|
38
|
+
"line-group": ({ points: [a, b] }, group, opts) => {
|
|
39
|
+
const dir = sub2([], b, a);
|
|
40
|
+
const max = magSq2(dir);
|
|
41
|
+
const res = intersects(
|
|
42
|
+
new Ray(a, normalize2(null, dir)),
|
|
43
|
+
group,
|
|
44
|
+
opts
|
|
45
|
+
);
|
|
46
|
+
if (res === NONE)
|
|
47
|
+
return res;
|
|
48
|
+
res.isec = res.isec.filter((p) => distSq2(a, p) <= max);
|
|
49
|
+
if (res.isec.length) {
|
|
50
|
+
res.alpha = dist2(a, res.isec[0]);
|
|
51
|
+
return res;
|
|
52
|
+
}
|
|
53
|
+
return NONE;
|
|
54
|
+
},
|
|
26
55
|
"line-line": ({ points: a }, { points: b }) => intersectLineLine(a[0], a[1], b[0], b[1]),
|
|
56
|
+
"line-poly": ({ points: a }, poly) => intersectLinePolylineAll(a[0], a[1], poly.points, true),
|
|
57
|
+
"line-polyline": ({ points: a }, poly) => intersectLinePolylineAll(a[0], a[1], poly.points, false),
|
|
27
58
|
"plane-plane": (a, b) => intersectPlanePlane(a.normal, a.w, b.normal, b.w),
|
|
28
59
|
"ray-aabb": (ray, box) => intersectRayAABB(ray.pos, ray.dir, box.pos, box.max()),
|
|
29
60
|
"ray-circle": (ray, sphere) => intersectRayCircle(ray.pos, ray.dir, sphere.pos, sphere.r),
|
|
61
|
+
"ray-group": (ray, { children }, opts) => {
|
|
62
|
+
let minD = Infinity;
|
|
63
|
+
const points = [];
|
|
64
|
+
const all = opts?.all;
|
|
65
|
+
let inside = false;
|
|
66
|
+
for (let child of children) {
|
|
67
|
+
let $res = intersects(ray, child, opts);
|
|
68
|
+
if ($res.type !== IntersectionType.INTERSECT)
|
|
69
|
+
continue;
|
|
70
|
+
if ($res.inside)
|
|
71
|
+
inside = true;
|
|
72
|
+
const first = $res.isec[0];
|
|
73
|
+
const alpha = $res.alpha !== void 0 ? $res.alpha : dist2(ray.pos, first);
|
|
74
|
+
if (all) {
|
|
75
|
+
points.push(...$res.isec);
|
|
76
|
+
minD = Math.min(minD, alpha);
|
|
77
|
+
} else if (alpha < minD) {
|
|
78
|
+
minD = alpha;
|
|
79
|
+
points[0] = first;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return minD < Infinity ? {
|
|
83
|
+
type: IntersectionType.INTERSECT,
|
|
84
|
+
isec: points,
|
|
85
|
+
alpha: minD,
|
|
86
|
+
inside
|
|
87
|
+
} : NONE;
|
|
88
|
+
},
|
|
30
89
|
"ray-plane": (ray, plane) => intersectRayPlane(ray.pos, ray.dir, plane.normal, plane.w),
|
|
31
|
-
"ray-poly": (ray, poly) => intersectRayPolyline(ray.pos, ray.dir, poly.points, true),
|
|
32
|
-
"ray-polyline": (ray, poly) => intersectRayPolyline(ray.pos, ray.dir, poly.points, false),
|
|
90
|
+
"ray-poly": (ray, poly, opts) => opts?.all ? intersectRayPolylineAll(ray.pos, ray.dir, poly.points, true) : intersectRayPolyline(ray.pos, ray.dir, poly.points, true),
|
|
91
|
+
"ray-polyline": (ray, poly, opts) => opts?.all ? intersectRayPolylineAll(ray.pos, ray.dir, poly.points, false) : intersectRayPolyline(ray.pos, ray.dir, poly.points, false),
|
|
33
92
|
"ray-rect": (ray, rect) => intersectRayRect(ray.pos, ray.dir, rect.pos, rect.max()),
|
|
34
93
|
"rect-circle": (rect, circle) => ({
|
|
35
94
|
type: testRectCircle(rect.pos, rect.size, circle.pos, circle.r) ? IntersectionType.INTERSECT : IntersectionType.NONE
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/geom",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "Functional, polymorphic API for 2D geometry types & SVG generation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -38,32 +38,32 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@thi.ng/api": "^8.9.30",
|
|
41
|
-
"@thi.ng/arrays": "^2.8.
|
|
42
|
-
"@thi.ng/associative": "^6.3.
|
|
41
|
+
"@thi.ng/arrays": "^2.8.11",
|
|
42
|
+
"@thi.ng/associative": "^6.3.51",
|
|
43
43
|
"@thi.ng/checks": "^3.5.4",
|
|
44
44
|
"@thi.ng/defmulti": "^3.0.33",
|
|
45
45
|
"@thi.ng/equiv": "^2.1.52",
|
|
46
46
|
"@thi.ng/errors": "^2.5.1",
|
|
47
|
-
"@thi.ng/geom-api": "^
|
|
48
|
-
"@thi.ng/geom-arc": "^2.1.
|
|
49
|
-
"@thi.ng/geom-clip-line": "^2.3.
|
|
50
|
-
"@thi.ng/geom-clip-poly": "^2.1.
|
|
51
|
-
"@thi.ng/geom-closest-point": "^2.1.
|
|
52
|
-
"@thi.ng/geom-hull": "^2.1.
|
|
53
|
-
"@thi.ng/geom-isec": "^
|
|
54
|
-
"@thi.ng/geom-poly-utils": "^2.3.
|
|
55
|
-
"@thi.ng/geom-resample": "^2.3.
|
|
56
|
-
"@thi.ng/geom-splines": "^2.2.
|
|
57
|
-
"@thi.ng/geom-subdiv-curve": "^2.1.
|
|
58
|
-
"@thi.ng/geom-tessellate": "^2.1.
|
|
59
|
-
"@thi.ng/hiccup": "^5.1.
|
|
60
|
-
"@thi.ng/hiccup-svg": "^5.2.
|
|
47
|
+
"@thi.ng/geom-api": "^4.0.0",
|
|
48
|
+
"@thi.ng/geom-arc": "^2.1.122",
|
|
49
|
+
"@thi.ng/geom-clip-line": "^2.3.79",
|
|
50
|
+
"@thi.ng/geom-clip-poly": "^2.1.121",
|
|
51
|
+
"@thi.ng/geom-closest-point": "^2.1.117",
|
|
52
|
+
"@thi.ng/geom-hull": "^2.1.117",
|
|
53
|
+
"@thi.ng/geom-isec": "^3.0.0",
|
|
54
|
+
"@thi.ng/geom-poly-utils": "^2.3.105",
|
|
55
|
+
"@thi.ng/geom-resample": "^2.3.43",
|
|
56
|
+
"@thi.ng/geom-splines": "^2.2.96",
|
|
57
|
+
"@thi.ng/geom-subdiv-curve": "^2.1.121",
|
|
58
|
+
"@thi.ng/geom-tessellate": "^2.1.122",
|
|
59
|
+
"@thi.ng/hiccup": "^5.1.24",
|
|
60
|
+
"@thi.ng/hiccup-svg": "^5.2.27",
|
|
61
61
|
"@thi.ng/math": "^5.10.7",
|
|
62
|
-
"@thi.ng/matrices": "^2.3.
|
|
63
|
-
"@thi.ng/random": "^3.
|
|
64
|
-
"@thi.ng/strings": "^3.7.
|
|
65
|
-
"@thi.ng/transducers": "^8.9.
|
|
66
|
-
"@thi.ng/vectors": "^7.10.
|
|
62
|
+
"@thi.ng/matrices": "^2.3.27",
|
|
63
|
+
"@thi.ng/random": "^3.7.0",
|
|
64
|
+
"@thi.ng/strings": "^3.7.26",
|
|
65
|
+
"@thi.ng/transducers": "^8.9.15",
|
|
66
|
+
"@thi.ng/vectors": "^7.10.21"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@microsoft/api-extractor": "^7.42.3",
|
|
@@ -399,5 +399,5 @@
|
|
|
399
399
|
],
|
|
400
400
|
"year": 2013
|
|
401
401
|
},
|
|
402
|
-
"gitHead": "
|
|
402
|
+
"gitHead": "da965520b2f3f8c259a791e8e8864308be2ba0be\n"
|
|
403
403
|
}
|