@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.
Files changed (104) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +1 -1
  3. package/aabb.js +31 -32
  4. package/api/aabb.js +34 -29
  5. package/api/apc.js +15 -13
  6. package/api/arc.js +82 -66
  7. package/api/bpatch.js +79 -96
  8. package/api/circle.js +21 -21
  9. package/api/cubic.js +28 -25
  10. package/api/ellipse.js +26 -21
  11. package/api/group.js +45 -47
  12. package/api/line.js +26 -27
  13. package/api/path.js +62 -58
  14. package/api/plane.js +21 -21
  15. package/api/points.js +30 -26
  16. package/api/polygon.js +19 -16
  17. package/api/polyline.js +25 -22
  18. package/api/quad.js +20 -17
  19. package/api/quad3.js +20 -17
  20. package/api/quadratic.js +28 -25
  21. package/api/ray.js +30 -26
  22. package/api/rect.js +34 -29
  23. package/api/sphere.js +21 -21
  24. package/api/text.js +21 -28
  25. package/api/triangle.js +20 -17
  26. package/apply-transforms.js +28 -48
  27. package/arc-length.js +17 -30
  28. package/arc.js +17 -6
  29. package/area.js +19 -45
  30. package/as-cubic.js +38 -57
  31. package/as-path.js +4 -8
  32. package/as-polygon.js +12 -29
  33. package/as-polyline.js +18 -38
  34. package/as-svg.js +32 -63
  35. package/bounds.js +46 -48
  36. package/bpatch.js +22 -14
  37. package/center.js +22 -17
  38. package/centroid.js +14 -34
  39. package/circle.js +11 -6
  40. package/classify-point.js +20 -27
  41. package/clip-convex.js +40 -39
  42. package/closest-point.js +28 -34
  43. package/convex-hull.js +12 -27
  44. package/cubic.js +13 -5
  45. package/edges.js +31 -60
  46. package/ellipse.js +5 -2
  47. package/fit-into-bounds.js +78 -61
  48. package/flip.js +24 -41
  49. package/group.js +4 -1
  50. package/internal/args.js +18 -51
  51. package/internal/bounds.js +23 -38
  52. package/internal/collate.js +33 -17
  53. package/internal/copy.js +12 -23
  54. package/internal/dispatch.js +6 -4
  55. package/internal/edges.js +4 -1
  56. package/internal/pclike.js +8 -4
  57. package/internal/points-as-shape.js +4 -3
  58. package/internal/rotate.js +6 -2
  59. package/internal/scale.js +8 -2
  60. package/internal/split.js +9 -6
  61. package/internal/transform.js +24 -12
  62. package/internal/translate.js +6 -2
  63. package/internal/vertices.js +15 -31
  64. package/intersects.js +15 -39
  65. package/line.js +11 -9
  66. package/map-point.js +10 -18
  67. package/offset.js +31 -29
  68. package/package.json +33 -30
  69. package/path-builder.js +152 -143
  70. package/path-from-svg.js +129 -131
  71. package/path.js +28 -25
  72. package/plane.js +10 -5
  73. package/point-at.js +12 -30
  74. package/point-inside.js +20 -25
  75. package/points.js +6 -2
  76. package/polygon.js +15 -47
  77. package/polyline.js +18 -22
  78. package/quad.js +23 -15
  79. package/quadratic.js +7 -3
  80. package/ray.js +4 -1
  81. package/rect.js +47 -46
  82. package/resample.js +12 -27
  83. package/rotate.js +30 -42
  84. package/scale.js +66 -64
  85. package/scatter.js +18 -30
  86. package/simplify.js +38 -55
  87. package/sphere.js +7 -3
  88. package/split-arclength.js +53 -108
  89. package/split-at.js +46 -26
  90. package/split-near.js +28 -22
  91. package/subdiv-curve.js +33 -72
  92. package/tangent-at.js +12 -24
  93. package/tessellate.js +22 -47
  94. package/text.js +4 -1
  95. package/transform-vertices.js +31 -55
  96. package/transform.js +31 -54
  97. package/translate.js +39 -46
  98. package/triangle.js +7 -3
  99. package/union.js +12 -15
  100. package/unmap-point.js +21 -25
  101. package/vertices.js +91 -113
  102. package/volume.js +10 -14
  103. package/warp-points.js +15 -25
  104. 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
