@thi.ng/geom 4.2.12 → 4.3.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 +8 -1
- package/README.md +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +5 -2
- package/polyline.d.ts +20 -1
- package/polyline.js +25 -0
- package/split-arclength.d.ts +20 -0
- package/split-arclength.js +53 -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-22T22:24:21Z
|
|
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,13 @@ 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.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/geom@4.3.0) (2023-03-22)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add splitArclength() ([906a326](https://github.com/thi-ng/umbrella/commit/906a326))
|
|
17
|
+
- add spiral() polyline factory fn ([572e0ef](https://github.com/thi-ng/umbrella/commit/572e0ef))
|
|
18
|
+
|
|
12
19
|
## [4.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/geom@4.2.0) (2023-01-10)
|
|
13
20
|
|
|
14
21
|
#### 🚀 Features
|
package/README.md
CHANGED
package/index.d.ts
CHANGED
|
@@ -69,6 +69,7 @@ export * from "./rotate.js";
|
|
|
69
69
|
export * from "./scale.js";
|
|
70
70
|
export * from "./scatter.js";
|
|
71
71
|
export * from "./simplify.js";
|
|
72
|
+
export * from "./split-arclength.js";
|
|
72
73
|
export * from "./split-at.js";
|
|
73
74
|
export * from "./split-near.js";
|
|
74
75
|
export * from "./subdiv-curve.js";
|
package/index.js
CHANGED
|
@@ -69,6 +69,7 @@ export * from "./rotate.js";
|
|
|
69
69
|
export * from "./scale.js";
|
|
70
70
|
export * from "./scatter.js";
|
|
71
71
|
export * from "./simplify.js";
|
|
72
|
+
export * from "./split-arclength.js";
|
|
72
73
|
export * from "./split-at.js";
|
|
73
74
|
export * from "./split-near.js";
|
|
74
75
|
export * from "./subdiv-curve.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/geom",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "Functional, polymorphic API for 2D geometry types & SVG generation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -334,6 +334,9 @@
|
|
|
334
334
|
"./sphere": {
|
|
335
335
|
"default": "./sphere.js"
|
|
336
336
|
},
|
|
337
|
+
"./split-arclength": {
|
|
338
|
+
"default": "./split-arclength.js"
|
|
339
|
+
},
|
|
337
340
|
"./split-at": {
|
|
338
341
|
"default": "./split-at.js"
|
|
339
342
|
},
|
|
@@ -395,5 +398,5 @@
|
|
|
395
398
|
],
|
|
396
399
|
"year": 2013
|
|
397
400
|
},
|
|
398
|
-
"gitHead": "
|
|
401
|
+
"gitHead": "5b3d731c0e192c53f65efb4baed97be0e4029a33\n"
|
|
399
402
|
}
|
package/polyline.d.ts
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
import type { Attribs } from "@thi.ng/geom-api";
|
|
2
|
-
import type { Vec } from "@thi.ng/vectors";
|
|
2
|
+
import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
|
|
3
3
|
import { Polyline } from "./api/polyline.js";
|
|
4
4
|
export declare const polyline: (pts: Vec[], attribs?: Attribs) => Polyline;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a polyline spiral from given params. The number of twists is defined
|
|
7
|
+
* by the angle range. Resolution depends on angle range and number of steps.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* // 4 full turns over 80 steps
|
|
12
|
+
* spiral([0, 0], 5, 100, 0, Math.PI * 2 * 4, 80);
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @param origin
|
|
16
|
+
* @param r1
|
|
17
|
+
* @param r2
|
|
18
|
+
* @param startTheta
|
|
19
|
+
* @param endTheta
|
|
20
|
+
* @param steps
|
|
21
|
+
* @param attribs
|
|
22
|
+
*/
|
|
23
|
+
export declare const spiral: (origin: ReadonlyVec, r1: number, r2: number, startTheta: number, endTheta: number, steps: number, attribs?: Attribs) => Polyline;
|
|
5
24
|
//# sourceMappingURL=polyline.d.ts.map
|
package/polyline.js
CHANGED
|
@@ -1,2 +1,27 @@
|
|
|
1
|
+
import { mix } from "@thi.ng/math/mix";
|
|
2
|
+
import { map } from "@thi.ng/transducers/map";
|
|
3
|
+
import { normRange } from "@thi.ng/transducers/norm-range";
|
|
4
|
+
import { cartesian2 } from "@thi.ng/vectors/cartesian";
|
|
1
5
|
import { Polyline } from "./api/polyline.js";
|
|
2
6
|
export const polyline = (pts, attribs) => new Polyline(pts, attribs);
|
|
7
|
+
/**
|
|
8
|
+
* Creates a polyline spiral from given params. The number of twists is defined
|
|
9
|
+
* by the angle range. Resolution depends on angle range and number of steps.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // 4 full turns over 80 steps
|
|
14
|
+
* spiral([0, 0], 5, 100, 0, Math.PI * 2 * 4, 80);
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @param origin
|
|
18
|
+
* @param r1
|
|
19
|
+
* @param r2
|
|
20
|
+
* @param startTheta
|
|
21
|
+
* @param endTheta
|
|
22
|
+
* @param steps
|
|
23
|
+
* @param attribs
|
|
24
|
+
*/
|
|
25
|
+
export const spiral = (origin, r1, r2, startTheta, endTheta, steps, attribs) => new Polyline([
|
|
26
|
+
...map((t) => cartesian2(null, [mix(r1, r2, t), mix(startTheta, endTheta, t)], origin), normRange(steps - 1)),
|
|
27
|
+
], attribs);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MultiFn2 } from "@thi.ng/defmulti";
|
|
2
|
+
import type { IShape } from "@thi.ng/geom-api";
|
|
3
|
+
/**
|
|
4
|
+
* Splits given shape into {@link Polyline} segments of given (max) arc length.
|
|
5
|
+
* Returns array of new shapes/polylines.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Currently only implemented for:
|
|
9
|
+
*
|
|
10
|
+
* - {@link Group}
|
|
11
|
+
* - {@link Polyline}
|
|
12
|
+
*
|
|
13
|
+
* Other shape types will be attempted to be auto-converted via
|
|
14
|
+
* {@link asPolyline} first.
|
|
15
|
+
*
|
|
16
|
+
* @param shape
|
|
17
|
+
* @param dist
|
|
18
|
+
*/
|
|
19
|
+
export declare const splitArclength: MultiFn2<IShape, number, IShape[]>;
|
|
20
|
+
//# sourceMappingURL=split-arclength.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { DEFAULT, defmulti } from "@thi.ng/defmulti/defmulti";
|
|
2
|
+
import { Sampler } from "@thi.ng/geom-resample/sampler";
|
|
3
|
+
import { mapcat } from "@thi.ng/transducers/mapcat";
|
|
4
|
+
import { Group } from "./api/group.js";
|
|
5
|
+
import { Polyline } from "./api/polyline.js";
|
|
6
|
+
import { asPolyline } from "./as-polyline.js";
|
|
7
|
+
import { __copyAttribs } from "./internal/copy.js";
|
|
8
|
+
import { __dispatch } from "./internal/dispatch.js";
|
|
9
|
+
import { __pointArraysAsShapes } from "./internal/points-as-shape.js";
|
|
10
|
+
/**
|
|
11
|
+
* Splits given shape into {@link Polyline} segments of given (max) arc length.
|
|
12
|
+
* Returns array of new shapes/polylines.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* Currently only implemented for:
|
|
16
|
+
*
|
|
17
|
+
* - {@link Group}
|
|
18
|
+
* - {@link Polyline}
|
|
19
|
+
*
|
|
20
|
+
* Other shape types will be attempted to be auto-converted via
|
|
21
|
+
* {@link asPolyline} first.
|
|
22
|
+
*
|
|
23
|
+
* @param shape
|
|
24
|
+
* @param dist
|
|
25
|
+
*/
|
|
26
|
+
export const splitArclength = defmulti(__dispatch, {}, {
|
|
27
|
+
[DEFAULT]: ($, d) => splitArclength(asPolyline($), d),
|
|
28
|
+
group: ($, d) => [
|
|
29
|
+
new Group(__copyAttribs($.attribs), [
|
|
30
|
+
...mapcat((c) => splitArclength(c, d), $.children),
|
|
31
|
+
]),
|
|
32
|
+
],
|
|
33
|
+
polyline: ($, d) => {
|
|
34
|
+
const chunks = [];
|
|
35
|
+
let pts = $.points;
|
|
36
|
+
while (true) {
|
|
37
|
+
const sampler = new Sampler(pts);
|
|
38
|
+
const total = sampler.totalLength();
|
|
39
|
+
if (total > d) {
|
|
40
|
+
const parts = sampler.splitAt(d / total);
|
|
41
|
+
if (!parts)
|
|
42
|
+
break;
|
|
43
|
+
chunks.push(parts[0]);
|
|
44
|
+
pts = parts[1];
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
chunks.push(pts);
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return __pointArraysAsShapes(Polyline, chunks, $.attribs);
|
|
52
|
+
},
|
|
53
|
+
});
|