@thi.ng/geom 6.0.7 → 6.0.9
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 +1 -1
- package/README.md +1 -1
- package/aabb.js +31 -32
- package/api/aabb.js +34 -29
- package/api/apc.js +15 -13
- package/api/arc.js +82 -66
- package/api/bpatch.js +79 -96
- package/api/circle.js +21 -21
- package/api/cubic.js +28 -25
- package/api/ellipse.js +26 -21
- package/api/group.js +45 -47
- package/api/line.js +26 -27
- package/api/path.js +62 -58
- package/api/plane.js +21 -21
- package/api/points.js +30 -26
- package/api/polygon.js +19 -16
- package/api/polyline.js +25 -22
- package/api/quad.js +20 -17
- package/api/quad3.js +20 -17
- package/api/quadratic.js +28 -25
- package/api/ray.js +30 -26
- package/api/rect.js +34 -29
- package/api/sphere.js +21 -21
- package/api/text.js +21 -28
- package/api/triangle.js +20 -17
- package/apply-transforms.js +28 -48
- package/arc-length.js +17 -30
- package/arc.js +17 -6
- package/area.js +19 -45
- package/as-cubic.js +38 -57
- package/as-path.js +4 -8
- package/as-polygon.js +12 -29
- package/as-polyline.js +18 -38
- package/as-svg.js +32 -63
- package/bounds.js +46 -48
- package/bpatch.js +22 -14
- package/center.js +22 -17
- package/centroid.js +14 -34
- package/circle.js +11 -6
- package/classify-point.js +20 -27
- package/clip-convex.js +40 -39
- package/closest-point.js +28 -34
- package/convex-hull.js +12 -27
- package/cubic.js +13 -5
- package/edges.js +31 -60
- package/ellipse.js +5 -2
- package/fit-into-bounds.js +78 -61
- package/flip.js +24 -41
- package/group.js +4 -1
- package/internal/args.js +18 -51
- package/internal/bounds.js +23 -38
- package/internal/collate.js +33 -17
- package/internal/copy.js +12 -23
- package/internal/dispatch.js +6 -4
- package/internal/edges.js +4 -1
- package/internal/pclike.js +8 -4
- package/internal/points-as-shape.js +4 -3
- package/internal/rotate.js +6 -2
- package/internal/scale.js +8 -2
- package/internal/split.js +9 -6
- package/internal/transform.js +24 -12
- package/internal/translate.js +6 -2
- package/internal/vertices.js +15 -31
- package/intersects.js +15 -39
- package/line.js +11 -9
- package/map-point.js +10 -18
- package/offset.js +31 -29
- package/package.json +33 -30
- package/path-builder.js +152 -143
- package/path-from-svg.js +129 -131
- package/path.js +28 -25
- package/plane.js +10 -5
- package/point-at.js +12 -30
- package/point-inside.js +20 -25
- package/points.js +6 -2
- package/polygon.js +15 -47
- package/polyline.js +18 -22
- package/quad.js +23 -15
- package/quadratic.js +7 -3
- package/ray.js +4 -1
- package/rect.js +47 -46
- package/resample.js +12 -27
- package/rotate.js +30 -42
- package/scale.js +66 -64
- package/scatter.js +18 -30
- package/simplify.js +38 -55
- package/sphere.js +7 -3
- package/split-arclength.js +53 -108
- package/split-at.js +46 -26
- package/split-near.js +28 -22
- package/subdiv-curve.js +33 -72
- package/tangent-at.js +12 -24
- package/tessellate.js +22 -47
- package/text.js +4 -1
- package/transform-vertices.js +31 -55
- package/transform.js +31 -54
- package/translate.js +39 -46
- package/triangle.js +7 -3
- package/union.js +12 -15
- package/unmap-point.js +21 -25
- package/vertices.js +91 -113
- package/volume.js +10 -14
- package/warp-points.js +15 -25
- package/with-attribs.js +4 -11
package/internal/args.js
CHANGED
|
@@ -1,57 +1,24 @@
|
|
|
1
1
|
import { isNumber } from "@thi.ng/checks/is-number";
|
|
2
2
|
import { isPlainObject } from "@thi.ng/checks/is-plain-object";
|
|
3
3
|
import { vecOf } from "@thi.ng/vectors/vec-of";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* @param args -
|
|
10
|
-
*
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
export const __argAttribs = (args) => {
|
|
14
|
-
if (args.length) {
|
|
15
|
-
const last = args[args.length - 1];
|
|
16
|
-
return isPlainObject(last)
|
|
17
|
-
? args.pop()
|
|
18
|
-
: last == null
|
|
19
|
-
? (args.pop(), undefined)
|
|
20
|
-
: undefined;
|
|
21
|
-
}
|
|
4
|
+
const __argAttribs = (args) => {
|
|
5
|
+
if (args.length) {
|
|
6
|
+
const last = args[args.length - 1];
|
|
7
|
+
return isPlainObject(last) ? args.pop() : last == null ? (args.pop(), void 0) : void 0;
|
|
8
|
+
}
|
|
22
9
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*
|
|
27
|
-
* @param args -
|
|
28
|
-
*
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
|
-
export const __argsVV = (args) => {
|
|
32
|
-
const attr = __argAttribs(args);
|
|
33
|
-
return args.length
|
|
34
|
-
? args.length === 2
|
|
35
|
-
? [args[0], args[1], attr]
|
|
36
|
-
: [undefined, args[0], attr]
|
|
37
|
-
: [undefined, undefined, attr];
|
|
10
|
+
const __argsVV = (args) => {
|
|
11
|
+
const attr = __argAttribs(args);
|
|
12
|
+
return args.length ? args.length === 2 ? [args[0], args[1], attr] : [void 0, args[0], attr] : [void 0, void 0, attr];
|
|
38
13
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return args.length
|
|
50
|
-
? args.length === 2
|
|
51
|
-
? [args[0], args[1], attr]
|
|
52
|
-
: isNumber(args[0])
|
|
53
|
-
? [undefined, args[0], attr]
|
|
54
|
-
: [args[0], undefined, attr]
|
|
55
|
-
: [undefined, undefined, attr];
|
|
14
|
+
const __argsVN = (args) => {
|
|
15
|
+
const attr = __argAttribs(args);
|
|
16
|
+
return args.length ? args.length === 2 ? [args[0], args[1], attr] : isNumber(args[0]) ? [void 0, args[0], attr] : [args[0], void 0, attr] : [void 0, void 0, attr];
|
|
17
|
+
};
|
|
18
|
+
const __asVec = (x, size = 2) => isNumber(x) ? vecOf(size, x) : x;
|
|
19
|
+
export {
|
|
20
|
+
__argAttribs,
|
|
21
|
+
__argsVN,
|
|
22
|
+
__argsVV,
|
|
23
|
+
__asVec
|
|
56
24
|
};
|
|
57
|
-
export const __asVec = (x, size = 2) => isNumber(x) ? vecOf(size, x) : x;
|
package/internal/bounds.js
CHANGED
|
@@ -2,44 +2,29 @@ import { add } from "@thi.ng/vectors/add";
|
|
|
2
2
|
import { max } from "@thi.ng/vectors/max";
|
|
3
3
|
import { min } from "@thi.ng/vectors/min";
|
|
4
4
|
import { sub } from "@thi.ng/vectors/sub";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
let n = shapes.length - 1;
|
|
16
|
-
if (n < 0)
|
|
17
|
-
return;
|
|
18
|
-
let b = bounds(shapes[n]);
|
|
5
|
+
const __collBounds = (shapes, bounds) => {
|
|
6
|
+
let n = shapes.length - 1;
|
|
7
|
+
if (n < 0)
|
|
8
|
+
return;
|
|
9
|
+
let b = bounds(shapes[n]);
|
|
10
|
+
if (!b)
|
|
11
|
+
return;
|
|
12
|
+
let { pos, size } = b;
|
|
13
|
+
for (; n-- > 0; ) {
|
|
14
|
+
b = bounds(shapes[n]);
|
|
19
15
|
if (!b)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (!b)
|
|
25
|
-
continue;
|
|
26
|
-
[pos, size] = __unionBounds(pos, size, b.pos, b.size);
|
|
27
|
-
}
|
|
28
|
-
return [pos, size];
|
|
16
|
+
continue;
|
|
17
|
+
[pos, size] = __unionBounds(pos, size, b.pos, b.size);
|
|
18
|
+
}
|
|
19
|
+
return [pos, size];
|
|
29
20
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
*/
|
|
40
|
-
export const __unionBounds = (apos, asize, bpos, bsize) => {
|
|
41
|
-
const p = add([], apos, asize);
|
|
42
|
-
const q = add([], bpos, bsize);
|
|
43
|
-
const pos = min([], apos, bpos);
|
|
44
|
-
return [pos, sub(null, max(null, p, q), pos)];
|
|
21
|
+
const __unionBounds = (apos, asize, bpos, bsize) => {
|
|
22
|
+
const p = add([], apos, asize);
|
|
23
|
+
const q = add([], bpos, bsize);
|
|
24
|
+
const pos = min([], apos, bpos);
|
|
25
|
+
return [pos, sub(null, max(null, p, q), pos)];
|
|
26
|
+
};
|
|
27
|
+
export {
|
|
28
|
+
__collBounds,
|
|
29
|
+
__unionBounds
|
|
45
30
|
};
|
package/internal/collate.js
CHANGED
|
@@ -1,19 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
const __remapBuffer = (buf, pts, start, cstride, estride) => {
|
|
2
|
+
for (let i = pts.length; i-- > 0; ) {
|
|
3
|
+
const p = pts[i];
|
|
4
|
+
p.buf = buf;
|
|
5
|
+
p.offset = start + i * estride;
|
|
6
|
+
p.stride = cstride;
|
|
7
|
+
}
|
|
8
|
+
return buf;
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
const __collateWith = (fn, pts, opts, stride) => {
|
|
11
|
+
opts = {
|
|
12
|
+
start: 0,
|
|
13
|
+
cstride: 1,
|
|
14
|
+
estride: stride,
|
|
15
|
+
...opts
|
|
16
|
+
};
|
|
17
|
+
const { start, cstride, estride } = opts;
|
|
18
|
+
return __remapBuffer(
|
|
19
|
+
fn(
|
|
20
|
+
opts.buf || new Array(start + pts.length * estride).fill(0),
|
|
21
|
+
pts,
|
|
22
|
+
start,
|
|
23
|
+
cstride,
|
|
24
|
+
estride
|
|
25
|
+
),
|
|
26
|
+
pts,
|
|
27
|
+
start,
|
|
28
|
+
cstride,
|
|
29
|
+
estride
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
__collateWith,
|
|
34
|
+
__remapBuffer
|
|
19
35
|
};
|
package/internal/copy.js
CHANGED
|
@@ -1,26 +1,15 @@
|
|
|
1
|
-
// thing:export
|
|
2
1
|
import { withoutKeysObj } from "@thi.ng/associative/without-keys";
|
|
3
2
|
import { copyVectors } from "@thi.ng/vectors/copy";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
const __copyAttribs = ($, ...exclude) => {
|
|
4
|
+
if (!$.attribs)
|
|
5
|
+
return;
|
|
6
|
+
const attribs = { ...$.attribs };
|
|
7
|
+
return exclude.length ? withoutKeysObj(attribs, exclude) : attribs;
|
|
8
|
+
};
|
|
9
|
+
const __copyAttribsNoSamples = (x) => __copyAttribs(x, "__samples");
|
|
10
|
+
const __copyShape = (ctor, inst) => new ctor(copyVectors(inst.points), __copyAttribs(inst));
|
|
11
|
+
export {
|
|
12
|
+
__copyAttribs,
|
|
13
|
+
__copyAttribsNoSamples,
|
|
14
|
+
__copyShape
|
|
15
15
|
};
|
|
16
|
-
/**
|
|
17
|
-
* Syntax sugar for {@link __copyAttribs}, also removing `__samples` key from
|
|
18
|
-
* result.
|
|
19
|
-
*
|
|
20
|
-
* @param x
|
|
21
|
-
*
|
|
22
|
-
* @internal
|
|
23
|
-
*/
|
|
24
|
-
export const __copyAttribsNoSamples = (x) => __copyAttribs(x, "__samples");
|
|
25
|
-
/** @internal */
|
|
26
|
-
export const __copyShape = (ctor, inst) => new ctor(copyVectors(inst.points), __copyAttribs(inst));
|
package/internal/dispatch.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
const __dispatch = (x) => x.type;
|
|
2
|
+
const __dispatch2 = (a, b) => a.type + "-" + b.type;
|
|
3
|
+
export {
|
|
4
|
+
__dispatch,
|
|
5
|
+
__dispatch2
|
|
6
|
+
};
|
package/internal/edges.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { partition } from "@thi.ng/transducers/partition";
|
|
2
2
|
import { wrapSides } from "@thi.ng/transducers/wrap-sides";
|
|
3
|
-
|
|
3
|
+
const __edges = (vertices, closed = false) => partition(2, 1, closed ? wrapSides(vertices, 0, 1) : vertices);
|
|
4
|
+
export {
|
|
5
|
+
__edges
|
|
6
|
+
};
|
package/internal/pclike.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { assert } from "@thi.ng/errors/assert";
|
|
2
2
|
import { __argAttribs } from "./args.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const __pclike = (ctor, args) => {
|
|
4
|
+
const attr = __argAttribs(args);
|
|
5
|
+
return new ctor(args.length === 1 ? args[0] : args, attr);
|
|
6
|
+
};
|
|
7
|
+
const __ensureNumVerts = (num, expected) => assert(num === expected, `require ${expected} points`);
|
|
8
|
+
export {
|
|
9
|
+
__ensureNumVerts,
|
|
10
|
+
__pclike
|
|
6
11
|
};
|
|
7
|
-
export const __ensureNumVerts = (num, expected) => assert(num === expected, `require ${expected} points`);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { map } from "@thi.ng/transducers/map";
|
|
2
2
|
import { copyVectors } from "@thi.ng/vectors/copy";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const __pointArraysAsShapes = (ctor, src, attribs) => src ? [...map((pts) => new ctor(copyVectors(pts), { ...attribs }), src)] : void 0;
|
|
4
|
+
export {
|
|
5
|
+
__pointArraysAsShapes
|
|
6
|
+
};
|
package/internal/rotate.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { rotate } from "@thi.ng/vectors/rotate";
|
|
2
2
|
import { __copyAttribs } from "./copy.js";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const __rotatedPoints = (pts, delta) => pts.map((x) => rotate([], x, delta));
|
|
4
|
+
const __rotatedShape = (ctor) => ($, delta) => new ctor(__rotatedPoints($.points, delta), __copyAttribs($));
|
|
5
|
+
export {
|
|
6
|
+
__rotatedPoints,
|
|
7
|
+
__rotatedShape
|
|
8
|
+
};
|
package/internal/scale.js
CHANGED
|
@@ -2,5 +2,11 @@ import { isNumber } from "@thi.ng/checks/is-number";
|
|
|
2
2
|
import { mul } from "@thi.ng/vectors/mul";
|
|
3
3
|
import { mulN } from "@thi.ng/vectors/muln";
|
|
4
4
|
import { __copyAttribs } from "./copy.js";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const __scaledPoints = (pts, delta) => pts.map(
|
|
6
|
+
isNumber(delta) ? (x) => mulN([], x, delta) : (x) => mul([], x, delta)
|
|
7
|
+
);
|
|
8
|
+
const __scaledShape = (ctor) => ($, delta) => new ctor(__scaledPoints($.points, delta), __copyAttribs($));
|
|
9
|
+
export {
|
|
10
|
+
__scaledPoints,
|
|
11
|
+
__scaledShape
|
|
12
|
+
};
|
package/internal/split.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { mixN } from "@thi.ng/vectors/mixn";
|
|
2
2
|
import { set } from "@thi.ng/vectors/set";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
const __splitLine = (a, b, t) => {
|
|
4
|
+
const p = mixN([], a, b, t);
|
|
5
|
+
return [
|
|
6
|
+
[a, p],
|
|
7
|
+
[set([], p), b]
|
|
8
|
+
];
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
__splitLine
|
|
9
12
|
};
|
package/internal/transform.js
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
import { mulV, mulV344 } from "@thi.ng/matrices/mulv";
|
|
2
2
|
import { __copyAttribs } from "./copy.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export
|
|
3
|
+
const __transformPoints = (pts, mat, op = mulV) => (pts.forEach((p) => op(null, mat, p)), pts);
|
|
4
|
+
const __transformedPoints = (pts, mat, op = mulV) => pts.map((p) => op([], mat, p));
|
|
5
|
+
const __transformPointsWith = (pts, fn, op = mulV) => (pts.forEach((p) => op(null, fn(p), p)), pts);
|
|
6
|
+
const __transformedPointsWith = (pts, fn, op = mulV) => pts.map((p) => op([], fn(p), p));
|
|
7
|
+
const __transformedShape = (ctor) => ($, mat) => new ctor(__transformedPoints($.points, mat), __copyAttribs($));
|
|
8
|
+
const __transformedShapePoints = (ctor) => ($, fn) => new ctor(__transformedPointsWith($.points, fn), __copyAttribs($));
|
|
9
|
+
const __transformPoints3 = (pts, mat) => __transformPoints(pts, mat, mulV344);
|
|
10
|
+
const __transformedPoints3 = (pts, mat) => __transformedPoints(pts, mat, mulV344);
|
|
11
|
+
const __transformedPointsWith3 = (pts, fn) => __transformedPointsWith(pts, fn, mulV344);
|
|
12
|
+
const __transformedShape3 = (ctor) => ($, mat) => new ctor(__transformedPoints3($.points, mat), __copyAttribs($));
|
|
13
|
+
const __transformedShapePoints3 = (ctor) => ($, fn) => new ctor(__transformedPointsWith3($.points, fn), __copyAttribs($));
|
|
14
|
+
export {
|
|
15
|
+
__transformPoints,
|
|
16
|
+
__transformPoints3,
|
|
17
|
+
__transformPointsWith,
|
|
18
|
+
__transformedPoints,
|
|
19
|
+
__transformedPoints3,
|
|
20
|
+
__transformedPointsWith,
|
|
21
|
+
__transformedPointsWith3,
|
|
22
|
+
__transformedShape,
|
|
23
|
+
__transformedShape3,
|
|
24
|
+
__transformedShapePoints,
|
|
25
|
+
__transformedShapePoints3
|
|
26
|
+
};
|
package/internal/translate.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { add } from "@thi.ng/vectors/add";
|
|
2
2
|
import { __copyAttribs } from "./copy.js";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const __translatedPoints = (pts, delta) => pts.map((x) => add([], x, delta));
|
|
4
|
+
const __translatedShape = (ctor) => ($, delta) => new ctor(__translatedPoints($.points, delta), __copyAttribs($));
|
|
5
|
+
export {
|
|
6
|
+
__translatedPoints,
|
|
7
|
+
__translatedShape
|
|
8
|
+
};
|
package/internal/vertices.js
CHANGED
|
@@ -1,35 +1,19 @@
|
|
|
1
|
-
// thing:export
|
|
2
1
|
import { isNumber } from "@thi.ng/checks/is-number";
|
|
3
2
|
import { DEFAULT_SAMPLES } from "@thi.ng/geom-api/sample";
|
|
4
3
|
import { TAU } from "@thi.ng/math/api";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*
|
|
21
|
-
* @internal
|
|
22
|
-
*/
|
|
23
|
-
export const __sampleAttribs = (opts, attribs) => {
|
|
24
|
-
if (attribs) {
|
|
25
|
-
const val = attribs.__samples;
|
|
26
|
-
return isNumber(opts)
|
|
27
|
-
? isNumber(val)
|
|
28
|
-
? val
|
|
29
|
-
: { num: opts, ...val }
|
|
30
|
-
: isNumber(val)
|
|
31
|
-
? { ...opts, num: val }
|
|
32
|
-
: { ...opts, ...val };
|
|
33
|
-
}
|
|
34
|
-
return opts;
|
|
4
|
+
const __circleOpts = (opts, r) => isNumber(opts) ? [opts, 0, false] : [
|
|
5
|
+
opts.theta ? Math.floor(TAU / opts.theta) : opts.dist ? Math.floor(TAU / (opts.dist / r)) : opts.num || DEFAULT_SAMPLES,
|
|
6
|
+
(opts.start || 0) * TAU,
|
|
7
|
+
opts.last === true
|
|
8
|
+
];
|
|
9
|
+
const __sampleAttribs = (opts, attribs) => {
|
|
10
|
+
if (attribs) {
|
|
11
|
+
const val = attribs.__samples;
|
|
12
|
+
return isNumber(opts) ? isNumber(val) ? val : { num: opts, ...val } : isNumber(val) ? { ...opts, num: val } : { ...opts, ...val };
|
|
13
|
+
}
|
|
14
|
+
return opts;
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
__circleOpts,
|
|
18
|
+
__sampleAttribs
|
|
35
19
|
};
|
package/intersects.js
CHANGED
|
@@ -10,41 +10,17 @@ import { intersectRayAABB, intersectRayRect } from "@thi.ng/geom-isec/ray-rect";
|
|
|
10
10
|
import { testRectCircle } from "@thi.ng/geom-isec/rect-circle";
|
|
11
11
|
import { testAabbAabb, testRectRect } from "@thi.ng/geom-isec/rect-rect";
|
|
12
12
|
import { __dispatch2 } from "./internal/dispatch.js";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*
|
|
17
|
-
* @remarks
|
|
18
|
-
* Currently supported pairs:
|
|
19
|
-
*
|
|
20
|
-
* - {@link Circle} / {@link Circle}
|
|
21
|
-
* - {@link Line} / {@link Line}
|
|
22
|
-
* - {@link Plane} / {@link Plane}
|
|
23
|
-
* - {@link Ray} / {@link AABB}
|
|
24
|
-
* - {@link Ray} / {@link Circle}
|
|
25
|
-
* - {@link Ray} / {@link Plane}
|
|
26
|
-
* - {@link Ray} / {@link Polygon}
|
|
27
|
-
* - {@link Ray} / {@link Polyline}
|
|
28
|
-
* - {@link Ray} / {@link Quad}
|
|
29
|
-
* - {@link Ray} / {@link Rect}
|
|
30
|
-
* - {@link Ray} / {@link Sphere}
|
|
31
|
-
* - {@link Ray} / {@link Triangle}
|
|
32
|
-
* - {@link Rect} / {@link Rect}
|
|
33
|
-
* - {@link Sphere} / {@link Sphere}
|
|
34
|
-
*
|
|
35
|
-
* @param a
|
|
36
|
-
* @param b
|
|
37
|
-
*/
|
|
38
|
-
export const intersects = defmulti(__dispatch2, {
|
|
13
|
+
const intersects = defmulti(
|
|
14
|
+
__dispatch2,
|
|
15
|
+
{
|
|
39
16
|
"ray-sphere": "ray-circle",
|
|
40
17
|
"ray-quad": "ray-poly",
|
|
41
18
|
"ray-tri": "ray-poly",
|
|
42
|
-
"sphere-sphere": "circle-circle"
|
|
43
|
-
},
|
|
19
|
+
"sphere-sphere": "circle-circle"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
44
22
|
"aabb-aabb": (a, b) => ({
|
|
45
|
-
|
|
46
|
-
? IntersectionType.INTERSECT
|
|
47
|
-
: IntersectionType.NONE,
|
|
23
|
+
type: testAabbAabb(a.pos, a.size, b.pos, b.size) ? IntersectionType.INTERSECT : IntersectionType.NONE
|
|
48
24
|
}),
|
|
49
25
|
"circle-circle": (a, b) => intersectCircleCircle(a.pos, b.pos, a.r, b.r),
|
|
50
26
|
"line-line": ({ points: a }, { points: b }) => intersectLineLine(a[0], a[1], b[0], b[1]),
|
|
@@ -56,13 +32,13 @@ export const intersects = defmulti(__dispatch2, {
|
|
|
56
32
|
"ray-polyline": (ray, poly) => intersectRayPolyline(ray.pos, ray.dir, poly.points, false),
|
|
57
33
|
"ray-rect": (ray, rect) => intersectRayRect(ray.pos, ray.dir, rect.pos, rect.max()),
|
|
58
34
|
"rect-circle": (rect, circle) => ({
|
|
59
|
-
|
|
60
|
-
? IntersectionType.INTERSECT
|
|
61
|
-
: IntersectionType.NONE,
|
|
35
|
+
type: testRectCircle(rect.pos, rect.size, circle.pos, circle.r) ? IntersectionType.INTERSECT : IntersectionType.NONE
|
|
62
36
|
}),
|
|
63
37
|
"rect-rect": (a, b) => ({
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
38
|
+
type: testRectRect(a.pos, a.size, b.pos, b.size) ? IntersectionType.INTERSECT : IntersectionType.NONE
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
export {
|
|
43
|
+
intersects
|
|
44
|
+
};
|
package/line.js
CHANGED
|
@@ -2,14 +2,16 @@ import { liangBarsky2 } from "@thi.ng/geom-clip-line/liang-barsky";
|
|
|
2
2
|
import { Line } from "./api/line.js";
|
|
3
3
|
import { Rect } from "./api/rect.js";
|
|
4
4
|
import { __pclike } from "./internal/pclike.js";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
function line(...args) {
|
|
6
|
+
return __pclike(Line, args);
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
const clippedLine = (l, bounds) => {
|
|
9
|
+
const res = bounds instanceof Rect ? liangBarsky2(l.points[0], l.points[1], bounds.pos, bounds.max()) : liangBarsky2(l.points[0], l.points[1], bounds[0], bounds[1]);
|
|
10
|
+
if (res) {
|
|
11
|
+
return new Line([res[0], res[1]], { ...l.attribs });
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
export {
|
|
15
|
+
clippedLine,
|
|
16
|
+
line
|
|
15
17
|
};
|
package/map-point.js
CHANGED
|
@@ -2,21 +2,13 @@ import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
|
2
2
|
import { div } from "@thi.ng/vectors/div";
|
|
3
3
|
import { sub } from "@thi.ng/vectors/sub";
|
|
4
4
|
import { __dispatch } from "./internal/dispatch.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
* @param shape
|
|
17
|
-
* @param p
|
|
18
|
-
* @param out
|
|
19
|
-
*/
|
|
20
|
-
export const mapPoint = defmulti(__dispatch, { aabb: "rect" }, {
|
|
21
|
-
rect: ($, p, out = []) => div(null, sub(out, p, $.pos), $.size),
|
|
22
|
-
});
|
|
5
|
+
const mapPoint = defmulti(
|
|
6
|
+
__dispatch,
|
|
7
|
+
{ aabb: "rect" },
|
|
8
|
+
{
|
|
9
|
+
rect: ($, p, out = []) => div(null, sub(out, p, $.pos), $.size)
|
|
10
|
+
}
|
|
11
|
+
);
|
|
12
|
+
export {
|
|
13
|
+
mapPoint
|
|
14
|
+
};
|
package/offset.js
CHANGED
|
@@ -10,35 +10,37 @@ import { centroid } from "./centroid.js";
|
|
|
10
10
|
import { __copyAttribs } from "./internal/copy.js";
|
|
11
11
|
import { __dispatch } from "./internal/dispatch.js";
|
|
12
12
|
import { rectWithCentroidAndMargin } from "./rect.js";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* - {@link AABB}
|
|
24
|
-
* - {@link Circle}
|
|
25
|
-
* - {@link Line}
|
|
26
|
-
* - {@link Rect}
|
|
27
|
-
*
|
|
28
|
-
* @param shape
|
|
29
|
-
* @param dist
|
|
30
|
-
*/
|
|
31
|
-
export const offset = defmulti(__dispatch, {}, {
|
|
32
|
-
aabb: ($, n) => aabbWithCentroidAndMargin(centroid($), $.size, n, __copyAttribs($)),
|
|
13
|
+
const offset = defmulti(
|
|
14
|
+
__dispatch,
|
|
15
|
+
{},
|
|
16
|
+
{
|
|
17
|
+
aabb: ($, n) => aabbWithCentroidAndMargin(
|
|
18
|
+
centroid($),
|
|
19
|
+
$.size,
|
|
20
|
+
n,
|
|
21
|
+
__copyAttribs($)
|
|
22
|
+
),
|
|
33
23
|
circle: ($, n) => new Circle(set2([], $.pos), Math.max($.r + n, 0)),
|
|
34
24
|
line: ({ points: [a, b], attribs }, n) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
25
|
+
const norm = normalCW([], a, b, n);
|
|
26
|
+
return new Quad(
|
|
27
|
+
[
|
|
28
|
+
add2([], a, norm),
|
|
29
|
+
add2([], b, norm),
|
|
30
|
+
sub2([], b, norm),
|
|
31
|
+
sub2([], a, norm)
|
|
32
|
+
],
|
|
33
|
+
{ ...attribs }
|
|
34
|
+
);
|
|
42
35
|
},
|
|
43
|
-
rect: ($, n) => rectWithCentroidAndMargin(
|
|
44
|
-
|
|
36
|
+
rect: ($, n) => rectWithCentroidAndMargin(
|
|
37
|
+
centroid($),
|
|
38
|
+
$.size,
|
|
39
|
+
n,
|
|
40
|
+
__copyAttribs($)
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
export {
|
|
45
|
+
offset
|
|
46
|
+
};
|