- * Takes an array of arguments, checks if last element is a plain object or
6
- * nullish and if so, removes value from array and returns it (`null` will be
7
- * cast to `undefined`). Else returns `undefined`.
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
- * Args parser for functions expecting up to 2 vector args and optional
25
- * attribs object. Returns 3-tuple of re-structured args.
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
- * Args parser for functions expecting a vector, numeric and/or optional
41
- * attribs object. Returns 3-tuple of re-structured args.
42
- *
43
- * @param args -
44
- *
45
- * @internal
46
- */
47
- export const __argsVN = (args) => {
48
- const attr = __argAttribs(args);
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;
@@ -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
- * Computes the total bounds for the given shape collection, which should either
7
- * contain only 2D or 3D types. No mixed dimensions are allowed! Currently the
8
- * {@link bounds} function MUST be passed in as arg to avoid circular module
9
- * dependencies. Returns 2-tuple of `[pos, size]`.
10
- *
11
- * @param shapes - input shapes
12
- * @param bounds - bbox function
13
- */
14
- export const __collBounds = (shapes, bounds) => {
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
- return;
21
- let { pos, size } = b;
22
- for (; n-- > 0;) {
23
- b = bounds(shapes[n]);
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
- * Takes the position and size vectors of 2
32
- * [`AABBLike`](https://docs.thi.ng/umbrella/geom-api/interfaces/AABBLike.html)s
33
- * and returns 2-tuple of `[pos,size]` of their union bounds.
34
- *
35
- * @param apos - bbox 1 min pos
36
- * @param asize - bbox1 size
37
- * @param bpos - bbox 2 min pos
38
- * @param bsize - bbox 2 size
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
  };
@@ -1,19 +1,35 @@
1
- export 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;
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
- export 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(fn(opts.buf || new Array(start + pts.length * estride).fill(0), pts, start, cstride, estride), pts, start, cstride, estride);
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
- * Creates a shallow copy of shape's attribs. Any `exclude` keys will be removed
6
- * from result attribs.
7
- *
8
- * @internal
9
- */
10
- export const __copyAttribs = ($, ...exclude) => {
11
- if (!$.attribs)
12
- return;
13
- const attribs = { ...$.attribs };
14
- return exclude.length ? withoutKeysObj(attribs, exclude) : attribs;
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));
@@ -1,4 +1,6 @@
1
- /** @internal */
2
- export const __dispatch = (x) => x.type;
3
- /** @internal */
4
- export const __dispatch2 = (a, b) => a.type + "-" + b.type;
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
- export const __edges = (vertices, closed = false) => (partition(2, 1, closed ? wrapSides(vertices, 0, 1) : vertices));
3
+ const __edges = (vertices, closed = false) => partition(2, 1, closed ? wrapSides(vertices, 0, 1) : vertices);
4
+ export {
5
+ __edges
6
+ };
@@ -1,7 +1,11 @@
1
1
  import { assert } from "@thi.ng/errors/assert";
2
2
  import { __argAttribs } from "./args.js";
3
- export const __pclike = (ctor, args) => {
4
- const attr = __argAttribs(args);
5
- return new ctor(args.length === 1 ? args[0] : args, attr);
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
- export const __pointArraysAsShapes = (ctor, src, attribs) => src
4
- ? [...map((pts) => new ctor(copyVectors(pts), { ...attribs }), src)]
5
- : undefined;
3
+ const __pointArraysAsShapes = (ctor, src, attribs) => src ? [...map((pts) => new ctor(copyVectors(pts), { ...attribs }), src)] : void 0;
4
+ export {
5
+ __pointArraysAsShapes
6
+ };
@@ -1,4 +1,8 @@
1
1
  import { rotate } from "@thi.ng/vectors/rotate";
2
2
  import { __copyAttribs } from "./copy.js";
3
- export const __rotatedPoints = (pts, delta) => pts.map((x) => rotate([], x, delta));
4
- export const __rotatedShape = (ctor) => ($, delta) => new ctor(__rotatedPoints($.points, delta), __copyAttribs($));
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
- export const __scaledPoints = (pts, delta) => pts.map(isNumber(delta) ? (x) => mulN([], x, delta) : (x) => mul([], x, delta));
6
- export const __scaledShape = (ctor) => ($, delta) => new ctor(__scaledPoints($.points, delta), __copyAttribs($));
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
- export const __splitLine = (a, b, t) => {
4
- const p = mixN([], a, b, t);
5
- return [
6
- [a, p],
7
- [set([], p), b],
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
  };
@@ -1,14 +1,26 @@
1
1
  import { mulV, mulV344 } from "@thi.ng/matrices/mulv";
2
2
  import { __copyAttribs } from "./copy.js";
3
- export const __transformPoints = (pts, mat, op = mulV) => (pts.forEach((p) => op(null, mat, p)), pts);
4
- export const __transformedPoints = (pts, mat, op = mulV) => pts.map((p) => op([], mat, p));
5
- export const __transformPointsWith = (pts, fn, op = mulV) => (pts.forEach((p) => op(null, fn(p), p)), pts);
6
- export const __transformedPointsWith = (pts, fn, op = mulV) => pts.map((p) => op([], fn(p), p));
7
- export const __transformedShape = (ctor) => ($, mat) => new ctor(__transformedPoints($.points, mat), __copyAttribs($));
8
- export const __transformedShapePoints = (ctor) => ($, fn) => new ctor(__transformedPointsWith($.points, fn), __copyAttribs($));
9
- // 3d versions
10
- export const __transformPoints3 = (pts, mat) => __transformPoints(pts, mat, mulV344);
11
- export const __transformedPoints3 = (pts, mat) => __transformedPoints(pts, mat, mulV344);
12
- export const __transformedPointsWith3 = (pts, fn) => __transformedPointsWith(pts, fn, mulV344);
13
- export const __transformedShape3 = (ctor) => ($, mat) => new ctor(__transformedPoints3($.points, mat), __copyAttribs($));
14
- export const __transformedShapePoints3 = (ctor) => ($, fn) => new ctor(__transformedPointsWith3($.points, fn), __copyAttribs($));
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
+ };
@@ -1,4 +1,8 @@
1
1
  import { add } from "@thi.ng/vectors/add";
2
2
  import { __copyAttribs } from "./copy.js";
3
- export const __translatedPoints = (pts, delta) => pts.map((x) => add([], x, delta));
4
- export const __translatedShape = (ctor) => ($, delta) => new ctor(__translatedPoints($.points, delta), __copyAttribs($));
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
+ };
@@ -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
- /** @internal */
6
- export const __circleOpts = (opts, r) => isNumber(opts)
7
- ? [opts, 0, false]
8
- : [
9
- opts.theta
10
- ? Math.floor(TAU / opts.theta)
11
- : opts.dist
12
- ? Math.floor(TAU / (opts.dist / r))
13
- : opts.num || DEFAULT_SAMPLES,
14
- (opts.start || 0) * TAU,
15
- opts.last === true,
16
- ];
17
- /**
18
- * @param opts
19
- * @param attribs
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
- * Performs intersection tests on given 2 shapes and returns
15
- * [`IntersectionResult`](https://docs.thi.ng/umbrella/geom-api/interfaces/IntersectionResult.html).
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
- type: testAabbAabb(a.pos, a.size, b.pos, b.size)
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
- type: testRectCircle(rect.pos, rect.size, circle.pos, circle.r)
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
- type: testRectRect(a.pos, a.size, b.pos, b.size)
65
- ? IntersectionType.INTERSECT
66
- : IntersectionType.NONE,
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
- export function line(...args) {
6
- return __pclike(Line, args);
5
+ function line(...args) {
6
+ return __pclike(Line, args);
7
7
  }
8
- export const clippedLine = (l, bounds) => {
9
- const res = bounds instanceof Rect
10
- ? liangBarsky2(l.points[0], l.points[1], bounds.pos, bounds.max())
11
- : liangBarsky2(l.points[0], l.points[1], bounds[0], bounds[1]);
12
- if (res) {
13
- return new Line([res[0], res[1]], { ...l.attribs });
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
- * Maps point `p` from world space to the local space of given shape.
7
- *
8
- * @remarks
9
- * This is the reverse operation of {@link unmapPoint}.
10
- *
11
- * Currently only implemented for:
12
- *
13
- * - {@link AABB}
14
- * - {@link Rect}
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
- * Computes an offset shape (as in "path offsetting") of given shape and offset
15
- * distance `dist`.
16
- *
17
- * @remarks
18
- * Also see [thi.ng/geom-sdf](https://thi.ng/thi.ng/geom-sdf) package for more
19
- * flexible & advanced usage.
20
- *
21
- * Currently only implemented for:
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
- const norm = normalCW([], a, b, n);
36
- return new Quad([
37
- add2([], a, norm),
38
- add2([], b, norm),
39
- sub2([], b, norm),
40
- sub2([], a, norm),
41
- ], { ...attribs });
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(centroid($), $.size, n, __copyAttribs($)),
44
- });
36
+ rect: ($, n) => rectWithCentroidAndMargin(
37
+ centroid($),
38
+ $.size,
39
+ n,
40
+ __copyAttribs($)
41
+ )
42
+ }
43
+ );
44
+ export {
45
+ offset
46
+ };