@thi.ng/geom 4.1.0 → 4.2.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 +11 -1
- package/README.md +2 -1
- package/internal/vertices.d.ts +12 -0
- package/internal/vertices.js +35 -0
- package/package.json +33 -30
- package/vertices.js +9 -29
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**:
|
|
3
|
+
- **Last updated**: 2023-01-10T15:20: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,16 @@ 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.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/geom@4.2.0) (2023-01-10)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- update vertices() for circle, ellipse, group ([9ff890a](https://github.com/thi-ng/umbrella/commit/9ff890a))
|
|
17
|
+
- add support for SamplingOpts.start (circle/ellipse)
|
|
18
|
+
- add SamplingOpts support for groups
|
|
19
|
+
- migrate internal helpers
|
|
20
|
+
- update export maps
|
|
21
|
+
|
|
12
22
|
## [4.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/geom@4.1.0) (2022-12-22)
|
|
13
23
|
|
|
14
24
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -158,6 +158,7 @@ packages (which are more low-level, lightweight and usable by themselves too):
|
|
|
158
158
|
- [@thi.ng/geom-splines](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-splines) - nD cubic & quadratic curve analysis, conversion, interpolation, splitting
|
|
159
159
|
- [@thi.ng/geom-subdiv-curve](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-subdiv-curve) - Freely customizable, iterative nD subdivision curves for open / closed geometries
|
|
160
160
|
- [@thi.ng/geom-tessellate](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-tessellate) - 2D/3D convex polygon tessellators
|
|
161
|
+
- [@thi.ng/geom-trace-bitmap](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-trace-bitmap) - Bitmap image to hairline vector and point cloud conversions
|
|
161
162
|
- [@thi.ng/geom-voronoi](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-voronoi) - Fast, incremental 2D Delaunay & Voronoi mesh implementation
|
|
162
163
|
|
|
163
164
|
## Status
|
|
@@ -269,4 +270,4 @@ If this project contributes to an academic publication, please cite it as:
|
|
|
269
270
|
|
|
270
271
|
## License
|
|
271
272
|
|
|
272
|
-
© 2013 -
|
|
273
|
+
© 2013 - 2023 Karsten Schmidt // Apache License 2.0
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Attribs } from "@thi.ng/geom-api";
|
|
2
|
+
import { SamplingOpts } from "@thi.ng/geom-api/sample";
|
|
3
|
+
/** @internal */
|
|
4
|
+
export declare const __circleOpts: (opts: number | Partial<SamplingOpts>, r: number) => [number, number, boolean];
|
|
5
|
+
/**
|
|
6
|
+
* @param opts
|
|
7
|
+
* @param attribs
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare const __sampleAttribs: (opts?: number | Partial<SamplingOpts>, attribs?: Attribs) => number | Partial<SamplingOpts> | undefined;
|
|
12
|
+
//# sourceMappingURL=vertices.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// thing:export
|
|
2
|
+
import { isNumber } from "@thi.ng/checks/is-number";
|
|
3
|
+
import { DEFAULT_SAMPLES } from "@thi.ng/geom-api/sample";
|
|
4
|
+
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;
|
|
35
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/geom",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Functional, polymorphic API for 2D geometry types & SVG generation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -35,37 +35,37 @@
|
|
|
35
35
|
"tool:bpatch": "tools:node-esm tools/bpatch.ts"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@thi.ng/api": "^8.6.
|
|
39
|
-
"@thi.ng/arrays": "^2.
|
|
40
|
-
"@thi.ng/associative": "^6.2.
|
|
41
|
-
"@thi.ng/checks": "^3.3.
|
|
42
|
-
"@thi.ng/defmulti": "^2.1.
|
|
43
|
-
"@thi.ng/equiv": "^2.1.
|
|
44
|
-
"@thi.ng/errors": "^2.2.
|
|
45
|
-
"@thi.ng/geom-api": "^3.
|
|
46
|
-
"@thi.ng/geom-arc": "^2.1.
|
|
47
|
-
"@thi.ng/geom-clip-line": "^2.
|
|
48
|
-
"@thi.ng/geom-clip-poly": "^2.1.
|
|
49
|
-
"@thi.ng/geom-closest-point": "^2.1.
|
|
50
|
-
"@thi.ng/geom-hull": "^2.1.
|
|
51
|
-
"@thi.ng/geom-isec": "^2.1.
|
|
52
|
-
"@thi.ng/geom-poly-utils": "^2.3.
|
|
53
|
-
"@thi.ng/geom-resample": "^2.
|
|
54
|
-
"@thi.ng/geom-splines": "^2.2.
|
|
55
|
-
"@thi.ng/geom-subdiv-curve": "^2.1.
|
|
56
|
-
"@thi.ng/geom-tessellate": "^2.1.
|
|
57
|
-
"@thi.ng/hiccup": "^4.2.
|
|
58
|
-
"@thi.ng/hiccup-svg": "^4.3.
|
|
59
|
-
"@thi.ng/math": "^5.
|
|
60
|
-
"@thi.ng/matrices": "^2.1.
|
|
61
|
-
"@thi.ng/random": "^3.3.
|
|
62
|
-
"@thi.ng/strings": "^3.3.
|
|
63
|
-
"@thi.ng/transducers": "^8.3.
|
|
64
|
-
"@thi.ng/vectors": "^7.5.
|
|
38
|
+
"@thi.ng/api": "^8.6.3",
|
|
39
|
+
"@thi.ng/arrays": "^2.5.1",
|
|
40
|
+
"@thi.ng/associative": "^6.2.23",
|
|
41
|
+
"@thi.ng/checks": "^3.3.7",
|
|
42
|
+
"@thi.ng/defmulti": "^2.1.27",
|
|
43
|
+
"@thi.ng/equiv": "^2.1.17",
|
|
44
|
+
"@thi.ng/errors": "^2.2.8",
|
|
45
|
+
"@thi.ng/geom-api": "^3.4.0",
|
|
46
|
+
"@thi.ng/geom-arc": "^2.1.43",
|
|
47
|
+
"@thi.ng/geom-clip-line": "^2.3.0",
|
|
48
|
+
"@thi.ng/geom-clip-poly": "^2.1.42",
|
|
49
|
+
"@thi.ng/geom-closest-point": "^2.1.39",
|
|
50
|
+
"@thi.ng/geom-hull": "^2.1.39",
|
|
51
|
+
"@thi.ng/geom-isec": "^2.1.42",
|
|
52
|
+
"@thi.ng/geom-poly-utils": "^2.3.26",
|
|
53
|
+
"@thi.ng/geom-resample": "^2.2.0",
|
|
54
|
+
"@thi.ng/geom-splines": "^2.2.17",
|
|
55
|
+
"@thi.ng/geom-subdiv-curve": "^2.1.42",
|
|
56
|
+
"@thi.ng/geom-tessellate": "^2.1.42",
|
|
57
|
+
"@thi.ng/hiccup": "^4.2.29",
|
|
58
|
+
"@thi.ng/hiccup-svg": "^4.3.28",
|
|
59
|
+
"@thi.ng/math": "^5.4.0",
|
|
60
|
+
"@thi.ng/matrices": "^2.1.40",
|
|
61
|
+
"@thi.ng/random": "^3.3.21",
|
|
62
|
+
"@thi.ng/strings": "^3.3.23",
|
|
63
|
+
"@thi.ng/transducers": "^8.3.30",
|
|
64
|
+
"@thi.ng/vectors": "^7.5.31"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@microsoft/api-extractor": "^7.33.7",
|
|
68
|
-
"@thi.ng/testament": "^0.3.
|
|
68
|
+
"@thi.ng/testament": "^0.3.9",
|
|
69
69
|
"rimraf": "^3.0.2",
|
|
70
70
|
"tools": "^0.0.1",
|
|
71
71
|
"typedoc": "^0.23.22",
|
|
@@ -262,6 +262,9 @@
|
|
|
262
262
|
"./internal/transform": {
|
|
263
263
|
"default": "./internal/transform.js"
|
|
264
264
|
},
|
|
265
|
+
"./internal/vertices": {
|
|
266
|
+
"default": "./internal/vertices.js"
|
|
267
|
+
},
|
|
265
268
|
"./intersects": {
|
|
266
269
|
"default": "./intersects.js"
|
|
267
270
|
},
|
|
@@ -383,5 +386,5 @@
|
|
|
383
386
|
"thi.ng": {
|
|
384
387
|
"year": 2013
|
|
385
388
|
},
|
|
386
|
-
"gitHead": "
|
|
389
|
+
"gitHead": "3f0b3e2a7c82aefc7e46fb4338369836b5e1b8cf\n"
|
|
387
390
|
}
|
package/vertices.js
CHANGED
|
@@ -14,6 +14,7 @@ import { madd2 } from "@thi.ng/vectors/madd";
|
|
|
14
14
|
import { set2 } from "@thi.ng/vectors/set";
|
|
15
15
|
import { Polygon } from "./api/polygon.js";
|
|
16
16
|
import { __dispatch } from "./internal/dispatch.js";
|
|
17
|
+
import { __circleOpts, __sampleAttribs } from "./internal/vertices.js";
|
|
17
18
|
/**
|
|
18
19
|
* Extracts/samples vertices from given shape's boundary and returns them as
|
|
19
20
|
* array. Some shapes also support
|
|
@@ -94,12 +95,12 @@ export const vertices = defmulti(__dispatch, {
|
|
|
94
95
|
opts = __sampleAttribs(opts, $.attribs);
|
|
95
96
|
const pos = $.pos;
|
|
96
97
|
const r = $.r;
|
|
97
|
-
let [num, last] = __circleOpts(opts, r);
|
|
98
|
+
let [num, start, last] = __circleOpts(opts, r);
|
|
98
99
|
const delta = TAU / num;
|
|
99
100
|
last && num++;
|
|
100
101
|
const buf = new Array(num);
|
|
101
102
|
for (let i = 0; i < num; i++) {
|
|
102
|
-
buf[i] = cartesian2(null, [r, i * delta], pos);
|
|
103
|
+
buf[i] = cartesian2(null, [r, start + i * delta], pos);
|
|
103
104
|
}
|
|
104
105
|
return buf;
|
|
105
106
|
},
|
|
@@ -109,15 +110,18 @@ export const vertices = defmulti(__dispatch, {
|
|
|
109
110
|
const buf = [];
|
|
110
111
|
const pos = $.pos;
|
|
111
112
|
const r = $.r;
|
|
112
|
-
let [num, last] = __circleOpts(opts, Math.max($.r[0], $.r[1]));
|
|
113
|
+
let [num, start, last] = __circleOpts(opts, Math.max($.r[0], $.r[1]));
|
|
113
114
|
const delta = TAU / num;
|
|
114
115
|
last && num++;
|
|
115
116
|
for (let i = 0; i < num; i++) {
|
|
116
|
-
buf[i] = madd2([], cossin(i * delta), r, pos);
|
|
117
|
+
buf[i] = madd2([], cossin(start + i * delta), r, pos);
|
|
117
118
|
}
|
|
118
119
|
return buf;
|
|
119
120
|
},
|
|
120
|
-
group: (
|
|
121
|
+
group: ($, opts) => {
|
|
122
|
+
opts = __sampleAttribs(opts, $.attribs);
|
|
123
|
+
return $.children.reduce((acc, $) => acc.concat(vertices($, opts)), []);
|
|
124
|
+
},
|
|
121
125
|
path: ($, opts) => {
|
|
122
126
|
opts = __sampleAttribs(opts, $.attribs);
|
|
123
127
|
const _opts = isNumber(opts) ? { num: opts } : opts;
|
|
@@ -153,27 +157,3 @@ export const vertices = defmulti(__dispatch, {
|
|
|
153
157
|
* @param shape -
|
|
154
158
|
*/
|
|
155
159
|
export const ensureVertices = (shape) => isArray(shape) ? shape : vertices(shape);
|
|
156
|
-
/** @internal */
|
|
157
|
-
const __circleOpts = (opts, r) => isNumber(opts)
|
|
158
|
-
? [opts, false]
|
|
159
|
-
: [
|
|
160
|
-
opts.theta
|
|
161
|
-
? Math.floor(TAU / opts.theta)
|
|
162
|
-
: opts.dist
|
|
163
|
-
? Math.floor(TAU / (opts.dist / r))
|
|
164
|
-
: opts.num || DEFAULT_SAMPLES,
|
|
165
|
-
opts.last === true,
|
|
166
|
-
];
|
|
167
|
-
const __sampleAttribs = (opts, attribs) => {
|
|
168
|
-
if (attribs) {
|
|
169
|
-
const val = attribs.__samples;
|
|
170
|
-
return isNumber(opts)
|
|
171
|
-
? isNumber(val)
|
|
172
|
-
? val
|
|
173
|
-
: { num: opts, ...val }
|
|
174
|
-
: isNumber(val)
|
|
175
|
-
? { ...opts, num: val }
|
|
176
|
-
: { ...opts, ...val };
|
|
177
|
-
}
|
|
178
|
-
return opts;
|
|
179
|
-
};
|