@thi.ng/geom 8.2.13 → 8.3.3

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/README.md CHANGED
@@ -451,7 +451,7 @@ For Node.js REPL:
451
451
  const geom = await import("@thi.ng/geom");
452
452
  ```
453
453
 
454
- Package sizes (brotli'd, pre-treeshake): ESM: 17.46 KB
454
+ Package sizes (brotli'd, pre-treeshake): ESM: 17.50 KB
455
455
 
456
456
  ## Dependencies
457
457
 
package/offset.d.ts CHANGED
@@ -19,14 +19,21 @@ export type OffsetFn = {
19
19
  * distance `dist`.
20
20
  *
21
21
  * @remarks
22
- * Also see [thi.ng/geom-sdf](https://thi.ng/thi.ng/geom-sdf) package for more
23
- * flexible & advanced usage.
22
+ * The implementation for polygons and convex polygons is _very_ naive and only
23
+ * intended for (some basic) convex cases. See
24
+ * [thi.ng/geom-sdf](https://thi.ng/thi.ng/geom-sdf) package for more flexible &
25
+ * advanced usage.
26
+ *
27
+ * For complex polygons, the vertex order of holes plays a role here (assumed to
28
+ * be the reverse of the boundary's order).
24
29
  *
25
30
  * Currently only implemented for:
26
31
  *
27
32
  * - {@link AABB}
28
33
  * - {@link Circle}
34
+ * - {@link ComplexPolygon} (convex only)
29
35
  * - {@link Line}
36
+ * - {@link Polygon} (convex only)
30
37
  * - {@link Rect}
31
38
  *
32
39
  * @param shape
package/offset.js CHANGED
@@ -1,15 +1,18 @@
1
1
  import { defmulti } from "@thi.ng/defmulti/defmulti";
2
+ import { offsetConvex } from "@thi.ng/geom-poly-utils/offset-convex";
2
3
  import { add2 } from "@thi.ng/vectors/add";
3
4
  import { normalCW } from "@thi.ng/vectors/normal";
4
5
  import { set2 } from "@thi.ng/vectors/set";
5
6
  import { sub2 } from "@thi.ng/vectors/sub";
6
7
  import { aabbWithCentroidAndMargin } from "./aabb.js";
7
8
  import { Circle } from "./api/circle.js";
9
+ import { Polygon } from "./api/polygon.js";
8
10
  import { Quad } from "./api/quad.js";
9
11
  import { centroid } from "./centroid.js";
10
12
  import { __copyAttribs } from "./internal/copy.js";
11
13
  import { __dispatch } from "./internal/dispatch.js";
12
14
  import { rectWithCentroidAndMargin } from "./rect.js";
15
+ import { ComplexPolygon } from "./api/complex-polygon.js";
13
16
  const offset = defmulti(
14
17
  __dispatch,
15
18
  {},
@@ -21,6 +24,13 @@ const offset = defmulti(
21
24
  __copyAttribs($.attribs)
22
25
  ),
23
26
  circle: ($, n) => new Circle(set2([], $.pos), Math.max($.r + n, 0)),
27
+ complexpoly: ({ boundary, children, attribs }, n) => new ComplexPolygon(
28
+ offset(boundary, n),
29
+ children.map(
30
+ (x) => offset(x, n),
31
+ __copyAttribs(attribs)
32
+ )
33
+ ),
24
34
  line: ({ points: [a, b], attribs }, n) => {
25
35
  const norm = normalCW([], a, b, n);
26
36
  return new Quad(
@@ -30,9 +40,10 @@ const offset = defmulti(
30
40
  sub2([], b, norm),
31
41
  sub2([], a, norm)
32
42
  ],
33
- { ...attribs }
43
+ __copyAttribs(attribs)
34
44
  );
35
45
  },
46
+ poly: ({ points, attribs }, n) => new Polygon(offsetConvex(points, n), __copyAttribs(attribs)),
36
47
  rect: ($, n) => rectWithCentroidAndMargin(
37
48
  centroid($),
38
49
  $.size,