@thi.ng/geom 4.3.0 → 4.4.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 +18 -1
- package/README.md +3 -2
- package/api/group.d.ts +2 -2
- package/as-polygon.d.ts +3 -0
- package/as-polygon.js +5 -2
- package/as-polyline.d.ts +3 -0
- package/as-polyline.js +7 -4
- package/edges.d.ts +16 -2
- package/edges.js +18 -2
- package/internal/copy.d.ts +16 -2
- package/internal/copy.js +22 -2
- package/package.json +12 -12
- package/resample.d.ts +3 -0
- package/resample.js +6 -3
- package/split-arclength.d.ts +9 -1
- package/split-arclength.js +14 -6
- package/subdiv-curve.d.ts +47 -0
- package/subdiv-curve.js +59 -1
- package/tessellate.d.ts +30 -0
- package/tessellate.js +36 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2023-03-
|
|
3
|
+
- **Last updated**: 2023-03-24T19:50:18Z
|
|
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,23 @@ 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
|
+
## [4.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/geom@4.4.0) (2023-03-24)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- avoid recursive application of __samples attrib ([189446d](https://github.com/thi-ng/umbrella/commit/189446d))
|
|
17
|
+
- add internal __copyAttribsNoSamples() helper
|
|
18
|
+
- update implementations for:
|
|
19
|
+
- asPolygon()
|
|
20
|
+
- asPolyline()
|
|
21
|
+
- edges()
|
|
22
|
+
- resample()
|
|
23
|
+
- splitArcLength()
|
|
24
|
+
- update Group ctor to make attribs optional
|
|
25
|
+
- add/expose subdiv & tessellation presets ([0f79c6d](https://github.com/thi-ng/umbrella/commit/0f79c6d))
|
|
26
|
+
- re-export aliases for subdivCurve() from [@thi.ng/geom-subdiv-curve](https://github.com/thi-ng/umbrella/tree/main/packages/geom-subdiv-curve) (as `SUBDIV_XXX`...)
|
|
27
|
+
- re-export aliases for tessellate() from [@thi.ng/geom-tessellate](https://github.com/thi-ng/umbrella/tree/main/packages/geom-tessellate) (as `TESSELLATE_XXX`...)
|
|
28
|
+
|
|
12
29
|
## [4.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/geom@4.3.0) (2023-03-22)
|
|
13
30
|
|
|
14
31
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ create them, please check linked sources and/or docs.
|
|
|
57
57
|
| [Quad](https://github.com/thi-ng/umbrella/blob/develop/packages/geom/src/quad.ts) | 2D/3D quad (4-gon) | ✅<sup>(1)</sup> |
|
|
58
58
|
| [Quadratic](https://github.com/thi-ng/umbrella/blob/develop/packages/geom/src/quadratic.ts) | nD quadratic bezier | ✅<sup>(1)</sup> |
|
|
59
59
|
| [Ray](https://github.com/thi-ng/umbrella/blob/develop/packages/geom/src/ray.ts) | nD ray | ✅<sup>(1)</sup> |
|
|
60
|
-
| [Rectangle](https://github.com/thi-ng/umbrella/blob/develop/packages/geom/src/
|
|
60
|
+
| [Rectangle](https://github.com/thi-ng/umbrella/blob/develop/packages/geom/src/rect.ts) | 2D rectangle | ✅ |
|
|
61
61
|
| [Sphere](https://github.com/thi-ng/umbrella/blob/develop/packages/geom/src/sphere.ts) | 3D sphere | ✅<sup>(2)</sup> |
|
|
62
62
|
| [Text](https://github.com/thi-ng/umbrella/blob/develop/packages/geom/src/text.ts) | Basic stub for text labels | ✅<sup>(3)</sup> |
|
|
63
63
|
| [Triangle](https://github.com/thi-ng/umbrella/blob/develop/packages/geom/src/triangle.ts) | 2D triangle | ✅ |
|
|
@@ -122,6 +122,7 @@ directly and/or perform automatic resampling/conversion if needed).
|
|
|
122
122
|
| [`scale()`](https://docs.thi.ng/umbrella/geom/functions/scale.html) | scale shape (uniformly/non-uniformly) |
|
|
123
123
|
| [`scatter()`](https://docs.thi.ng/umbrella/geom/functions/scatter.html) | create random points inside a shape boundary |
|
|
124
124
|
| [`simplify()`](https://docs.thi.ng/umbrella/geom/functions/simplify.html) | simplify shape/boundary (Douglas-Peucker) |
|
|
125
|
+
| [`splitArcLength()`](https://docs.thi.ng/umbrella/geom/functions/splitArcLength.html) | split shapes based on max. arc length |
|
|
125
126
|
| [`splitAt()`](https://docs.thi.ng/umbrella/geom/functions/splitAt.html) | split shape/boundary at parametric position |
|
|
126
127
|
| [`splitNear()`](https://docs.thi.ng/umbrella/geom/functions/splitNear.html) | split shape/boundary near world position |
|
|
127
128
|
| [`subdivCurve()`](https://docs.thi.ng/umbrella/geom/functions/subdivCurve.html) | recursively apply curve subdivision kernel |
|
|
@@ -198,7 +199,7 @@ For Node.js REPL:
|
|
|
198
199
|
const geom = await import("@thi.ng/geom");
|
|
199
200
|
```
|
|
200
201
|
|
|
201
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 12.
|
|
202
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 12.62 KB
|
|
202
203
|
|
|
203
204
|
## Dependencies
|
|
204
205
|
|
package/api/group.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Fn } from "@thi.ng/api";
|
|
2
2
|
import type { Attribs, IHiccupShape } from "@thi.ng/geom-api";
|
|
3
3
|
export declare class Group implements IHiccupShape {
|
|
4
|
-
attribs
|
|
4
|
+
attribs?: Attribs | undefined;
|
|
5
5
|
children: IHiccupShape[];
|
|
6
|
-
constructor(attribs
|
|
6
|
+
constructor(attribs?: Attribs | undefined, children?: IHiccupShape[]);
|
|
7
7
|
get type(): string;
|
|
8
8
|
[Symbol.iterator](): Generator<IHiccupShape, void, undefined>;
|
|
9
9
|
copy(): Group;
|
package/as-polygon.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ import { Polygon } from "./api/polygon.js";
|
|
|
7
7
|
* or number of target vertices.
|
|
8
8
|
*
|
|
9
9
|
* @remarks
|
|
10
|
+
* If the shape has a `__samples` attribute, it will be removed in the result to
|
|
11
|
+
* avoid recursive application.
|
|
12
|
+
*
|
|
10
13
|
* Currently implemented for:
|
|
11
14
|
*
|
|
12
15
|
* - {@link Circle}
|
package/as-polygon.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
2
2
|
import { Polygon } from "./api/polygon.js";
|
|
3
|
-
import {
|
|
3
|
+
import { __copyAttribsNoSamples as __attribs } from "./internal/copy.js";
|
|
4
4
|
import { __dispatch } from "./internal/dispatch.js";
|
|
5
5
|
import { vertices } from "./vertices.js";
|
|
6
6
|
/**
|
|
@@ -9,6 +9,9 @@ import { vertices } from "./vertices.js";
|
|
|
9
9
|
* or number of target vertices.
|
|
10
10
|
*
|
|
11
11
|
* @remarks
|
|
12
|
+
* If the shape has a `__samples` attribute, it will be removed in the result to
|
|
13
|
+
* avoid recursive application.
|
|
14
|
+
*
|
|
12
15
|
* Currently implemented for:
|
|
13
16
|
*
|
|
14
17
|
* - {@link Circle}
|
|
@@ -35,5 +38,5 @@ export const asPolygon = defmulti(__dispatch, {
|
|
|
35
38
|
rect: "points",
|
|
36
39
|
tri: "points",
|
|
37
40
|
}, {
|
|
38
|
-
points: ($, opts) => new Polygon(vertices($, opts),
|
|
41
|
+
points: ($, opts) => new Polygon(vertices($, opts), __attribs($)),
|
|
39
42
|
});
|
package/as-polyline.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ import { Polyline } from "./api/polyline.js";
|
|
|
7
7
|
* or number of target vertices.
|
|
8
8
|
*
|
|
9
9
|
* @remarks
|
|
10
|
+
* If the shape has a `__samples` attribute, it will be removed in the result to
|
|
11
|
+
* avoid recursive application.
|
|
12
|
+
*
|
|
10
13
|
* Currently implemented for:
|
|
11
14
|
*
|
|
12
15
|
* - {@link Arc}
|
package/as-polyline.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
2
2
|
import { set } from "@thi.ng/vectors/set";
|
|
3
3
|
import { Polyline } from "./api/polyline.js";
|
|
4
|
-
import {
|
|
4
|
+
import { __copyAttribsNoSamples as __attribs } from "./internal/copy.js";
|
|
5
5
|
import { __dispatch } from "./internal/dispatch.js";
|
|
6
6
|
import { vertices } from "./vertices.js";
|
|
7
7
|
/**
|
|
@@ -10,6 +10,9 @@ import { vertices } from "./vertices.js";
|
|
|
10
10
|
* or number of target vertices.
|
|
11
11
|
*
|
|
12
12
|
* @remarks
|
|
13
|
+
* If the shape has a `__samples` attribute, it will be removed in the result to
|
|
14
|
+
* avoid recursive application.
|
|
15
|
+
*
|
|
13
16
|
* Currently implemented for:
|
|
14
17
|
*
|
|
15
18
|
* - {@link Arc}
|
|
@@ -40,15 +43,15 @@ export const asPolyline = defmulti(__dispatch, {
|
|
|
40
43
|
rect: "poly",
|
|
41
44
|
tri: "poly",
|
|
42
45
|
}, {
|
|
43
|
-
points: ($, opts) => new Polyline(vertices($, opts),
|
|
46
|
+
points: ($, opts) => new Polyline(vertices($, opts), __attribs($)),
|
|
44
47
|
path: ($, opts) => {
|
|
45
48
|
const pts = vertices($, opts);
|
|
46
49
|
$.closed && pts.push(set([], pts[0]));
|
|
47
|
-
return new Polyline(pts,
|
|
50
|
+
return new Polyline(pts, __attribs($));
|
|
48
51
|
},
|
|
49
52
|
poly: ($, opts) => {
|
|
50
53
|
const pts = vertices($, opts);
|
|
51
54
|
pts.push(set([], pts[0]));
|
|
52
|
-
return new Polyline(pts,
|
|
55
|
+
return new Polyline(pts, __attribs($));
|
|
53
56
|
},
|
|
54
57
|
});
|
package/edges.d.ts
CHANGED
|
@@ -3,10 +3,12 @@ import type { IShape, SamplingOpts } from "@thi.ng/geom-api";
|
|
|
3
3
|
import type { VecPair } from "@thi.ng/vectors";
|
|
4
4
|
/**
|
|
5
5
|
* Extracts the edges of given shape's boundary and returns them as an iterable
|
|
6
|
-
* of vector pairs.
|
|
7
|
-
* [`SamplingOpts`](https://docs.thi.ng/umbrella/geom-api/interfaces/SamplingOpts.html).
|
|
6
|
+
* of vector pairs.
|
|
8
7
|
*
|
|
9
8
|
* @remarks
|
|
9
|
+
* If the shape has a `__samples` attribute, it will be removed in the result to
|
|
10
|
+
* avoid recursive application.
|
|
11
|
+
*
|
|
10
12
|
* Currently implemented for:
|
|
11
13
|
*
|
|
12
14
|
* - {@link AABB}
|
|
@@ -15,6 +17,7 @@ import type { VecPair } from "@thi.ng/vectors";
|
|
|
15
17
|
* - {@link Circle}
|
|
16
18
|
* - {@link Cubic}
|
|
17
19
|
* - {@link Ellipse}
|
|
20
|
+
* - {@link Group}
|
|
18
21
|
* - {@link Line}
|
|
19
22
|
* - {@link Path}
|
|
20
23
|
* - {@link Polygon}
|
|
@@ -24,6 +27,17 @@ import type { VecPair } from "@thi.ng/vectors";
|
|
|
24
27
|
* - {@link Rect}
|
|
25
28
|
* - {@link Triangle}
|
|
26
29
|
*
|
|
30
|
+
* The implementations for the following shapes **do not** support
|
|
31
|
+
* [`SamplingOpts`](https://docs.thi.ng/umbrella/geom-api/interfaces/SamplingOpts.html)
|
|
32
|
+
* (all others do):
|
|
33
|
+
*
|
|
34
|
+
* - {@link Line}
|
|
35
|
+
* - {@link Polygon}
|
|
36
|
+
* - {@link Polyline}
|
|
37
|
+
* - {@link Quad}
|
|
38
|
+
* - {@link Rect}
|
|
39
|
+
* - {@link Triangle}
|
|
40
|
+
*
|
|
27
41
|
* @param shape
|
|
28
42
|
* @param opts
|
|
29
43
|
*/
|
package/edges.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
2
|
+
import { mapcat } from "@thi.ng/transducers/mapcat";
|
|
2
3
|
import { asPolygon } from "./as-polygon.js";
|
|
3
4
|
import { asPolyline } from "./as-polyline.js";
|
|
4
5
|
import { __dispatch } from "./internal/dispatch.js";
|
|
@@ -6,10 +7,12 @@ import { __edges } from "./internal/edges.js";
|
|
|
6
7
|
import { vertices } from "./vertices.js";
|
|
7
8
|
/**
|
|
8
9
|
* Extracts the edges of given shape's boundary and returns them as an iterable
|
|
9
|
-
* of vector pairs.
|
|
10
|
-
* [`SamplingOpts`](https://docs.thi.ng/umbrella/geom-api/interfaces/SamplingOpts.html).
|
|
10
|
+
* of vector pairs.
|
|
11
11
|
*
|
|
12
12
|
* @remarks
|
|
13
|
+
* If the shape has a `__samples` attribute, it will be removed in the result to
|
|
14
|
+
* avoid recursive application.
|
|
15
|
+
*
|
|
13
16
|
* Currently implemented for:
|
|
14
17
|
*
|
|
15
18
|
* - {@link AABB}
|
|
@@ -18,6 +21,7 @@ import { vertices } from "./vertices.js";
|
|
|
18
21
|
* - {@link Circle}
|
|
19
22
|
* - {@link Cubic}
|
|
20
23
|
* - {@link Ellipse}
|
|
24
|
+
* - {@link Group}
|
|
21
25
|
* - {@link Line}
|
|
22
26
|
* - {@link Path}
|
|
23
27
|
* - {@link Polygon}
|
|
@@ -27,6 +31,17 @@ import { vertices } from "./vertices.js";
|
|
|
27
31
|
* - {@link Rect}
|
|
28
32
|
* - {@link Triangle}
|
|
29
33
|
*
|
|
34
|
+
* The implementations for the following shapes **do not** support
|
|
35
|
+
* [`SamplingOpts`](https://docs.thi.ng/umbrella/geom-api/interfaces/SamplingOpts.html)
|
|
36
|
+
* (all others do):
|
|
37
|
+
*
|
|
38
|
+
* - {@link Line}
|
|
39
|
+
* - {@link Polygon}
|
|
40
|
+
* - {@link Polyline}
|
|
41
|
+
* - {@link Quad}
|
|
42
|
+
* - {@link Rect}
|
|
43
|
+
* - {@link Triangle}
|
|
44
|
+
*
|
|
30
45
|
* @param shape
|
|
31
46
|
* @param opts
|
|
32
47
|
*/
|
|
@@ -58,6 +73,7 @@ export const edges = defmulti(__dispatch, {
|
|
|
58
73
|
arc: ($, opts) => __edges(asPolyline($, opts).points, false),
|
|
59
74
|
bpatch: ($) => $.edges(),
|
|
60
75
|
circle: ($, opts) => __edges(asPolygon($, opts).points, true),
|
|
76
|
+
group: ($, opts) => mapcat((c) => edges(c, opts), $.children),
|
|
61
77
|
path: ($, opts) => __edges(asPolygon($, opts).points, $.closed),
|
|
62
78
|
poly: ($) => __edges($.points, true),
|
|
63
79
|
polyline: ($) => __edges($.points),
|
package/internal/copy.d.ts
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import type { Attribs, IShape, PCLike, PCLikeConstructor } from "@thi.ng/geom-api";
|
|
2
|
-
/**
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Creates a shallow copy of shape's attribs. Any `exclude` keys will be removed
|
|
4
|
+
* from result attribs.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare const __copyAttribs: ($: IShape, ...exclude: string[]) => Attribs | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Syntax sugar for {@link __copyAttribs}, also removing `__samples` key from
|
|
11
|
+
* result.
|
|
12
|
+
*
|
|
13
|
+
* @param x
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export declare const __copyAttribsNoSamples: (x: IShape) => Attribs | undefined;
|
|
4
18
|
/** @internal */
|
|
5
19
|
export declare const __copyShape: <T extends PCLike>(ctor: PCLikeConstructor, inst: T) => T;
|
|
6
20
|
//# sourceMappingURL=copy.d.ts.map
|
package/internal/copy.js
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
// thing:export
|
|
2
|
+
import { withoutKeysObj } from "@thi.ng/associative/without-keys";
|
|
2
3
|
import { copyVectors } from "@thi.ng/vectors/copy";
|
|
3
|
-
/**
|
|
4
|
-
|
|
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;
|
|
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");
|
|
5
25
|
/** @internal */
|
|
6
26
|
export const __copyShape = (ctor, inst) => new ctor(copyVectors(inst.points), __copyAttribs(inst));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/geom",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"description": "Functional, polymorphic API for 2D geometry types & SVG generation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -42,18 +42,18 @@
|
|
|
42
42
|
"@thi.ng/defmulti": "^2.1.33",
|
|
43
43
|
"@thi.ng/equiv": "^2.1.20",
|
|
44
44
|
"@thi.ng/errors": "^2.2.13",
|
|
45
|
-
"@thi.ng/geom-api": "^3.4.
|
|
46
|
-
"@thi.ng/geom-arc": "^2.1.
|
|
47
|
-
"@thi.ng/geom-clip-line": "^2.3.
|
|
48
|
-
"@thi.ng/geom-clip-poly": "^2.1.
|
|
45
|
+
"@thi.ng/geom-api": "^3.4.11",
|
|
46
|
+
"@thi.ng/geom-arc": "^2.1.54",
|
|
47
|
+
"@thi.ng/geom-clip-line": "^2.3.11",
|
|
48
|
+
"@thi.ng/geom-clip-poly": "^2.1.53",
|
|
49
49
|
"@thi.ng/geom-closest-point": "^2.1.49",
|
|
50
50
|
"@thi.ng/geom-hull": "^2.1.49",
|
|
51
|
-
"@thi.ng/geom-isec": "^2.1.
|
|
52
|
-
"@thi.ng/geom-poly-utils": "^2.3.
|
|
53
|
-
"@thi.ng/geom-resample": "^2.2.
|
|
54
|
-
"@thi.ng/geom-splines": "^2.2.
|
|
55
|
-
"@thi.ng/geom-subdiv-curve": "^2.1.
|
|
56
|
-
"@thi.ng/geom-tessellate": "^2.1.
|
|
51
|
+
"@thi.ng/geom-isec": "^2.1.53",
|
|
52
|
+
"@thi.ng/geom-poly-utils": "^2.3.37",
|
|
53
|
+
"@thi.ng/geom-resample": "^2.2.11",
|
|
54
|
+
"@thi.ng/geom-splines": "^2.2.28",
|
|
55
|
+
"@thi.ng/geom-subdiv-curve": "^2.1.53",
|
|
56
|
+
"@thi.ng/geom-tessellate": "^2.1.53",
|
|
57
57
|
"@thi.ng/hiccup": "^4.2.37",
|
|
58
58
|
"@thi.ng/hiccup-svg": "^4.3.39",
|
|
59
59
|
"@thi.ng/math": "^5.4.5",
|
|
@@ -398,5 +398,5 @@
|
|
|
398
398
|
],
|
|
399
399
|
"year": 2013
|
|
400
400
|
},
|
|
401
|
-
"gitHead": "
|
|
401
|
+
"gitHead": "51a3361eb4b4e906ff6dfc114049f1ea9cd97d0e\n"
|
|
402
402
|
}
|
package/resample.d.ts
CHANGED
|
@@ -5,6 +5,9 @@ import type { IShape, SamplingOpts } from "@thi.ng/geom-api";
|
|
|
5
5
|
* closed) or polyline (if open).
|
|
6
6
|
*
|
|
7
7
|
* @remarks
|
|
8
|
+
* If the shape has a `__samples` attribute, it will be removed in the result to
|
|
9
|
+
* avoid recursive application.
|
|
10
|
+
*
|
|
8
11
|
* Currently implemented for:
|
|
9
12
|
*
|
|
10
13
|
* - {@link Circle}
|
package/resample.js
CHANGED
|
@@ -3,13 +3,16 @@ import { resample as _resample } from "@thi.ng/geom-resample/resample";
|
|
|
3
3
|
import { Polygon } from "./api/polygon.js";
|
|
4
4
|
import { Polyline } from "./api/polyline.js";
|
|
5
5
|
import { asPolygon } from "./as-polygon.js";
|
|
6
|
-
import {
|
|
6
|
+
import { __copyAttribsNoSamples as __attribs } from "./internal/copy.js";
|
|
7
7
|
import { __dispatch } from "./internal/dispatch.js";
|
|
8
8
|
/**
|
|
9
9
|
* Resamples given 2D shape with given options and returns result as polygon (if
|
|
10
10
|
* closed) or polyline (if open).
|
|
11
11
|
*
|
|
12
12
|
* @remarks
|
|
13
|
+
* If the shape has a `__samples` attribute, it will be removed in the result to
|
|
14
|
+
* avoid recursive application.
|
|
15
|
+
*
|
|
13
16
|
* Currently implemented for:
|
|
14
17
|
*
|
|
15
18
|
* - {@link Circle}
|
|
@@ -32,6 +35,6 @@ export const resample = defmulti(__dispatch, {
|
|
|
32
35
|
rect: "circle",
|
|
33
36
|
}, {
|
|
34
37
|
circle: ($, opts) => asPolygon($, opts),
|
|
35
|
-
poly: ($, opts) => new Polygon(_resample($.points, opts, true, true),
|
|
36
|
-
polyline: ($, opts) => new Polyline(_resample($.points, opts, false, true),
|
|
38
|
+
poly: ($, opts) => new Polygon(_resample($.points, opts, true, true), __attribs($)),
|
|
39
|
+
polyline: ($, opts) => new Polyline(_resample($.points, opts, false, true), __attribs($)),
|
|
37
40
|
});
|
package/split-arclength.d.ts
CHANGED
|
@@ -5,6 +5,9 @@ import type { IShape } from "@thi.ng/geom-api";
|
|
|
5
5
|
* Returns array of new shapes/polylines.
|
|
6
6
|
*
|
|
7
7
|
* @remarks
|
|
8
|
+
* If the shape has a `__samples` attribute, it will be removed in the result to
|
|
9
|
+
* avoid recursive application.
|
|
10
|
+
*
|
|
8
11
|
* Currently only implemented for:
|
|
9
12
|
*
|
|
10
13
|
* - {@link Group}
|
|
@@ -13,8 +16,13 @@ import type { IShape } from "@thi.ng/geom-api";
|
|
|
13
16
|
* Other shape types will be attempted to be auto-converted via
|
|
14
17
|
* {@link asPolyline} first.
|
|
15
18
|
*
|
|
19
|
+
* Groups will be recursively processed (i.e. by calling {@link splitArcLength}
|
|
20
|
+
* for each child). Any nested groups will be retained, but each group might
|
|
21
|
+
* have a greater resulting number of children (depending on number of splits
|
|
22
|
+
* performed).
|
|
23
|
+
*
|
|
16
24
|
* @param shape
|
|
17
25
|
* @param dist
|
|
18
26
|
*/
|
|
19
|
-
export declare const
|
|
27
|
+
export declare const splitArcLength: MultiFn2<IShape, number, IShape[]>;
|
|
20
28
|
//# sourceMappingURL=split-arclength.d.ts.map
|
package/split-arclength.js
CHANGED
|
@@ -4,7 +4,7 @@ import { mapcat } from "@thi.ng/transducers/mapcat";
|
|
|
4
4
|
import { Group } from "./api/group.js";
|
|
5
5
|
import { Polyline } from "./api/polyline.js";
|
|
6
6
|
import { asPolyline } from "./as-polyline.js";
|
|
7
|
-
import {
|
|
7
|
+
import { __copyAttribsNoSamples as __attribs } from "./internal/copy.js";
|
|
8
8
|
import { __dispatch } from "./internal/dispatch.js";
|
|
9
9
|
import { __pointArraysAsShapes } from "./internal/points-as-shape.js";
|
|
10
10
|
/**
|
|
@@ -12,6 +12,9 @@ import { __pointArraysAsShapes } from "./internal/points-as-shape.js";
|
|
|
12
12
|
* Returns array of new shapes/polylines.
|
|
13
13
|
*
|
|
14
14
|
* @remarks
|
|
15
|
+
* If the shape has a `__samples` attribute, it will be removed in the result to
|
|
16
|
+
* avoid recursive application.
|
|
17
|
+
*
|
|
15
18
|
* Currently only implemented for:
|
|
16
19
|
*
|
|
17
20
|
* - {@link Group}
|
|
@@ -20,14 +23,19 @@ import { __pointArraysAsShapes } from "./internal/points-as-shape.js";
|
|
|
20
23
|
* Other shape types will be attempted to be auto-converted via
|
|
21
24
|
* {@link asPolyline} first.
|
|
22
25
|
*
|
|
26
|
+
* Groups will be recursively processed (i.e. by calling {@link splitArcLength}
|
|
27
|
+
* for each child). Any nested groups will be retained, but each group might
|
|
28
|
+
* have a greater resulting number of children (depending on number of splits
|
|
29
|
+
* performed).
|
|
30
|
+
*
|
|
23
31
|
* @param shape
|
|
24
32
|
* @param dist
|
|
25
33
|
*/
|
|
26
|
-
export const
|
|
27
|
-
[DEFAULT]: ($, d) =>
|
|
34
|
+
export const splitArcLength = defmulti(__dispatch, {}, {
|
|
35
|
+
[DEFAULT]: ($, d) => splitArcLength(asPolyline($), d),
|
|
28
36
|
group: ($, d) => [
|
|
29
|
-
new Group(
|
|
30
|
-
...mapcat((c) =>
|
|
37
|
+
new Group(__attribs($), [
|
|
38
|
+
...mapcat((c) => splitArcLength(c, d), $.children),
|
|
31
39
|
]),
|
|
32
40
|
],
|
|
33
41
|
polyline: ($, d) => {
|
|
@@ -48,6 +56,6 @@ export const splitArclength = defmulti(__dispatch, {}, {
|
|
|
48
56
|
break;
|
|
49
57
|
}
|
|
50
58
|
}
|
|
51
|
-
return __pointArraysAsShapes(Polyline, chunks,
|
|
59
|
+
return __pointArraysAsShapes(Polyline, chunks, __attribs($));
|
|
52
60
|
},
|
|
53
61
|
});
|
package/subdiv-curve.d.ts
CHANGED
|
@@ -12,12 +12,59 @@ import type { IShape, SubdivKernel } from "@thi.ng/geom-api";
|
|
|
12
12
|
*
|
|
13
13
|
* Currently only implemented for:
|
|
14
14
|
*
|
|
15
|
+
* - {@link Arc}
|
|
16
|
+
* - {@link Circle}
|
|
17
|
+
* - {@link Ellipse}
|
|
18
|
+
* - {@link Line}
|
|
15
19
|
* - {@link Polygon}
|
|
16
20
|
* - {@link Polyline}
|
|
21
|
+
* - {@link Quad}
|
|
22
|
+
* - {@link Rect}
|
|
23
|
+
* - {@link Triangle}
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
*
|
|
28
|
+
* ```
|
|
17
29
|
*
|
|
18
30
|
* @param shape
|
|
19
31
|
* @param kernel
|
|
20
32
|
* @param iter
|
|
21
33
|
*/
|
|
22
34
|
export declare const subdivCurve: MultiFn2O<IShape, SubdivKernel, number, IShape>;
|
|
35
|
+
/**
|
|
36
|
+
* Re-export of thi.ng/geom-subdiv-curve
|
|
37
|
+
* [`SUBDIV_MID_OPEN`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_MID_OPEN.html)
|
|
38
|
+
*/
|
|
39
|
+
export declare const SUBDIV_MID_OPEN: SubdivKernel;
|
|
40
|
+
/**
|
|
41
|
+
* Re-export of thi.ng/geom-subdiv-curve
|
|
42
|
+
* [`SUBDIV_MID_CLOSED`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_MID_CLOSED.html)
|
|
43
|
+
*/
|
|
44
|
+
export declare const SUBDIV_MID_CLOSED: SubdivKernel;
|
|
45
|
+
/**
|
|
46
|
+
* Re-export of thi.ng/geom-subdiv-curve
|
|
47
|
+
* [`SUBDIV_THIRDS_OPEN`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_THIRDS_OPEN.html)
|
|
48
|
+
*/
|
|
49
|
+
export declare const SUBDIV_THIRDS_OPEN: SubdivKernel;
|
|
50
|
+
/**
|
|
51
|
+
* Re-export of thi.ng/geom-subdiv-curve
|
|
52
|
+
* [`SUBDIV_THIRDS_CLOSED`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_THIRDS_CLOSED.html)
|
|
53
|
+
*/
|
|
54
|
+
export declare const SUBDIV_THIRDS_CLOSED: SubdivKernel;
|
|
55
|
+
/**
|
|
56
|
+
* Re-export of thi.ng/geom-subdiv-curve
|
|
57
|
+
* [`SUBDIV_CHAIKIN_OPEN`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_CHAIKIN_OPEN.html)
|
|
58
|
+
*/
|
|
59
|
+
export declare const SUBDIV_CHAIKIN_OPEN: SubdivKernel;
|
|
60
|
+
/**
|
|
61
|
+
* Re-export of thi.ng/geom-subdiv-curve
|
|
62
|
+
* [`SUBDIV_CHAIKIN_CLOSED`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_CHAIKIN_CLOSED.html)
|
|
63
|
+
*/
|
|
64
|
+
export declare const SUBDIV_CHAIKIN_CLOSED: SubdivKernel;
|
|
65
|
+
/**
|
|
66
|
+
* Re-export of thi.ng/geom-subdiv-curve
|
|
67
|
+
* [`SUBDIV_CUBIC_CLOSED`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_CUBIC_CLOSED.html)
|
|
68
|
+
*/
|
|
69
|
+
export declare const SUBDIV_CUBIC_CLOSED: SubdivKernel;
|
|
23
70
|
//# sourceMappingURL=subdiv-curve.d.ts.map
|
package/subdiv-curve.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
2
|
+
import * as sdc from "@thi.ng/geom-subdiv-curve/api";
|
|
2
3
|
import { subdivide } from "@thi.ng/geom-subdiv-curve/subdivide";
|
|
3
4
|
import { Polygon } from "./api/polygon.js";
|
|
4
5
|
import { Polyline } from "./api/polyline.js";
|
|
6
|
+
import { asPolygon } from "./as-polygon.js";
|
|
7
|
+
import { asPolyline } from "./as-polyline.js";
|
|
5
8
|
import { __copyAttribs } from "./internal/copy.js";
|
|
6
9
|
import { __dispatch } from "./internal/dispatch.js";
|
|
7
10
|
/**
|
|
@@ -16,14 +19,69 @@ import { __dispatch } from "./internal/dispatch.js";
|
|
|
16
19
|
*
|
|
17
20
|
* Currently only implemented for:
|
|
18
21
|
*
|
|
22
|
+
* - {@link Arc}
|
|
23
|
+
* - {@link Circle}
|
|
24
|
+
* - {@link Ellipse}
|
|
25
|
+
* - {@link Line}
|
|
19
26
|
* - {@link Polygon}
|
|
20
27
|
* - {@link Polyline}
|
|
28
|
+
* - {@link Quad}
|
|
29
|
+
* - {@link Rect}
|
|
30
|
+
* - {@link Triangle}
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
*
|
|
35
|
+
* ```
|
|
21
36
|
*
|
|
22
37
|
* @param shape
|
|
23
38
|
* @param kernel
|
|
24
39
|
* @param iter
|
|
25
40
|
*/
|
|
26
|
-
export const subdivCurve = defmulti(__dispatch, {
|
|
41
|
+
export const subdivCurve = defmulti(__dispatch, {
|
|
42
|
+
ellipse: "circle",
|
|
43
|
+
line: "polyline",
|
|
44
|
+
quad: "poly",
|
|
45
|
+
rect: "circle",
|
|
46
|
+
tri: "poly",
|
|
47
|
+
}, {
|
|
48
|
+
arc: ($, kernel, iter = 1) => subdivCurve(asPolyline($), kernel, iter),
|
|
49
|
+
circle: ($, kernel, iter = 1) => subdivCurve(asPolygon($), kernel, iter),
|
|
27
50
|
poly: ($, kernel, iter = 1) => new Polygon(subdivide($.points, kernel, iter), __copyAttribs($)),
|
|
28
51
|
polyline: ($, kernel, iter = 1) => new Polyline(subdivide($.points, kernel, iter), __copyAttribs($)),
|
|
29
52
|
});
|
|
53
|
+
/**
|
|
54
|
+
* Re-export of thi.ng/geom-subdiv-curve
|
|
55
|
+
* [`SUBDIV_MID_OPEN`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_MID_OPEN.html)
|
|
56
|
+
*/
|
|
57
|
+
export const SUBDIV_MID_OPEN = sdc.SUBDIV_MID_OPEN;
|
|
58
|
+
/**
|
|
59
|
+
* Re-export of thi.ng/geom-subdiv-curve
|
|
60
|
+
* [`SUBDIV_MID_CLOSED`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_MID_CLOSED.html)
|
|
61
|
+
*/
|
|
62
|
+
export const SUBDIV_MID_CLOSED = sdc.SUBDIV_MID_CLOSED;
|
|
63
|
+
/**
|
|
64
|
+
* Re-export of thi.ng/geom-subdiv-curve
|
|
65
|
+
* [`SUBDIV_THIRDS_OPEN`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_THIRDS_OPEN.html)
|
|
66
|
+
*/
|
|
67
|
+
export const SUBDIV_THIRDS_OPEN = sdc.SUBDIV_THIRDS_OPEN;
|
|
68
|
+
/**
|
|
69
|
+
* Re-export of thi.ng/geom-subdiv-curve
|
|
70
|
+
* [`SUBDIV_THIRDS_CLOSED`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_THIRDS_CLOSED.html)
|
|
71
|
+
*/
|
|
72
|
+
export const SUBDIV_THIRDS_CLOSED = sdc.SUBDIV_THIRDS_CLOSED;
|
|
73
|
+
/**
|
|
74
|
+
* Re-export of thi.ng/geom-subdiv-curve
|
|
75
|
+
* [`SUBDIV_CHAIKIN_OPEN`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_CHAIKIN_OPEN.html)
|
|
76
|
+
*/
|
|
77
|
+
export const SUBDIV_CHAIKIN_OPEN = sdc.SUBDIV_CHAIKIN_OPEN;
|
|
78
|
+
/**
|
|
79
|
+
* Re-export of thi.ng/geom-subdiv-curve
|
|
80
|
+
* [`SUBDIV_CHAIKIN_CLOSED`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_CHAIKIN_CLOSED.html)
|
|
81
|
+
*/
|
|
82
|
+
export const SUBDIV_CHAIKIN_CLOSED = sdc.SUBDIV_CHAIKIN_CLOSED;
|
|
83
|
+
/**
|
|
84
|
+
* Re-export of thi.ng/geom-subdiv-curve
|
|
85
|
+
* [`SUBDIV_CUBIC_CLOSED`](https://docs.thi.ng/umbrella/geom-subdiv-curve/variables/SUBDIV_CUBIC_CLOSED.html)
|
|
86
|
+
*/
|
|
87
|
+
export const SUBDIV_CUBIC_CLOSED = sdc.SUBDIV_CUBIC_CLOSED;
|
package/tessellate.d.ts
CHANGED
|
@@ -14,4 +14,34 @@ import type { Vec } from "@thi.ng/vectors";
|
|
|
14
14
|
* @param tessellators
|
|
15
15
|
*/
|
|
16
16
|
export declare const tessellate: import("@thi.ng/defmulti").MultiFn2<IShape<IShape<any>>, Tessellator[], Vec[][]>;
|
|
17
|
+
/**
|
|
18
|
+
* Alias for thi.ng/geom-tessellate
|
|
19
|
+
* [`earCut2`](https://docs.thi.ng/umbrella/geom-tessellate/functions/earCut2.html)
|
|
20
|
+
*/
|
|
21
|
+
export declare const TESSELLATE_EARCUT: Tessellator;
|
|
22
|
+
/**
|
|
23
|
+
* Alias for thi.ng/geom-tessellate
|
|
24
|
+
* [`edgeSplit`](https://docs.thi.ng/umbrella/geom-tessellate/functions/edgeSplit.html)
|
|
25
|
+
*/
|
|
26
|
+
export declare const TESSELLATE_EDGE_SPLIT: Tessellator;
|
|
27
|
+
/**
|
|
28
|
+
* Alias for thi.ng/geom-tessellate
|
|
29
|
+
* [`tesselInset`](https://docs.thi.ng/umbrella/geom-tessellate/functions/tesselInset.html)
|
|
30
|
+
*/
|
|
31
|
+
export declare const TESSELLATE_INSET: (inset?: number | undefined, keepInterior?: boolean | undefined) => Tessellator;
|
|
32
|
+
/**
|
|
33
|
+
* Alias for thi.ng/geom-tessellate
|
|
34
|
+
* [`quadFan`](https://docs.thi.ng/umbrella/geom-tessellate/functions/quadFan.html)
|
|
35
|
+
*/
|
|
36
|
+
export declare const TESSELLATE_QUAD_FAN: Tessellator;
|
|
37
|
+
/**
|
|
38
|
+
* Alias for thi.ng/geom-tessellate
|
|
39
|
+
* [`rimTris`](https://docs.thi.ng/umbrella/geom-tessellate/functions/rimTris.html)
|
|
40
|
+
*/
|
|
41
|
+
export declare const TESSELLATE_RIM_TRIS: Tessellator;
|
|
42
|
+
/**
|
|
43
|
+
* Alias for thi.ng/geom-tessellate
|
|
44
|
+
* [`triFan`](https://docs.thi.ng/umbrella/geom-tessellate/functions/triFan.html)
|
|
45
|
+
*/
|
|
46
|
+
export declare const TESSELLATE_TRI_FAN: Tessellator;
|
|
17
47
|
//# sourceMappingURL=tessellate.d.ts.map
|
package/tessellate.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { DEFAULT, defmulti } from "@thi.ng/defmulti/defmulti";
|
|
2
|
+
import { earCut2 } from "@thi.ng/geom-tessellate/earcut";
|
|
3
|
+
import { edgeSplit } from "@thi.ng/geom-tessellate/edge-split";
|
|
4
|
+
import { tesselInset } from "@thi.ng/geom-tessellate/inset";
|
|
5
|
+
import { quadFan } from "@thi.ng/geom-tessellate/quad-fan";
|
|
6
|
+
import { rimTris } from "@thi.ng/geom-tessellate/rim-tris";
|
|
2
7
|
import { tessellate as _tessellate } from "@thi.ng/geom-tessellate/tessellate";
|
|
8
|
+
import { triFan } from "@thi.ng/geom-tessellate/tri-fan";
|
|
3
9
|
import { __dispatch } from "./internal/dispatch.js";
|
|
4
10
|
import { vertices } from "./vertices.js";
|
|
5
11
|
/**
|
|
@@ -18,3 +24,33 @@ import { vertices } from "./vertices.js";
|
|
|
18
24
|
export const tessellate = defmulti(__dispatch, {}, {
|
|
19
25
|
[DEFAULT]: ($, fns) => _tessellate(vertices($), fns),
|
|
20
26
|
});
|
|
27
|
+
/**
|
|
28
|
+
* Alias for thi.ng/geom-tessellate
|
|
29
|
+
* [`earCut2`](https://docs.thi.ng/umbrella/geom-tessellate/functions/earCut2.html)
|
|
30
|
+
*/
|
|
31
|
+
export const TESSELLATE_EARCUT = earCut2;
|
|
32
|
+
/**
|
|
33
|
+
* Alias for thi.ng/geom-tessellate
|
|
34
|
+
* [`edgeSplit`](https://docs.thi.ng/umbrella/geom-tessellate/functions/edgeSplit.html)
|
|
35
|
+
*/
|
|
36
|
+
export const TESSELLATE_EDGE_SPLIT = edgeSplit;
|
|
37
|
+
/**
|
|
38
|
+
* Alias for thi.ng/geom-tessellate
|
|
39
|
+
* [`tesselInset`](https://docs.thi.ng/umbrella/geom-tessellate/functions/tesselInset.html)
|
|
40
|
+
*/
|
|
41
|
+
export const TESSELLATE_INSET = tesselInset;
|
|
42
|
+
/**
|
|
43
|
+
* Alias for thi.ng/geom-tessellate
|
|
44
|
+
* [`quadFan`](https://docs.thi.ng/umbrella/geom-tessellate/functions/quadFan.html)
|
|
45
|
+
*/
|
|
46
|
+
export const TESSELLATE_QUAD_FAN = quadFan;
|
|
47
|
+
/**
|
|
48
|
+
* Alias for thi.ng/geom-tessellate
|
|
49
|
+
* [`rimTris`](https://docs.thi.ng/umbrella/geom-tessellate/functions/rimTris.html)
|
|
50
|
+
*/
|
|
51
|
+
export const TESSELLATE_RIM_TRIS = rimTris;
|
|
52
|
+
/**
|
|
53
|
+
* Alias for thi.ng/geom-tessellate
|
|
54
|
+
* [`triFan`](https://docs.thi.ng/umbrella/geom-tessellate/functions/triFan.html)
|
|
55
|
+
*/
|
|
56
|
+
export const TESSELLATE_TRI_FAN = triFan;
|