@thi.ng/geom 3.1.5 → 3.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 +9 -1
- package/README.md +4 -3
- package/aabb.d.ts +2 -2
- package/aabb.js +2 -2
- package/api/bpatch.d.ts +38 -0
- package/api/bpatch.js +100 -0
- package/as-svg.d.ts +12 -0
- package/as-svg.js +22 -5
- package/bounds.js +5 -5
- package/bpatch.d.ts +7 -0
- package/bpatch.js +20 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +41 -33
- package/rect.d.ts +2 -2
- package/rect.js +2 -2
- package/vertices.d.ts +1 -1
- package/vertices.js +2 -1
- package/warp-points.d.ts +4 -1
- package/warp-points.js +9 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**:
|
|
3
|
+
- **Last updated**: 2022-03-11T12:13:49Z
|
|
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,14 @@ 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
|
+
## [3.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/geom@3.2.0) (2022-03-11)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- update/refactor various shape ops ([0e3b99a](https://github.com/thi-ng/umbrella/commit/0e3b99a))
|
|
17
|
+
- add BPatch type, ctors and warp fn ([ea81cb5](https://github.com/thi-ng/umbrella/commit/ea81cb5))
|
|
18
|
+
- add opt. bleed attrib for `svgDoc()` ([fb3ed1e](https://github.com/thi-ng/umbrella/commit/fb3ed1e))
|
|
19
|
+
|
|
12
20
|
## [3.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/geom@3.1.0) (2021-11-17)
|
|
13
21
|
|
|
14
22
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ themselves too):
|
|
|
41
41
|
- [@thi.ng/geom-api](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-api) - Shared type & interface declarations for [@thi.ng/geom](https://github.com/thi-ng/umbrella/tree/develop/packages/geom) packages
|
|
42
42
|
- [@thi.ng/geom-arc](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-arc) - 2D circular / elliptic arc operations
|
|
43
43
|
- [@thi.ng/geom-clip-line](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-clip-line) - 2D line clipping (Liang-Barsky)
|
|
44
|
-
- [@thi.ng/geom-clip-poly](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-clip-poly) - 2D
|
|
44
|
+
- [@thi.ng/geom-clip-poly](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-clip-poly) - 2D polygon clipping / offsetting (Sutherland-Hodgeman, Grainer-Hormann)
|
|
45
45
|
- [@thi.ng/geom-closest-point](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-closest-point) - 2D / 3D closest point / proximity helpers
|
|
46
46
|
- [@thi.ng/geom-fuzz](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-fuzz) - Highly configurable, fuzzy line & polygon creation with presets and composable fill & stroke styles. Canvas & SVG support
|
|
47
47
|
- [@thi.ng/geom-hull](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-hull) - Fast 2D convex hull (Graham Scan)
|
|
@@ -84,12 +84,13 @@ node --experimental-repl-await
|
|
|
84
84
|
> const geom = await import("@thi.ng/geom");
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
Package sizes (gzipped, pre-treeshake): ESM:
|
|
87
|
+
Package sizes (gzipped, pre-treeshake): ESM: 12.43 KB
|
|
88
88
|
|
|
89
89
|
## Dependencies
|
|
90
90
|
|
|
91
91
|
- [@thi.ng/api](https://github.com/thi-ng/umbrella/tree/develop/packages/api)
|
|
92
92
|
- [@thi.ng/arrays](https://github.com/thi-ng/umbrella/tree/develop/packages/arrays)
|
|
93
|
+
- [@thi.ng/associative](https://github.com/thi-ng/umbrella/tree/develop/packages/associative)
|
|
93
94
|
- [@thi.ng/checks](https://github.com/thi-ng/umbrella/tree/develop/packages/checks)
|
|
94
95
|
- [@thi.ng/defmulti](https://github.com/thi-ng/umbrella/tree/develop/packages/defmulti)
|
|
95
96
|
- [@thi.ng/equiv](https://github.com/thi-ng/umbrella/tree/develop/packages/equiv)
|
|
@@ -165,4 +166,4 @@ If this project contributes to an academic publication, please cite it as:
|
|
|
165
166
|
|
|
166
167
|
## License
|
|
167
168
|
|
|
168
|
-
© 2013 -
|
|
169
|
+
© 2013 - 2022 Karsten Schmidt // Apache Software License 2.0
|
package/aabb.d.ts
CHANGED
|
@@ -10,8 +10,8 @@ export declare const aabbFromMinMax: (min: Vec, max: Vec, attribs?: Attribs | un
|
|
|
10
10
|
* Returns the intersection AABB of given inputs or `undefined` if they
|
|
11
11
|
* are non-overlapping.
|
|
12
12
|
*
|
|
13
|
-
* @param a
|
|
14
|
-
* @param b
|
|
13
|
+
* @param a -
|
|
14
|
+
* @param b -
|
|
15
15
|
*/
|
|
16
16
|
export declare const intersectionAABB: (a: AABB, b: AABB) => AABB | undefined;
|
|
17
17
|
/**
|
package/aabb.js
CHANGED
|
@@ -15,8 +15,8 @@ export const aabbFromMinMax = (min, max, attribs) => new AABB(min, sub3([], max,
|
|
|
15
15
|
* Returns the intersection AABB of given inputs or `undefined` if they
|
|
16
16
|
* are non-overlapping.
|
|
17
17
|
*
|
|
18
|
-
* @param a
|
|
19
|
-
* @param b
|
|
18
|
+
* @param a -
|
|
19
|
+
* @param b -
|
|
20
20
|
*/
|
|
21
21
|
export const intersectionAABB = (a, b) => {
|
|
22
22
|
const p = max3([], a.pos, b.pos);
|
package/api/bpatch.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Attribs, IHiccupShape } from "@thi.ng/geom-api";
|
|
2
|
+
import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
|
|
3
|
+
import { APC } from "./apc.js";
|
|
4
|
+
/**
|
|
5
|
+
* nD Cubic bezier patch defined by array of 4x4 control points in this
|
|
6
|
+
* order:
|
|
7
|
+
*
|
|
8
|
+
* ```
|
|
9
|
+
* 7 11
|
|
10
|
+
* 3 +---+---+---+ 15 (UV = 1,1)
|
|
11
|
+
* | | | |
|
|
12
|
+
* 2 +---+---+---+ 14
|
|
13
|
+
* | | | |
|
|
14
|
+
* 1 +---+---+---+ 13
|
|
15
|
+
* v | | | |
|
|
16
|
+
* ^ 0 +---+---+---+ 12
|
|
17
|
+
* | 4 8
|
|
18
|
+
* |
|
|
19
|
+
* +----> u
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* The class implements a `unmapPoint()` method to transform a 2D UV coordinate
|
|
23
|
+
* into the worldspace position on the patch surface.
|
|
24
|
+
*
|
|
25
|
+
* The `toHiccup()` impl is only suitable for 2D patches.
|
|
26
|
+
*
|
|
27
|
+
* Ported from toxiclibs.
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
export declare class BPatch extends APC implements IHiccupShape {
|
|
31
|
+
constructor(points: Vec[], attribs?: Attribs);
|
|
32
|
+
get type(): string;
|
|
33
|
+
copy(): BPatch;
|
|
34
|
+
edges(): Vec[][];
|
|
35
|
+
unmapPoint(uv: ReadonlyVec, out?: Vec): Vec;
|
|
36
|
+
toHiccup(): any[];
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=bpatch.d.ts.map
|
package/api/bpatch.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { assert } from "@thi.ng/errors/assert";
|
|
2
|
+
import { mixCubic } from "@thi.ng/vectors/mix-cubic";
|
|
3
|
+
import { __copyShape } from "../internal/copy.js";
|
|
4
|
+
import { APC } from "./apc.js";
|
|
5
|
+
/**
|
|
6
|
+
* nD Cubic bezier patch defined by array of 4x4 control points in this
|
|
7
|
+
* order:
|
|
8
|
+
*
|
|
9
|
+
* ```
|
|
10
|
+
* 7 11
|
|
11
|
+
* 3 +---+---+---+ 15 (UV = 1,1)
|
|
12
|
+
* | | | |
|
|
13
|
+
* 2 +---+---+---+ 14
|
|
14
|
+
* | | | |
|
|
15
|
+
* 1 +---+---+---+ 13
|
|
16
|
+
* v | | | |
|
|
17
|
+
* ^ 0 +---+---+---+ 12
|
|
18
|
+
* | 4 8
|
|
19
|
+
* |
|
|
20
|
+
* +----> u
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* The class implements a `unmapPoint()` method to transform a 2D UV coordinate
|
|
24
|
+
* into the worldspace position on the patch surface.
|
|
25
|
+
*
|
|
26
|
+
* The `toHiccup()` impl is only suitable for 2D patches.
|
|
27
|
+
*
|
|
28
|
+
* Ported from toxiclibs.
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
export class BPatch extends APC {
|
|
32
|
+
constructor(points, attribs) {
|
|
33
|
+
assert(points.length === 16, "require 16 control points");
|
|
34
|
+
super(points, attribs);
|
|
35
|
+
}
|
|
36
|
+
get type() {
|
|
37
|
+
return "bpatch";
|
|
38
|
+
}
|
|
39
|
+
copy() {
|
|
40
|
+
return __copyShape(BPatch, this);
|
|
41
|
+
}
|
|
42
|
+
edges() {
|
|
43
|
+
const p = this.points;
|
|
44
|
+
return [
|
|
45
|
+
[0, 1],
|
|
46
|
+
[1, 2],
|
|
47
|
+
[2, 3],
|
|
48
|
+
[0, 4],
|
|
49
|
+
[1, 5],
|
|
50
|
+
[2, 6],
|
|
51
|
+
[3, 7],
|
|
52
|
+
[4, 5],
|
|
53
|
+
[5, 6],
|
|
54
|
+
[6, 7],
|
|
55
|
+
[4, 8],
|
|
56
|
+
[5, 9],
|
|
57
|
+
[6, 10],
|
|
58
|
+
[7, 11],
|
|
59
|
+
[8, 9],
|
|
60
|
+
[9, 10],
|
|
61
|
+
[10, 11],
|
|
62
|
+
[8, 12],
|
|
63
|
+
[9, 13],
|
|
64
|
+
[10, 14],
|
|
65
|
+
[11, 15],
|
|
66
|
+
[12, 13],
|
|
67
|
+
[13, 14],
|
|
68
|
+
[14, 15],
|
|
69
|
+
].map(([a, b]) => [p[a], p[b]]);
|
|
70
|
+
}
|
|
71
|
+
unmapPoint(uv, out) {
|
|
72
|
+
const cp = this.points;
|
|
73
|
+
const [u, v] = uv;
|
|
74
|
+
return mixCubic(out || null, mixCubic([], cp[0], cp[4], cp[8], cp[12], v), mixCubic([], cp[1], cp[5], cp[9], cp[13], v), mixCubic([], cp[2], cp[6], cp[10], cp[14], v), mixCubic([], cp[3], cp[7], cp[11], cp[15], v), u);
|
|
75
|
+
}
|
|
76
|
+
toHiccup() {
|
|
77
|
+
const attribs = this.attribs;
|
|
78
|
+
const acc = ["g", { fill: "none", ...attribs }];
|
|
79
|
+
if (attribs && attribs.res) {
|
|
80
|
+
const res = attribs.res - 1;
|
|
81
|
+
const delta = 1 / res;
|
|
82
|
+
for (let u = 0; u <= res; u++) {
|
|
83
|
+
const col = [];
|
|
84
|
+
const row = [];
|
|
85
|
+
const uu = u * delta;
|
|
86
|
+
for (let v = 0; v <= res; v++) {
|
|
87
|
+
const p = [uu, v * delta];
|
|
88
|
+
col.push(this.unmapPoint(p));
|
|
89
|
+
row.push(this.unmapPoint([p[1], p[0]]));
|
|
90
|
+
}
|
|
91
|
+
acc.push(["polyline", {}, col]);
|
|
92
|
+
acc.push(["polyline", {}, row]);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
this.edges().forEach((l) => acc.push(["line", {}, ...l]));
|
|
97
|
+
}
|
|
98
|
+
return acc;
|
|
99
|
+
}
|
|
100
|
+
}
|
package/as-svg.d.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import type { Attribs, IShape } from "@thi.ng/geom-api";
|
|
2
2
|
export declare const asSvg: (...args: any[]) => string;
|
|
3
|
+
/**
|
|
4
|
+
* Creates a hiccup SVG doc element for given {@link IShape}s and attribs. If
|
|
5
|
+
* the attribs do not include a `viewBox`, it will be computed automatically.
|
|
6
|
+
* Furthermore (and only for the case a viewbox needs to be computed), a `bleed`
|
|
7
|
+
* attrib can be provided to include a bleed/margin for the viewbox.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Use {@link asSvg} to serialize the resulting doc to an SVG string.
|
|
11
|
+
*
|
|
12
|
+
* @param attribs
|
|
13
|
+
* @param xs
|
|
14
|
+
*/
|
|
3
15
|
export declare const svgDoc: (attribs: Attribs, ...xs: IShape[]) => any[];
|
|
4
16
|
//# sourceMappingURL=as-svg.d.ts.map
|
package/as-svg.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { withoutKeysObj } from "@thi.ng/associative/without-keys";
|
|
1
2
|
import { convertTree } from "@thi.ng/hiccup-svg/convert";
|
|
2
3
|
import { ff } from "@thi.ng/hiccup-svg/format";
|
|
3
4
|
import { svg } from "@thi.ng/hiccup-svg/svg";
|
|
@@ -5,17 +6,33 @@ import { serialize } from "@thi.ng/hiccup/serialize";
|
|
|
5
6
|
import { bounds } from "./bounds.js";
|
|
6
7
|
import { __collBounds } from "./internal/bounds.js";
|
|
7
8
|
export const asSvg = (...args) => args.map((x) => serialize(convertTree(x))).join("");
|
|
9
|
+
/**
|
|
10
|
+
* Creates a hiccup SVG doc element for given {@link IShape}s and attribs. If
|
|
11
|
+
* the attribs do not include a `viewBox`, it will be computed automatically.
|
|
12
|
+
* Furthermore (and only for the case a viewbox needs to be computed), a `bleed`
|
|
13
|
+
* attrib can be provided to include a bleed/margin for the viewbox.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Use {@link asSvg} to serialize the resulting doc to an SVG string.
|
|
17
|
+
*
|
|
18
|
+
* @param attribs
|
|
19
|
+
* @param xs
|
|
20
|
+
*/
|
|
8
21
|
export const svgDoc = (attribs, ...xs) => {
|
|
9
22
|
if (xs.length > 0) {
|
|
10
|
-
if (!attribs
|
|
23
|
+
if (!attribs.viewBox) {
|
|
11
24
|
const cbounds = __collBounds(xs, bounds);
|
|
12
25
|
if (cbounds) {
|
|
13
26
|
const [[x, y], [w, h]] = cbounds;
|
|
27
|
+
const bleed = attribs.bleed || 0;
|
|
28
|
+
const bleed2 = 2 * bleed;
|
|
29
|
+
const width = ff(w + bleed2);
|
|
30
|
+
const height = ff(h + bleed2);
|
|
14
31
|
attribs = {
|
|
15
|
-
width
|
|
16
|
-
height
|
|
17
|
-
viewBox: `${ff(x)} ${ff(y)} ${
|
|
18
|
-
...attribs,
|
|
32
|
+
width,
|
|
33
|
+
height,
|
|
34
|
+
viewBox: `${ff(x - bleed)} ${ff(y - bleed)} ${width} ${height}`,
|
|
35
|
+
...withoutKeysObj(attribs, ["bleed"]),
|
|
19
36
|
};
|
|
20
37
|
}
|
|
21
38
|
}
|
package/bounds.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
2
2
|
import { bounds as arcBounds } from "@thi.ng/geom-arc/bounds";
|
|
3
|
-
import {
|
|
3
|
+
import { bounds2, bounds3 } from "@thi.ng/geom-poly-utils/bounds";
|
|
4
4
|
import { cubicBounds } from "@thi.ng/geom-splines/cubic-bounds";
|
|
5
5
|
import { quadraticBounds } from "@thi.ng/geom-splines/quadratic-bounds";
|
|
6
6
|
import { comp } from "@thi.ng/transducers/comp";
|
|
7
7
|
import { filter } from "@thi.ng/transducers/filter";
|
|
8
8
|
import { iterator1 } from "@thi.ng/transducers/iterator";
|
|
9
9
|
import { map } from "@thi.ng/transducers/map";
|
|
10
|
-
import { MAX2, MAX3, MIN2, MIN3 } from "@thi.ng/vectors/api";
|
|
11
10
|
import { max } from "@thi.ng/vectors/max";
|
|
12
11
|
import { min } from "@thi.ng/vectors/min";
|
|
13
12
|
import { mul2 } from "@thi.ng/vectors/mul";
|
|
14
13
|
import { mulN2 } from "@thi.ng/vectors/muln";
|
|
15
|
-
import { set2
|
|
14
|
+
import { set2 } from "@thi.ng/vectors/set";
|
|
16
15
|
import { sub2 } from "@thi.ng/vectors/sub";
|
|
17
16
|
import { subN2 } from "@thi.ng/vectors/subn";
|
|
18
17
|
import { aabbFromMinMax } from "./aabb.js";
|
|
@@ -22,6 +21,7 @@ import { __dispatch } from "./internal/dispatch.js";
|
|
|
22
21
|
import { rectFromMinMax } from "./rect.js";
|
|
23
22
|
export const bounds = defmulti(__dispatch, {
|
|
24
23
|
aabb: "rect",
|
|
24
|
+
bpatch: "points",
|
|
25
25
|
poly: "points",
|
|
26
26
|
polyline: "points",
|
|
27
27
|
quad: "points",
|
|
@@ -42,8 +42,8 @@ export const bounds = defmulti(__dispatch, {
|
|
|
42
42
|
], bounds);
|
|
43
43
|
return b ? new Rect(...b) : undefined;
|
|
44
44
|
},
|
|
45
|
-
points: ($) => rectFromMinMax(...
|
|
46
|
-
points3: ($) => aabbFromMinMax(...
|
|
45
|
+
points: ($) => rectFromMinMax(...bounds2($.points)),
|
|
46
|
+
points3: ($) => aabbFromMinMax(...bounds3($.points)),
|
|
47
47
|
quadratic: ({ points }) => rectFromMinMax(...quadraticBounds(points[0], points[1], points[2])),
|
|
48
48
|
rect: ($) => $.copy(),
|
|
49
49
|
text: ($) => new Rect(set2([], $.pos), [0, 0]),
|
package/bpatch.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Attribs } from "@thi.ng/geom-api";
|
|
2
|
+
import { Vec } from "@thi.ng/vectors";
|
|
3
|
+
import { BPatch } from "./api/bpatch.js";
|
|
4
|
+
export declare const bpatch: (pts: Vec[], attribs?: Attribs | undefined) => BPatch;
|
|
5
|
+
export declare const bpatchFromQuad: (pts: Vec[], attribs?: Attribs | undefined) => BPatch;
|
|
6
|
+
export declare const bpatchFromHex: (pts: Vec[], attribs?: Attribs | undefined) => BPatch;
|
|
7
|
+
//# sourceMappingURL=bpatch.d.ts.map
|
package/bpatch.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { assert } from "@thi.ng/errors/assert";
|
|
2
|
+
import { mixBilinear } from "@thi.ng/vectors";
|
|
3
|
+
import { BPatch } from "./api/bpatch.js";
|
|
4
|
+
export const bpatch = (pts, attribs) => new BPatch(pts, attribs);
|
|
5
|
+
export const bpatchFromQuad = (pts, attribs) => {
|
|
6
|
+
assert(pts.length === 4, "require 4 points");
|
|
7
|
+
const [a, b, c, d] = pts;
|
|
8
|
+
const cps = [];
|
|
9
|
+
for (let u = 0; u < 4; u++) {
|
|
10
|
+
for (let v = 0; v < 4; v++) {
|
|
11
|
+
cps.push(mixBilinear([], a, b, d, c, u / 3, v / 3));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return new BPatch(cps, attribs);
|
|
15
|
+
};
|
|
16
|
+
export const bpatchFromHex = (pts, attribs) => {
|
|
17
|
+
assert(pts.length === 6, "require 6 points");
|
|
18
|
+
const [a, b, c, d, e, f] = pts;
|
|
19
|
+
return new BPatch([e, e, f, f, d, d, a, a, d, d, a, a, c, c, b, b], attribs);
|
|
20
|
+
};
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./api/aabb.js";
|
|
2
2
|
export * from "./api/apc.js";
|
|
3
3
|
export * from "./api/arc.js";
|
|
4
|
+
export * from "./api/bpatch.js";
|
|
4
5
|
export * from "./api/circle.js";
|
|
5
6
|
export * from "./api/cubic.js";
|
|
6
7
|
export * from "./api/ellipse.js";
|
|
@@ -21,6 +22,7 @@ export * from "./api/text.js";
|
|
|
21
22
|
export * from "./api/triangle.js";
|
|
22
23
|
export * from "./aabb.js";
|
|
23
24
|
export * from "./arc.js";
|
|
25
|
+
export * from "./bpatch.js";
|
|
24
26
|
export * from "./circle.js";
|
|
25
27
|
export * from "./cubic.js";
|
|
26
28
|
export * from "./ellipse.js";
|
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./api/aabb.js";
|
|
2
2
|
export * from "./api/apc.js";
|
|
3
3
|
export * from "./api/arc.js";
|
|
4
|
+
export * from "./api/bpatch.js";
|
|
4
5
|
export * from "./api/circle.js";
|
|
5
6
|
export * from "./api/cubic.js";
|
|
6
7
|
export * from "./api/ellipse.js";
|
|
@@ -21,6 +22,7 @@ export * from "./api/text.js";
|
|
|
21
22
|
export * from "./api/triangle.js";
|
|
22
23
|
export * from "./aabb.js";
|
|
23
24
|
export * from "./arc.js";
|
|
25
|
+
export * from "./bpatch.js";
|
|
24
26
|
export * from "./circle.js";
|
|
25
27
|
export * from "./cubic.js";
|
|
26
28
|
export * from "./ellipse.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/geom",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Functional, polymorphic API for 2D geometry types & SVG generation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -31,43 +31,45 @@
|
|
|
31
31
|
"doc:readme": "yarn doc:stats && tools:readme",
|
|
32
32
|
"doc:stats": "tools:module-stats",
|
|
33
33
|
"pub": "yarn npm publish --access public",
|
|
34
|
-
"test": "testament test"
|
|
34
|
+
"test": "testament test",
|
|
35
|
+
"tool:bpatch": "tools:node-esm tools/bpatch.ts"
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"@thi.ng/api": "^8.3.
|
|
38
|
-
"@thi.ng/arrays": "^2.
|
|
39
|
-
"@thi.ng/
|
|
40
|
-
"@thi.ng/
|
|
41
|
-
"@thi.ng/
|
|
42
|
-
"@thi.ng/
|
|
43
|
-
"@thi.ng/
|
|
44
|
-
"@thi.ng/geom-
|
|
45
|
-
"@thi.ng/geom-
|
|
46
|
-
"@thi.ng/geom-clip-
|
|
47
|
-
"@thi.ng/geom-
|
|
48
|
-
"@thi.ng/geom-
|
|
49
|
-
"@thi.ng/geom-
|
|
50
|
-
"@thi.ng/geom-
|
|
51
|
-
"@thi.ng/geom-
|
|
52
|
-
"@thi.ng/geom-
|
|
53
|
-
"@thi.ng/geom-
|
|
54
|
-
"@thi.ng/geom-
|
|
55
|
-
"@thi.ng/
|
|
56
|
-
"@thi.ng/hiccup
|
|
57
|
-
"@thi.ng/
|
|
58
|
-
"@thi.ng/
|
|
59
|
-
"@thi.ng/
|
|
60
|
-
"@thi.ng/
|
|
61
|
-
"@thi.ng/
|
|
62
|
-
"@thi.ng/
|
|
38
|
+
"@thi.ng/api": "^8.3.4",
|
|
39
|
+
"@thi.ng/arrays": "^2.2.0",
|
|
40
|
+
"@thi.ng/associative": "^6.1.5",
|
|
41
|
+
"@thi.ng/checks": "^3.1.4",
|
|
42
|
+
"@thi.ng/defmulti": "^2.1.4",
|
|
43
|
+
"@thi.ng/equiv": "^2.1.4",
|
|
44
|
+
"@thi.ng/errors": "^2.1.4",
|
|
45
|
+
"@thi.ng/geom-api": "^3.1.8",
|
|
46
|
+
"@thi.ng/geom-arc": "^2.1.8",
|
|
47
|
+
"@thi.ng/geom-clip-line": "^2.1.8",
|
|
48
|
+
"@thi.ng/geom-clip-poly": "^2.1.8",
|
|
49
|
+
"@thi.ng/geom-closest-point": "^2.1.8",
|
|
50
|
+
"@thi.ng/geom-hull": "^2.1.8",
|
|
51
|
+
"@thi.ng/geom-isec": "^2.1.8",
|
|
52
|
+
"@thi.ng/geom-poly-utils": "^2.2.0",
|
|
53
|
+
"@thi.ng/geom-resample": "^2.1.8",
|
|
54
|
+
"@thi.ng/geom-splines": "^2.1.8",
|
|
55
|
+
"@thi.ng/geom-subdiv-curve": "^2.1.8",
|
|
56
|
+
"@thi.ng/geom-tessellate": "^2.1.8",
|
|
57
|
+
"@thi.ng/hiccup": "^4.2.5",
|
|
58
|
+
"@thi.ng/hiccup-svg": "^4.2.8",
|
|
59
|
+
"@thi.ng/math": "^5.3.0",
|
|
60
|
+
"@thi.ng/matrices": "^2.1.8",
|
|
61
|
+
"@thi.ng/random": "^3.2.4",
|
|
62
|
+
"@thi.ng/strings": "^3.3.2",
|
|
63
|
+
"@thi.ng/transducers": "^8.3.0",
|
|
64
|
+
"@thi.ng/vectors": "^7.5.0"
|
|
63
65
|
},
|
|
64
66
|
"devDependencies": {
|
|
65
|
-
"@microsoft/api-extractor": "^7.
|
|
66
|
-
"@thi.ng/testament": "^0.2.
|
|
67
|
+
"@microsoft/api-extractor": "^7.19.4",
|
|
68
|
+
"@thi.ng/testament": "^0.2.4",
|
|
67
69
|
"rimraf": "^3.0.2",
|
|
68
70
|
"tools": "^0.0.1",
|
|
69
|
-
"typedoc": "^0.22.
|
|
70
|
-
"typescript": "^4.
|
|
71
|
+
"typedoc": "^0.22.13",
|
|
72
|
+
"typescript": "^4.6.2"
|
|
71
73
|
},
|
|
72
74
|
"keywords": [
|
|
73
75
|
"2d",
|
|
@@ -119,6 +121,9 @@
|
|
|
119
121
|
"./api/arc": {
|
|
120
122
|
"import": "./api/arc.js"
|
|
121
123
|
},
|
|
124
|
+
"./api/bpatch": {
|
|
125
|
+
"import": "./api/bpatch.js"
|
|
126
|
+
},
|
|
122
127
|
"./api/circle": {
|
|
123
128
|
"import": "./api/circle.js"
|
|
124
129
|
},
|
|
@@ -200,6 +205,9 @@
|
|
|
200
205
|
"./bounds": {
|
|
201
206
|
"import": "./bounds.js"
|
|
202
207
|
},
|
|
208
|
+
"./bpatch": {
|
|
209
|
+
"import": "./bpatch.js"
|
|
210
|
+
},
|
|
203
211
|
"./center": {
|
|
204
212
|
"import": "./center.js"
|
|
205
213
|
},
|
|
@@ -354,5 +362,5 @@
|
|
|
354
362
|
"thi.ng": {
|
|
355
363
|
"year": 2013
|
|
356
364
|
},
|
|
357
|
-
"gitHead": "
|
|
365
|
+
"gitHead": "0fc692a3225c068aacafdc4cb6140cf603c67ad8\n"
|
|
358
366
|
}
|
package/rect.d.ts
CHANGED
|
@@ -12,8 +12,8 @@ export declare const rectFromCentroid: (centroid: Vec, size: Vec, attribs?: Attr
|
|
|
12
12
|
* Returns the intersection rect of given inputs or `undefined` if they
|
|
13
13
|
* are non-overlapping.
|
|
14
14
|
*
|
|
15
|
-
* @param a
|
|
16
|
-
* @param b
|
|
15
|
+
* @param a -
|
|
16
|
+
* @param b -
|
|
17
17
|
*/
|
|
18
18
|
export declare const intersectionRect: (a: Rect, b: Rect) => Rect | undefined;
|
|
19
19
|
/**
|
package/rect.js
CHANGED
|
@@ -19,8 +19,8 @@ export const rectFromCentroid = (centroid, size, attribs) => new Rect(maddN2([],
|
|
|
19
19
|
* Returns the intersection rect of given inputs or `undefined` if they
|
|
20
20
|
* are non-overlapping.
|
|
21
21
|
*
|
|
22
|
-
* @param a
|
|
23
|
-
* @param b
|
|
22
|
+
* @param a -
|
|
23
|
+
* @param b -
|
|
24
24
|
*/
|
|
25
25
|
export const intersectionRect = (a, b) => {
|
|
26
26
|
const p = max2([], a.pos, b.pos);
|
package/vertices.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare const vertices: MultiFn1O<IShape, number | Partial<SamplingOpts>,
|
|
|
7
7
|
* Takes array of vectors or an `IShape`. If the latter, calls {@link vertices}
|
|
8
8
|
* and return result, else returns original array.
|
|
9
9
|
*
|
|
10
|
-
* @param shape
|
|
10
|
+
* @param shape -
|
|
11
11
|
*/
|
|
12
12
|
export declare const ensureVertices: (shape: IShape | Vec[]) => Vec[];
|
|
13
13
|
//# sourceMappingURL=vertices.d.ts.map
|
package/vertices.js
CHANGED
|
@@ -16,6 +16,7 @@ import { Polygon } from "./api/polygon.js";
|
|
|
16
16
|
import { __dispatch } from "./internal/dispatch.js";
|
|
17
17
|
export const vertices = defmulti(__dispatch, {
|
|
18
18
|
line: "polyline",
|
|
19
|
+
bpatch: "points",
|
|
19
20
|
points3: "points",
|
|
20
21
|
quad: "poly",
|
|
21
22
|
tri: "poly",
|
|
@@ -98,7 +99,7 @@ export const vertices = defmulti(__dispatch, {
|
|
|
98
99
|
* Takes array of vectors or an `IShape`. If the latter, calls {@link vertices}
|
|
99
100
|
* and return result, else returns original array.
|
|
100
101
|
*
|
|
101
|
-
* @param shape
|
|
102
|
+
* @param shape -
|
|
102
103
|
*/
|
|
103
104
|
export const ensureVertices = (shape) => isArray(shape) ? shape : vertices(shape);
|
|
104
105
|
const circleOpts = (opts, r) => isNumber(opts)
|
package/warp-points.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { IShape } from "@thi.ng/geom-api";
|
|
2
|
-
import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
|
|
2
|
+
import type { ReadonlyVec, Vec } from "@thi.ng/vectors/api";
|
|
3
|
+
import type { BPatch } from "./api/bpatch.js";
|
|
4
|
+
import type { Rect } from "./api/rect.js";
|
|
3
5
|
export declare const warpPoints: (pts: ReadonlyVec[], dest: IShape, src: IShape) => Vec[];
|
|
6
|
+
export declare const warpPointsBPatch: (pts: ReadonlyVec[], dest: BPatch, src?: Rect | undefined, out?: Vec[]) => Vec[];
|
|
4
7
|
//# sourceMappingURL=warp-points.d.ts.map
|
package/warp-points.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { bounds2 } from "@thi.ng/geom-poly-utils/bounds";
|
|
1
2
|
import { mapPoint } from "./map-point.js";
|
|
3
|
+
import { rectFromMinMax } from "./rect.js";
|
|
2
4
|
import { unmapPoint } from "./unmap-point.js";
|
|
3
5
|
export const warpPoints = (pts, dest, src) => {
|
|
4
6
|
const res = [];
|
|
@@ -7,3 +9,10 @@ export const warpPoints = (pts, dest, src) => {
|
|
|
7
9
|
}
|
|
8
10
|
return res;
|
|
9
11
|
};
|
|
12
|
+
export const warpPointsBPatch = (pts, dest, src, out = []) => {
|
|
13
|
+
src = src || rectFromMinMax(...bounds2(pts));
|
|
14
|
+
for (let i = pts.length; i-- > 0;) {
|
|
15
|
+
out[i] = dest.unmapPoint(mapPoint(src, pts[i]));
|
|
16
|
+
}
|
|
17
|
+
return out;
|
|
18
|
+
};
|