@thi.ng/geom 6.0.6 → 6.0.8
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 +1 -1
- package/README.md +1 -1
- package/aabb.js +31 -32
- package/api/aabb.js +34 -29
- package/api/apc.js +15 -13
- package/api/arc.js +82 -66
- package/api/bpatch.js +79 -96
- package/api/circle.js +21 -21
- package/api/cubic.js +28 -25
- package/api/ellipse.js +26 -21
- package/api/group.js +45 -47
- package/api/line.js +26 -27
- package/api/path.js +62 -58
- package/api/plane.js +21 -21
- package/api/points.js +30 -26
- package/api/polygon.js +19 -16
- package/api/polyline.js +25 -22
- package/api/quad.js +20 -17
- package/api/quad3.js +20 -17
- package/api/quadratic.js +28 -25
- package/api/ray.js +30 -26
- package/api/rect.js +34 -29
- package/api/sphere.js +21 -21
- package/api/text.js +21 -28
- package/api/triangle.js +20 -17
- package/apply-transforms.js +28 -48
- package/arc-length.js +17 -30
- package/arc.js +17 -6
- package/area.js +19 -45
- package/as-cubic.js +38 -57
- package/as-path.js +4 -8
- package/as-polygon.js +12 -29
- package/as-polyline.js +18 -38
- package/as-svg.js +32 -63
- package/bounds.js +46 -48
- package/bpatch.js +22 -14
- package/center.js +22 -17
- package/centroid.js +14 -34
- package/circle.js +11 -6
- package/classify-point.js +20 -27
- package/clip-convex.js +40 -39
- package/closest-point.js +28 -34
- package/convex-hull.js +12 -27
- package/cubic.js +13 -5
- package/edges.js +31 -60
- package/ellipse.js +5 -2
- package/fit-into-bounds.js +78 -61
- package/flip.js +24 -41
- package/group.js +4 -1
- package/internal/args.js +18 -51
- package/internal/bounds.js +23 -38
- package/internal/collate.js +33 -17
- package/internal/copy.js +12 -23
- package/internal/dispatch.js +6 -4
- package/internal/edges.js +4 -1
- package/internal/pclike.js +8 -4
- package/internal/points-as-shape.js +4 -3
- package/internal/rotate.js +6 -2
- package/internal/scale.js +8 -2
- package/internal/split.js +9 -6
- package/internal/transform.js +24 -12
- package/internal/translate.js +6 -2
- package/internal/vertices.js +15 -31
- package/intersects.js +15 -39
- package/line.js +11 -9
- package/map-point.js +10 -18
- package/offset.js +31 -29
- package/package.json +33 -31
- package/path-builder.js +152 -143
- package/path-from-svg.js +129 -131
- package/path.js +28 -25
- package/plane.js +10 -5
- package/point-at.js +12 -30
- package/point-inside.js +20 -25
- package/points.js +6 -2
- package/polygon.js +15 -47
- package/polyline.js +18 -22
- package/quad.js +23 -15
- package/quadratic.js +7 -3
- package/ray.js +4 -1
- package/rect.js +47 -46
- package/resample.js +12 -27
- package/rotate.js +30 -42
- package/scale.js +66 -64
- package/scatter.js +18 -30
- package/simplify.js +38 -55
- package/sphere.js +7 -3
- package/split-arclength.js +53 -108
- package/split-at.js +46 -26
- package/split-near.js +28 -22
- package/subdiv-curve.js +33 -72
- package/tangent-at.js +12 -24
- package/tessellate.js +22 -47
- package/text.js +4 -1
- package/transform-vertices.js +31 -55
- package/transform.js +31 -54
- package/translate.js +39 -46
- package/triangle.js +7 -3
- package/union.js +12 -15
- package/unmap-point.js +21 -25
- package/vertices.js +91 -113
- package/volume.js +10 -14
- package/warp-points.js +15 -25
- package/with-attribs.js +4 -11
package/as-cubic.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
closedCubicFromBreakPoints,
|
|
4
|
+
openCubicFromBreakPoints
|
|
5
|
+
} from "@thi.ng/geom-splines/cubic-from-breakpoints";
|
|
6
|
+
import {
|
|
7
|
+
closedCubicFromControlPoints,
|
|
8
|
+
openCubicFromControlPoints
|
|
9
|
+
} from "@thi.ng/geom-splines/cubic-from-controlpoints";
|
|
4
10
|
import { TAU } from "@thi.ng/math/api";
|
|
5
11
|
import { mapcat } from "@thi.ng/transducers/mapcat";
|
|
6
12
|
import { Cubic } from "./api/cubic.js";
|
|
@@ -9,73 +15,48 @@ import { asPolygon } from "./as-polygon.js";
|
|
|
9
15
|
import { cubicFromArc, cubicFromLine, cubicFromQuadratic } from "./cubic.js";
|
|
10
16
|
import { __copyAttribs } from "./internal/copy.js";
|
|
11
17
|
import { __dispatch } from "./internal/dispatch.js";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
* @remarks
|
|
17
|
-
* Currently implemented for:
|
|
18
|
-
*
|
|
19
|
-
* - {@link Arc}
|
|
20
|
-
* - {@link Circle}
|
|
21
|
-
* - {@link Cubic}
|
|
22
|
-
* - {@link Ellipse}
|
|
23
|
-
* - {@link Group}
|
|
24
|
-
* - {@link Line}
|
|
25
|
-
* - {@link Path}
|
|
26
|
-
* - {@link Polygon}
|
|
27
|
-
* - {@link Polyline}
|
|
28
|
-
* - {@link Quad}
|
|
29
|
-
* - {@link Quadratic}
|
|
30
|
-
* - {@link Rect}
|
|
31
|
-
* - {@link Triangle}
|
|
32
|
-
*
|
|
33
|
-
* Shape types supporting custom conversion options (see
|
|
34
|
-
* [@thi.ng/geom-splines](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-splines#cubic-curve-conversion-from-polygons--polylines)
|
|
35
|
-
* for more details):
|
|
36
|
-
*
|
|
37
|
-
* - {@link Group} (only used for eligible children)
|
|
38
|
-
* - {@link Polygon}
|
|
39
|
-
* - {@link Polyline}
|
|
40
|
-
* - {@link Quad}
|
|
41
|
-
* - {@link Quadratic}
|
|
42
|
-
* - {@link Rect}
|
|
43
|
-
* - {@link Triangle}
|
|
44
|
-
*
|
|
45
|
-
* @param shape
|
|
46
|
-
* @param opts
|
|
47
|
-
*/
|
|
48
|
-
export const asCubic = defmulti(__dispatch, {
|
|
18
|
+
const asCubic = defmulti(
|
|
19
|
+
__dispatch,
|
|
20
|
+
{
|
|
49
21
|
ellipse: "circle",
|
|
50
22
|
quad: "poly",
|
|
51
|
-
tri: "poly"
|
|
52
|
-
},
|
|
23
|
+
tri: "poly"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
53
26
|
arc: cubicFromArc,
|
|
54
27
|
circle: ($) => asCubic(arc($.pos, $.r, 0, 0, TAU, true, true)),
|
|
55
28
|
cubic: ($) => [$],
|
|
56
29
|
group: ($, opts) => [
|
|
57
|
-
|
|
30
|
+
...mapcat((x) => asCubic(x, opts), $.children)
|
|
58
31
|
],
|
|
59
32
|
line: ({ attribs, points }) => [
|
|
60
|
-
|
|
33
|
+
cubicFromLine(points[0], points[1], { ...attribs })
|
|
61
34
|
],
|
|
62
35
|
path: ($) => [
|
|
63
|
-
|
|
36
|
+
...mapcat((s) => s.geo ? asCubic(s.geo) : null, $.segments)
|
|
64
37
|
],
|
|
65
|
-
poly: ($, opts = {}) => __polyCubic(
|
|
66
|
-
|
|
38
|
+
poly: ($, opts = {}) => __polyCubic(
|
|
39
|
+
$,
|
|
40
|
+
opts,
|
|
41
|
+
closedCubicFromBreakPoints,
|
|
42
|
+
closedCubicFromControlPoints
|
|
43
|
+
),
|
|
44
|
+
polyline: ($, opts = {}) => __polyCubic(
|
|
45
|
+
$,
|
|
46
|
+
opts,
|
|
47
|
+
openCubicFromBreakPoints,
|
|
48
|
+
openCubicFromControlPoints
|
|
49
|
+
),
|
|
67
50
|
quadratic: ({ attribs, points }) => [
|
|
68
|
-
|
|
51
|
+
cubicFromQuadratic(points[0], points[1], points[2], { ...attribs })
|
|
69
52
|
],
|
|
70
|
-
rect: ($, opts) => asCubic(asPolygon($), opts)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
* @internal
|
|
74
|
-
*/
|
|
75
|
-
// prettier-ignore
|
|
53
|
+
rect: ($, opts) => asCubic(asPolygon($), opts)
|
|
54
|
+
}
|
|
55
|
+
);
|
|
76
56
|
const __polyCubic = ($, opts, breakPoints, controlPoints) => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
57
|
+
opts = { breakPoints: false, scale: 1 / 3, uniform: false, ...opts };
|
|
58
|
+
return (opts.breakPoints ? breakPoints($.points, opts.scale, opts.uniform) : controlPoints($.points, opts.scale, opts.uniform)).map((pts) => new Cubic(pts, __copyAttribs($)));
|
|
59
|
+
};
|
|
60
|
+
export {
|
|
61
|
+
asCubic
|
|
81
62
|
};
|
package/as-path.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { asCubic } from "./as-cubic.js";
|
|
2
2
|
import { __copyAttribs } from "./internal/copy.js";
|
|
3
3
|
import { pathFromCubics } from "./path.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* @param src
|
|
9
|
-
* @param attribs
|
|
10
|
-
*/
|
|
11
|
-
export const asPath = (src, attribs) => pathFromCubics(asCubic(src), attribs || __copyAttribs(src));
|
|
4
|
+
const asPath = (src, attribs) => pathFromCubics(asCubic(src), attribs || __copyAttribs(src));
|
|
5
|
+
export {
|
|
6
|
+
asPath
|
|
7
|
+
};
|
package/as-polygon.js
CHANGED
|
@@ -3,31 +3,9 @@ import { Polygon } from "./api/polygon.js";
|
|
|
3
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* or number of target vertices.
|
|
10
|
-
*
|
|
11
|
-
* @remarks
|
|
12
|
-
* If the shape has a `__samples` attribute, it will be removed in the result to
|
|
13
|
-
* avoid recursive application.
|
|
14
|
-
*
|
|
15
|
-
* Currently implemented for:
|
|
16
|
-
*
|
|
17
|
-
* - {@link Circle}
|
|
18
|
-
* - {@link Ellipse}
|
|
19
|
-
* - {@link Line}
|
|
20
|
-
* - {@link Path}
|
|
21
|
-
* - {@link Poly}
|
|
22
|
-
* - {@link Polyline} (will be closed)
|
|
23
|
-
* - {@link Quad}
|
|
24
|
-
* - {@link Rect}
|
|
25
|
-
* - {@link Triangle}
|
|
26
|
-
*
|
|
27
|
-
* @param shape
|
|
28
|
-
* @param opts
|
|
29
|
-
*/
|
|
30
|
-
export const asPolygon = defmulti(__dispatch, {
|
|
6
|
+
const asPolygon = defmulti(
|
|
7
|
+
__dispatch,
|
|
8
|
+
{
|
|
31
9
|
circle: "points",
|
|
32
10
|
ellipse: "points",
|
|
33
11
|
line: "points",
|
|
@@ -36,7 +14,12 @@ export const asPolygon = defmulti(__dispatch, {
|
|
|
36
14
|
polyline: "points",
|
|
37
15
|
quad: "points",
|
|
38
16
|
rect: "points",
|
|
39
|
-
tri: "points"
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
|
|
17
|
+
tri: "points"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
points: ($, opts) => new Polygon(vertices($, opts), __attribs($))
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
export {
|
|
24
|
+
asPolygon
|
|
25
|
+
};
|
package/as-polyline.js
CHANGED
|
@@ -4,34 +4,9 @@ import { Polyline } from "./api/polyline.js";
|
|
|
4
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* or number of target vertices.
|
|
11
|
-
*
|
|
12
|
-
* @remarks
|
|
13
|
-
* If the shape has a `__samples` attribute, it will be removed in the result to
|
|
14
|
-
* avoid recursive application.
|
|
15
|
-
*
|
|
16
|
-
* Currently implemented for:
|
|
17
|
-
*
|
|
18
|
-
* - {@link Arc}
|
|
19
|
-
* - {@link Circle}
|
|
20
|
-
* - {@link Cubic}
|
|
21
|
-
* - {@link Ellipse}
|
|
22
|
-
* - {@link Line}
|
|
23
|
-
* - {@link Path}
|
|
24
|
-
* - {@link Poly}
|
|
25
|
-
* - {@link Polyline}
|
|
26
|
-
* - {@link Quad}
|
|
27
|
-
* - {@link Quadratic}
|
|
28
|
-
* - {@link Rect}
|
|
29
|
-
* - {@link Triangle}
|
|
30
|
-
*
|
|
31
|
-
* @param shape
|
|
32
|
-
* @param opts
|
|
33
|
-
*/
|
|
34
|
-
export const asPolyline = defmulti(__dispatch, {
|
|
7
|
+
const asPolyline = defmulti(
|
|
8
|
+
__dispatch,
|
|
9
|
+
{
|
|
35
10
|
arc: "points",
|
|
36
11
|
circle: "poly",
|
|
37
12
|
cubic: "points",
|
|
@@ -41,17 +16,22 @@ export const asPolyline = defmulti(__dispatch, {
|
|
|
41
16
|
quad: "poly",
|
|
42
17
|
quadratic: "points",
|
|
43
18
|
rect: "poly",
|
|
44
|
-
tri: "poly"
|
|
45
|
-
},
|
|
19
|
+
tri: "poly"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
46
22
|
points: ($, opts) => new Polyline(vertices($, opts), __attribs($)),
|
|
47
23
|
path: ($, opts) => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
24
|
+
const pts = vertices($, opts);
|
|
25
|
+
$.closed && pts.push(set([], pts[0]));
|
|
26
|
+
return new Polyline(pts, __attribs($));
|
|
51
27
|
},
|
|
52
28
|
poly: ($, opts) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
}
|
|
29
|
+
const pts = vertices($, opts);
|
|
30
|
+
pts.push(set([], pts[0]));
|
|
31
|
+
return new Polyline(pts, __attribs($));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
export {
|
|
36
|
+
asPolyline
|
|
37
|
+
};
|
package/as-svg.js
CHANGED
|
@@ -5,69 +5,38 @@ import { svg } from "@thi.ng/hiccup-svg/svg";
|
|
|
5
5
|
import { serialize } from "@thi.ng/hiccup/serialize";
|
|
6
6
|
import { bounds } from "./bounds.js";
|
|
7
7
|
import { __collBounds } from "./internal/bounds.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export let DEFAULT_ATTRIBS = { fill: "none", stroke: "#000" };
|
|
12
|
-
/**
|
|
13
|
-
* Sets the SVG root element attribs used by default by {@link svgDoc}.
|
|
14
|
-
*
|
|
15
|
-
* @param attribs
|
|
16
|
-
*/
|
|
17
|
-
export const setSvgDefaultAttribs = (attribs) => {
|
|
18
|
-
DEFAULT_ATTRIBS = attribs;
|
|
8
|
+
let DEFAULT_ATTRIBS = { fill: "none", stroke: "#000" };
|
|
9
|
+
const setSvgDefaultAttribs = (attribs) => {
|
|
10
|
+
DEFAULT_ATTRIBS = attribs;
|
|
19
11
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
* per-shape basis. If omitted, the currently configured precision will be used
|
|
42
|
-
* (default: 3).
|
|
43
|
-
*
|
|
44
|
-
* Also see
|
|
45
|
-
* [`convertTree()`](https://docs.thi.ng/umbrella/hiccup-svg/functions/convertTree.html)
|
|
46
|
-
* and
|
|
47
|
-
* [`setPrecision()`](https://docs.thi.ng/umbrella/hiccup-svg/functions/setPrecision.html).
|
|
48
|
-
*
|
|
49
|
-
* @param attribs
|
|
50
|
-
* @param xs
|
|
51
|
-
*/
|
|
52
|
-
export const svgDoc = (attribs, ...xs) => {
|
|
53
|
-
attribs = { ...DEFAULT_ATTRIBS, ...attribs };
|
|
54
|
-
if (xs.length > 0) {
|
|
55
|
-
if (!attribs.viewBox) {
|
|
56
|
-
const cbounds = __collBounds(xs, bounds);
|
|
57
|
-
if (cbounds) {
|
|
58
|
-
const [[x, y], [w, h]] = cbounds;
|
|
59
|
-
const bleed = attribs.__bleed || 0;
|
|
60
|
-
const bleed2 = 2 * bleed;
|
|
61
|
-
const width = ff(w + bleed2);
|
|
62
|
-
const height = ff(h + bleed2);
|
|
63
|
-
attribs = {
|
|
64
|
-
width,
|
|
65
|
-
height,
|
|
66
|
-
viewBox: `${ff(x - bleed)} ${ff(y - bleed)} ${width} ${height}`,
|
|
67
|
-
...withoutKeysObj(attribs, ["__bleed"]),
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
}
|
|
12
|
+
const asSvg = (...args) => args.map((x) => serialize(convertTree(x))).join("");
|
|
13
|
+
const svgDoc = (attribs, ...xs) => {
|
|
14
|
+
attribs = { ...DEFAULT_ATTRIBS, ...attribs };
|
|
15
|
+
if (xs.length > 0) {
|
|
16
|
+
if (!attribs.viewBox) {
|
|
17
|
+
const cbounds = __collBounds(xs, bounds);
|
|
18
|
+
if (cbounds) {
|
|
19
|
+
const [[x, y], [w, h]] = cbounds;
|
|
20
|
+
const bleed = attribs.__bleed || 0;
|
|
21
|
+
const bleed2 = 2 * bleed;
|
|
22
|
+
const width = ff(w + bleed2);
|
|
23
|
+
const height = ff(h + bleed2);
|
|
24
|
+
attribs = {
|
|
25
|
+
width,
|
|
26
|
+
height,
|
|
27
|
+
viewBox: `${ff(x - bleed)} ${ff(
|
|
28
|
+
y - bleed
|
|
29
|
+
)} ${width} ${height}`,
|
|
30
|
+
...withoutKeysObj(attribs, ["__bleed"])
|
|
31
|
+
};
|
|
32
|
+
}
|
|
71
33
|
}
|
|
72
|
-
|
|
34
|
+
}
|
|
35
|
+
return svg(attribs, ...xs);
|
|
36
|
+
};
|
|
37
|
+
export {
|
|
38
|
+
DEFAULT_ATTRIBS,
|
|
39
|
+
asSvg,
|
|
40
|
+
setSvgDefaultAttribs,
|
|
41
|
+
svgDoc
|
|
73
42
|
};
|
package/bounds.js
CHANGED
|
@@ -19,65 +19,63 @@ import { Rect } from "./api/rect.js";
|
|
|
19
19
|
import { __collBounds } from "./internal/bounds.js";
|
|
20
20
|
import { __dispatch } from "./internal/dispatch.js";
|
|
21
21
|
import { rectFromMinMaxWithMargin } from "./rect.js";
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* all children will be returned.
|
|
26
|
-
*
|
|
27
|
-
* @remarks
|
|
28
|
-
* Currently implemented for:
|
|
29
|
-
*
|
|
30
|
-
* - {@link AABB}
|
|
31
|
-
* - {@link Arc}
|
|
32
|
-
* - {@link BPatch}
|
|
33
|
-
* - {@link Circle}
|
|
34
|
-
* - {@link Cubic}
|
|
35
|
-
* - {@link Ellipse}
|
|
36
|
-
* - {@link Group}
|
|
37
|
-
* - {@link Line}
|
|
38
|
-
* - {@link Path}
|
|
39
|
-
* - {@link Polygon}
|
|
40
|
-
* - {@link Polyline}
|
|
41
|
-
* - {@link Points}
|
|
42
|
-
* - {@link Points3}
|
|
43
|
-
* - {@link Quad}
|
|
44
|
-
* - {@link Quadratic}
|
|
45
|
-
* - {@link Text} - (no way to compute size, only position & any margin)
|
|
46
|
-
*
|
|
47
|
-
* @param shape
|
|
48
|
-
* @param margin
|
|
49
|
-
*/
|
|
50
|
-
export const bounds = defmulti(__dispatch, {
|
|
22
|
+
const bounds = defmulti(
|
|
23
|
+
__dispatch,
|
|
24
|
+
{
|
|
51
25
|
aabb: "rect",
|
|
52
26
|
bpatch: "points",
|
|
53
27
|
poly: "points",
|
|
54
28
|
polyline: "points",
|
|
55
29
|
quad: "points",
|
|
56
|
-
tri: "points"
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
30
|
+
tri: "points"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
arc: ($, margin = 0) => rectFromMinMaxWithMargin(
|
|
34
|
+
...arcBounds($.pos, $.r, $.axis, $.start, $.end),
|
|
35
|
+
margin
|
|
36
|
+
),
|
|
37
|
+
circle: ($, margin = 0) => new Rect(
|
|
38
|
+
subN2([], $.pos, $.r + margin),
|
|
39
|
+
mulN2(null, [2, 2], $.r + margin)
|
|
40
|
+
),
|
|
41
|
+
cubic: ({ points }, margin = 0) => rectFromMinMaxWithMargin(
|
|
42
|
+
...cubicBounds(points[0], points[1], points[2], points[3]),
|
|
43
|
+
margin
|
|
44
|
+
),
|
|
61
45
|
ellipse: ($, margin = 0) => {
|
|
62
|
-
|
|
63
|
-
|
|
46
|
+
const r = addN2([], $.r, margin);
|
|
47
|
+
return new Rect(sub2([], $.pos, r), mul2(null, [2, 2], r));
|
|
64
48
|
},
|
|
65
49
|
group: ($, margin = 0) => {
|
|
66
|
-
|
|
67
|
-
|
|
50
|
+
const res = __collBounds($.children, bounds);
|
|
51
|
+
return res ? new Rect(...res).offset(margin) : void 0;
|
|
68
52
|
},
|
|
69
53
|
line: ({ points: [a, b] }, margin = 0) => rectFromMinMaxWithMargin(min([], a, b), max([], a, b), margin),
|
|
70
54
|
path: (path, margin = 0) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
55
|
+
const b = __collBounds(
|
|
56
|
+
[
|
|
57
|
+
...iterator1(
|
|
58
|
+
comp(
|
|
59
|
+
map((s) => s.geo),
|
|
60
|
+
filter((s) => !!s)
|
|
61
|
+
),
|
|
62
|
+
path.segments
|
|
63
|
+
)
|
|
64
|
+
],
|
|
65
|
+
bounds
|
|
66
|
+
);
|
|
67
|
+
return b ? new Rect(...b).offset(margin) : void 0;
|
|
75
68
|
},
|
|
76
69
|
points: ($, margin = 0) => rectFromMinMaxWithMargin(...bounds2($.points), margin),
|
|
77
70
|
points3: ($, margin = 0) => aabbFromMinMaxWithMargin(...bounds3($.points), margin),
|
|
78
|
-
quadratic: ({ points }, margin = 0) => rectFromMinMaxWithMargin(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
71
|
+
quadratic: ({ points }, margin = 0) => rectFromMinMaxWithMargin(
|
|
72
|
+
...quadraticBounds(points[0], points[1], points[2]),
|
|
73
|
+
margin
|
|
74
|
+
),
|
|
75
|
+
rect: ($, margin = 0) => margin === 0 ? $.copy() : $.copy().offset(margin),
|
|
76
|
+
text: ($, margin = 0) => new Rect(subN2([], $.pos, margin), margin * 2)
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
export {
|
|
80
|
+
bounds
|
|
81
|
+
};
|
package/bpatch.js
CHANGED
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
import { assert } from "@thi.ng/errors/assert";
|
|
2
2
|
import { mixBilinear } from "@thi.ng/vectors/mix-bilinear";
|
|
3
3
|
import { BPatch } from "./api/bpatch.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
4
|
+
const bpatch = (pts, attribs) => new BPatch(pts, attribs);
|
|
5
|
+
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));
|
|
13
12
|
}
|
|
14
|
-
|
|
13
|
+
}
|
|
14
|
+
return new BPatch(cps, attribs);
|
|
15
15
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
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(
|
|
20
|
+
[e, e, f, f, d, d, a, a, d, d, a, a, c, c, b, b],
|
|
21
|
+
attribs
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
bpatch,
|
|
26
|
+
bpatchFromHex,
|
|
27
|
+
bpatchFromQuad
|
|
20
28
|
};
|
package/center.js
CHANGED
|
@@ -10,24 +10,29 @@ import { centroid } from "./centroid.js";
|
|
|
10
10
|
import { __copyAttribs } from "./internal/copy.js";
|
|
11
11
|
import { __dispatch } from "./internal/dispatch.js";
|
|
12
12
|
import { translate } from "./translate.js";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* @remarks
|
|
18
|
-
* Implemented for all shape types supported by {@link centroid} and
|
|
19
|
-
* {@link translate}.
|
|
20
|
-
*
|
|
21
|
-
* @param shape
|
|
22
|
-
* @param p
|
|
23
|
-
*/
|
|
24
|
-
export const center = defmulti(__dispatch, {}, {
|
|
13
|
+
const center = defmulti(
|
|
14
|
+
__dispatch,
|
|
15
|
+
{},
|
|
16
|
+
{
|
|
25
17
|
[DEFAULT]: ($, origin = ZERO3) => {
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
const c = centroid($);
|
|
19
|
+
return c ? translate($, submN(null, c, origin, -1)) : void 0;
|
|
28
20
|
},
|
|
29
|
-
arc: ($, origin = ZERO2) => new Arc(
|
|
21
|
+
arc: ($, origin = ZERO2) => new Arc(
|
|
22
|
+
set2([], origin),
|
|
23
|
+
set2([], $.r),
|
|
24
|
+
$.axis,
|
|
25
|
+
$.start,
|
|
26
|
+
$.end,
|
|
27
|
+
$.xl,
|
|
28
|
+
$.cw,
|
|
29
|
+
__copyAttribs($)
|
|
30
|
+
),
|
|
30
31
|
circle: ($, origin = ZERO2) => new Circle(set2([], origin), $.r, __copyAttribs($)),
|
|
31
32
|
ellipse: ($, origin = ZERO2) => new Ellipse(set2([], origin), set2([], $.r), __copyAttribs($)),
|
|
32
|
-
sphere: ($, origin = ZERO3) => new Sphere(set3([], origin), $.r, __copyAttribs($))
|
|
33
|
-
}
|
|
33
|
+
sphere: ($, origin = ZERO3) => new Sphere(set3([], origin), $.r, __copyAttribs($))
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
export {
|
|
37
|
+
center
|
|
38
|
+
};
|
package/centroid.js
CHANGED
|
@@ -9,34 +9,9 @@ import { mulN } from "@thi.ng/vectors/muln";
|
|
|
9
9
|
import { set } from "@thi.ng/vectors/set";
|
|
10
10
|
import { bounds } from "./bounds.js";
|
|
11
11
|
import { __dispatch } from "./internal/dispatch.js";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
* @remarks
|
|
17
|
-
* Currently implemented for:
|
|
18
|
-
*
|
|
19
|
-
* - {@link AABB}
|
|
20
|
-
* - {@link Arc}
|
|
21
|
-
* - {@link BPatch}
|
|
22
|
-
* - {@link Circle}
|
|
23
|
-
* - {@link Cubic}
|
|
24
|
-
* - {@link Ellipse}
|
|
25
|
-
* - {@link Group}
|
|
26
|
-
* - {@link Line}
|
|
27
|
-
* - {@link Path}
|
|
28
|
-
* - {@link Polygon}
|
|
29
|
-
* - {@link Polyline}
|
|
30
|
-
* - {@link Points}
|
|
31
|
-
* - {@link Points3}
|
|
32
|
-
* - {@link Quad}
|
|
33
|
-
* - {@link Quadratic}
|
|
34
|
-
* - {@link Text} - (no way to compute size, only position & any margin)
|
|
35
|
-
*
|
|
36
|
-
* @param shape
|
|
37
|
-
* @param out
|
|
38
|
-
*/
|
|
39
|
-
export const centroid = defmulti(__dispatch, {
|
|
12
|
+
const centroid = defmulti(
|
|
13
|
+
__dispatch,
|
|
14
|
+
{
|
|
40
15
|
arc: "circle",
|
|
41
16
|
aabb: "rect",
|
|
42
17
|
bpatch: "points",
|
|
@@ -47,17 +22,22 @@ export const centroid = defmulti(__dispatch, {
|
|
|
47
22
|
quad: "poly",
|
|
48
23
|
sphere: "circle",
|
|
49
24
|
text: "circle",
|
|
50
|
-
tri3: "tri"
|
|
51
|
-
},
|
|
25
|
+
tri3: "tri"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
52
28
|
circle: ($, out) => set(out || [], $.pos),
|
|
53
29
|
group: ($, out) => {
|
|
54
|
-
|
|
55
|
-
|
|
30
|
+
const b = bounds($);
|
|
31
|
+
return b ? centroid(b, out) : void 0;
|
|
56
32
|
},
|
|
57
33
|
line: ({ points }, out) => mixN(out || [], points[0], points[1], 0.5),
|
|
58
34
|
points: ($, out) => _centroid($.points, out),
|
|
59
35
|
plane: ($, out) => mulN(out || [], $.normal, $.w),
|
|
60
36
|
poly: ($, out) => centerOfWeight2($.points, out),
|
|
61
37
|
rect: ($, out) => maddN(out || [], $.size, 0.5, $.pos),
|
|
62
|
-
tri: ({ points }, out) => addmN(null, add(out || [], points[0], points[1]), points[2], 1 / 3)
|
|
63
|
-
}
|
|
38
|
+
tri: ({ points }, out) => addmN(null, add(out || [], points[0], points[1]), points[2], 1 / 3)
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
export {
|
|
42
|
+
centroid
|
|
43
|
+
};
|
package/circle.js
CHANGED
|
@@ -3,11 +3,16 @@ import { dist } from "@thi.ng/vectors/dist";
|
|
|
3
3
|
import { mixN2 } from "@thi.ng/vectors/mixn";
|
|
4
4
|
import { Circle } from "./api/circle.js";
|
|
5
5
|
import { __argsVN } from "./internal/args.js";
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
function circle(...args) {
|
|
7
|
+
return new Circle(...__argsVN(args));
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
const circleFrom2Points = (a, b, attribs) => new Circle(mixN2([], a, b, 0.5), dist(a, b) / 2, attribs);
|
|
10
|
+
const circleFrom3Points = (a, b, c, attribs) => {
|
|
11
|
+
const o = circumCenter2(a, b, c);
|
|
12
|
+
return o ? new Circle(o, dist(a, o), attribs) : void 0;
|
|
13
|
+
};
|
|
14
|
+
export {
|
|
15
|
+
circle,
|
|
16
|
+
circleFrom2Points,
|
|
17
|
+
circleFrom3Points
|
|
13
18
|
};
|