@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/classify-point.js
CHANGED
|
@@ -1,34 +1,27 @@
|
|
|
1
1
|
import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
classifyPointInCircle,
|
|
4
|
+
classifyPointInTriangle2
|
|
5
|
+
} from "@thi.ng/geom-isec/point";
|
|
3
6
|
import { sign } from "@thi.ng/math/abs";
|
|
4
7
|
import { EPS } from "@thi.ng/math/api";
|
|
5
8
|
import { dot } from "@thi.ng/vectors/dot";
|
|
6
9
|
import { __dispatch } from "./internal/dispatch.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
* @remarks
|
|
13
|
-
* Currently only implemented for:
|
|
14
|
-
*
|
|
15
|
-
* - {@link Circle}
|
|
16
|
-
* - {@link Plane}
|
|
17
|
-
* - {@link Sphere}
|
|
18
|
-
* - {@link Triangle}
|
|
19
|
-
*
|
|
20
|
-
* The [thi.ng/geom-sdf](https://thi.ng/thi.ng/geom-sdf) package provides a much
|
|
21
|
-
* more comprehensive feature set (incl. support for more shapes) to perform
|
|
22
|
-
* similar checks as this function.
|
|
23
|
-
*
|
|
24
|
-
* Also see {@link pointInside}.
|
|
25
|
-
*
|
|
26
|
-
* @param shape
|
|
27
|
-
* @param p
|
|
28
|
-
* @param eps
|
|
29
|
-
*/
|
|
30
|
-
export const classifyPoint = defmulti(__dispatch, { sphere: "circle" }, {
|
|
10
|
+
const classifyPoint = defmulti(
|
|
11
|
+
__dispatch,
|
|
12
|
+
{ sphere: "circle" },
|
|
13
|
+
{
|
|
31
14
|
circle: ($, p, eps = EPS) => classifyPointInCircle(p, $.pos, $.r, eps),
|
|
32
15
|
plane: ($, p, eps) => sign(dot($.normal, p) - $.w, eps),
|
|
33
|
-
tri: ({ points }, p, eps = EPS) => classifyPointInTriangle2(
|
|
34
|
-
|
|
16
|
+
tri: ({ points }, p, eps = EPS) => classifyPointInTriangle2(
|
|
17
|
+
p,
|
|
18
|
+
points[0],
|
|
19
|
+
points[1],
|
|
20
|
+
points[2],
|
|
21
|
+
eps
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
export {
|
|
26
|
+
classifyPoint
|
|
27
|
+
};
|
package/clip-convex.js
CHANGED
|
@@ -8,53 +8,54 @@ import { Polygon } from "./api/polygon.js";
|
|
|
8
8
|
import { __copyAttribs } from "./internal/copy.js";
|
|
9
9
|
import { __dispatch } from "./internal/dispatch.js";
|
|
10
10
|
import { ensureVertices, vertices } from "./vertices.js";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* boundary). Returns `undefined` if there're no remaining result vertices.
|
|
15
|
-
*
|
|
16
|
-
* @remarks
|
|
17
|
-
* Internally uses
|
|
18
|
-
* [`sutherlandHodgeman()`](https://docs.thi.ng/umbrella/geom-clip-poly/functions/sutherlandHodgeman.html).
|
|
19
|
-
* For groups, calls itself for each child shape individually and returns a new
|
|
20
|
-
* group of results (if any).
|
|
21
|
-
*
|
|
22
|
-
* @param shape
|
|
23
|
-
* @param boundary
|
|
24
|
-
*/
|
|
25
|
-
export const clipConvex = defmulti(__dispatch, {
|
|
11
|
+
const clipConvex = defmulti(
|
|
12
|
+
__dispatch,
|
|
13
|
+
{
|
|
26
14
|
circle: "rect",
|
|
27
15
|
ellipse: "rect",
|
|
28
16
|
path: "rect",
|
|
29
17
|
quad: "poly",
|
|
30
|
-
tri: "poly"
|
|
31
|
-
},
|
|
18
|
+
tri: "poly"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
32
21
|
group: ({ children, attribs }, boundary) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
? new Group({ ...attribs }, clipped)
|
|
42
|
-
: undefined;
|
|
22
|
+
boundary = ensureVertices(boundary);
|
|
23
|
+
const clipped = [];
|
|
24
|
+
for (let c of children) {
|
|
25
|
+
const res = clipConvex(c, boundary);
|
|
26
|
+
if (res)
|
|
27
|
+
clipped.push(res);
|
|
28
|
+
}
|
|
29
|
+
return clipped.length ? new Group({ ...attribs }, clipped) : void 0;
|
|
43
30
|
},
|
|
44
31
|
line: ($, boundary) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
32
|
+
const segments = clipLineSegmentPoly(
|
|
33
|
+
$.points[0],
|
|
34
|
+
$.points[1],
|
|
35
|
+
ensureVertices(boundary)
|
|
36
|
+
);
|
|
37
|
+
return segments && segments.length ? new Line(segments[0], __copyAttribs($)) : void 0;
|
|
49
38
|
},
|
|
50
39
|
poly: ($, boundary) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
40
|
+
boundary = ensureVertices(boundary);
|
|
41
|
+
const pts = sutherlandHodgeman(
|
|
42
|
+
$.points,
|
|
43
|
+
boundary,
|
|
44
|
+
centroid(boundary)
|
|
45
|
+
);
|
|
46
|
+
return pts.length ? new Polygon(pts, __copyAttribs($)) : void 0;
|
|
54
47
|
},
|
|
55
48
|
rect: ($, boundary) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
boundary = ensureVertices(boundary);
|
|
50
|
+
const pts = sutherlandHodgeman(
|
|
51
|
+
vertices($),
|
|
52
|
+
boundary,
|
|
53
|
+
centroid(boundary)
|
|
54
|
+
);
|
|
55
|
+
return pts.length ? new Polygon(pts, __copyAttribs($)) : void 0;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
export {
|
|
60
|
+
clipConvex
|
|
61
|
+
};
|
package/closest-point.js
CHANGED
|
@@ -1,55 +1,49 @@
|
|
|
1
1
|
import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
2
2
|
import { closestPoint as closestPointArc } from "@thi.ng/geom-arc/closest-point";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
closestPointAABB,
|
|
5
|
+
closestPointRect
|
|
6
|
+
} from "@thi.ng/geom-closest-point/box";
|
|
4
7
|
import { closestPointCircle } from "@thi.ng/geom-closest-point/circle";
|
|
5
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
closestPointPolyline,
|
|
10
|
+
closestPointSegment
|
|
11
|
+
} from "@thi.ng/geom-closest-point/line";
|
|
6
12
|
import { closestPointPlane } from "@thi.ng/geom-closest-point/plane";
|
|
7
13
|
import { closestPointArray } from "@thi.ng/geom-closest-point/points";
|
|
8
14
|
import { closestPointCubic } from "@thi.ng/geom-splines/cubic-closest-point";
|
|
9
15
|
import { closestPointQuadratic } from "@thi.ng/geom-splines/quadratic-closest-point";
|
|
10
16
|
import { add2, add3 } from "@thi.ng/vectors/add";
|
|
11
17
|
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 Circle}
|
|
22
|
-
* - {@link Cubic}
|
|
23
|
-
* - {@link Line}
|
|
24
|
-
* - {@link Plane}
|
|
25
|
-
* - {@link Points}
|
|
26
|
-
* - {@link Points3}
|
|
27
|
-
* - {@link Polygon}
|
|
28
|
-
* - {@link Polyline}
|
|
29
|
-
* - {@link Quad}
|
|
30
|
-
* - {@link Quadratic}
|
|
31
|
-
* - {@link Rect}
|
|
32
|
-
* - {@link Sphere}
|
|
33
|
-
*
|
|
34
|
-
* @param shape
|
|
35
|
-
* @param p
|
|
36
|
-
* @param out
|
|
37
|
-
*/
|
|
38
|
-
export const closestPoint = defmulti(__dispatch, {
|
|
18
|
+
const closestPoint = defmulti(
|
|
19
|
+
__dispatch,
|
|
20
|
+
{
|
|
39
21
|
quad: "poly",
|
|
40
22
|
points3: "points",
|
|
41
23
|
sphere: "circle",
|
|
42
|
-
tri: "poly"
|
|
43
|
-
},
|
|
24
|
+
tri: "poly"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
44
27
|
aabb: ($, p, out) => closestPointAABB(p, $.pos, add3([], $.pos, $.size), out),
|
|
45
28
|
arc: ($, p, out) => closestPointArc(p, $.pos, $.r, $.axis, $.start, $.end, out),
|
|
46
29
|
circle: ($, p, out) => closestPointCircle(p, $.pos, $.r, out),
|
|
47
|
-
cubic: ({ points }, p, out) => closestPointCubic(
|
|
30
|
+
cubic: ({ points }, p, out) => closestPointCubic(
|
|
31
|
+
p,
|
|
32
|
+
points[0],
|
|
33
|
+
points[1],
|
|
34
|
+
points[2],
|
|
35
|
+
points[3],
|
|
36
|
+
out
|
|
37
|
+
),
|
|
48
38
|
line: ({ points }, p, out) => closestPointSegment(p, points[0], points[1], out),
|
|
49
39
|
plane: ($, p, out) => closestPointPlane(p, $.normal, $.w, out),
|
|
50
40
|
points: ($, p, out) => closestPointArray(p, $.points, out),
|
|
51
41
|
poly: ($, p, out) => closestPointPolyline(p, $.points, true, out),
|
|
52
42
|
polyline: ($, p, out) => closestPointPolyline(p, $.points, false, out),
|
|
53
43
|
quadratic: ({ points }, p, out) => closestPointQuadratic(p, points[0], points[1], points[2], out),
|
|
54
|
-
rect: ($, p, out) => closestPointRect(p, $.pos, add2([], $.pos, $.size), out)
|
|
55
|
-
}
|
|
44
|
+
rect: ($, p, out) => closestPointRect(p, $.pos, add2([], $.pos, $.size), out)
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
export {
|
|
48
|
+
closestPoint
|
|
49
|
+
};
|
package/convex-hull.js
CHANGED
|
@@ -4,29 +4,9 @@ import { Polygon } from "./api/polygon.js";
|
|
|
4
4
|
import { __copyAttribs } from "./internal/copy.js";
|
|
5
5
|
import { __dispatch } from "./internal/dispatch.js";
|
|
6
6
|
import { vertices } from "./vertices.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* @remarks
|
|
11
|
-
* Internally uses
|
|
12
|
-
* [`grahamScan2()`](https://docs.thi.ng/umbrella/geom-hull/functions/grahamScan2.html).
|
|
13
|
-
*
|
|
14
|
-
* Currently implemented for:
|
|
15
|
-
*
|
|
16
|
-
* - {@link Arc}
|
|
17
|
-
* - {@link Circle}
|
|
18
|
-
* - {@link Ellipse}
|
|
19
|
-
* - {@link Group} (only the listed child shape types are considered)
|
|
20
|
-
* - {@link Points}
|
|
21
|
-
* - {@link Polygon}
|
|
22
|
-
* - {@link Polyline}
|
|
23
|
-
* - {@link Quad}
|
|
24
|
-
* - {@link Rect}
|
|
25
|
-
* - {@link Triangle}
|
|
26
|
-
*
|
|
27
|
-
* @param shape
|
|
28
|
-
*/
|
|
29
|
-
export const convexHull = defmulti(__dispatch, {
|
|
7
|
+
const convexHull = defmulti(
|
|
8
|
+
__dispatch,
|
|
9
|
+
{
|
|
30
10
|
arc: "group",
|
|
31
11
|
circle: "tri",
|
|
32
12
|
cubic: "group",
|
|
@@ -36,9 +16,14 @@ export const convexHull = defmulti(__dispatch, {
|
|
|
36
16
|
polyline: "points",
|
|
37
17
|
quad: "points",
|
|
38
18
|
quadratic: "group",
|
|
39
|
-
rect: "tri"
|
|
40
|
-
},
|
|
19
|
+
rect: "tri"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
41
22
|
group: ($) => new Polygon(grahamScan2(vertices($)), __copyAttribs($)),
|
|
42
23
|
points: ($) => new Polygon(grahamScan2($.points), __copyAttribs($)),
|
|
43
|
-
tri: ($) => new Polygon(vertices($), __copyAttribs($))
|
|
44
|
-
}
|
|
24
|
+
tri: ($) => new Polygon(vertices($), __copyAttribs($))
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
export {
|
|
28
|
+
convexHull
|
|
29
|
+
};
|
package/cubic.js
CHANGED
|
@@ -4,9 +4,17 @@ import { cubicFromQuadratic as _quad } from "@thi.ng/geom-splines/cubic-quadrati
|
|
|
4
4
|
import { Cubic } from "./api/cubic.js";
|
|
5
5
|
import { __copyAttribs } from "./internal/copy.js";
|
|
6
6
|
import { __pclike } from "./internal/pclike.js";
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
function cubic(...args) {
|
|
8
|
+
return __pclike(Cubic, args);
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const cubicFromArc = (arc) => _arc(arc.pos, arc.r, arc.axis, arc.start, arc.end).map(
|
|
11
|
+
(c) => new Cubic(c, __copyAttribs(arc))
|
|
12
|
+
);
|
|
13
|
+
const cubicFromLine = (a, b, attribs) => new Cubic(_line(a, b), attribs);
|
|
14
|
+
const cubicFromQuadratic = (a, b, c, attribs) => new Cubic(_quad(a, b, c), attribs);
|
|
15
|
+
export {
|
|
16
|
+
cubic,
|
|
17
|
+
cubicFromArc,
|
|
18
|
+
cubicFromLine,
|
|
19
|
+
cubicFromQuadratic
|
|
20
|
+
};
|
package/edges.js
CHANGED
|
@@ -5,70 +5,37 @@ import { asPolyline } from "./as-polyline.js";
|
|
|
5
5
|
import { __dispatch } from "./internal/dispatch.js";
|
|
6
6
|
import { __edges } from "./internal/edges.js";
|
|
7
7
|
import { vertices } from "./vertices.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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 AABB}
|
|
19
|
-
* - {@link Arc}
|
|
20
|
-
* - {@link BPatch}
|
|
21
|
-
* - {@link Circle}
|
|
22
|
-
* - {@link Cubic}
|
|
23
|
-
* - {@link Ellipse}
|
|
24
|
-
* - {@link Group}
|
|
25
|
-
* - {@link Line}
|
|
26
|
-
* - {@link Path}
|
|
27
|
-
* - {@link Polygon}
|
|
28
|
-
* - {@link Polyline}
|
|
29
|
-
* - {@link Quad}
|
|
30
|
-
* - {@link Quadratic}
|
|
31
|
-
* - {@link Rect}
|
|
32
|
-
* - {@link Triangle}
|
|
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
|
-
*
|
|
45
|
-
* @param shape
|
|
46
|
-
* @param opts
|
|
47
|
-
*/
|
|
48
|
-
export const edges = defmulti(__dispatch, {
|
|
8
|
+
const edges = defmulti(
|
|
9
|
+
__dispatch,
|
|
10
|
+
{
|
|
49
11
|
cubic: "arc",
|
|
50
12
|
ellipse: "circle",
|
|
51
13
|
line: "polyline",
|
|
52
14
|
quad: "poly",
|
|
53
15
|
quadratic: "arc",
|
|
54
|
-
tri: "poly"
|
|
55
|
-
},
|
|
16
|
+
tri: "poly"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
56
19
|
aabb: ($) => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
20
|
+
const [a, b, c, d, e, f, g, h] = vertices($);
|
|
21
|
+
return [
|
|
22
|
+
[a, b],
|
|
23
|
+
[b, c],
|
|
24
|
+
[c, d],
|
|
25
|
+
[d, a],
|
|
26
|
+
// bottom
|
|
27
|
+
[e, f],
|
|
28
|
+
[f, g],
|
|
29
|
+
[g, h],
|
|
30
|
+
[h, e],
|
|
31
|
+
// top
|
|
32
|
+
[a, e],
|
|
33
|
+
[b, f],
|
|
34
|
+
// left
|
|
35
|
+
[c, g],
|
|
36
|
+
[d, h]
|
|
37
|
+
// right
|
|
38
|
+
];
|
|
72
39
|
},
|
|
73
40
|
arc: ($, opts) => __edges(asPolyline($, opts).points, false),
|
|
74
41
|
bpatch: ($) => $.edges(),
|
|
@@ -77,5 +44,9 @@ export const edges = defmulti(__dispatch, {
|
|
|
77
44
|
path: ($, opts) => __edges(asPolygon($, opts).points, $.closed),
|
|
78
45
|
poly: ($) => __edges($.points, true),
|
|
79
46
|
polyline: ($) => __edges($.points),
|
|
80
|
-
rect: ($) => __edges(vertices($), true)
|
|
81
|
-
}
|
|
47
|
+
rect: ($) => __edges(vertices($), true)
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
export {
|
|
51
|
+
edges
|
|
52
|
+
};
|
package/ellipse.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Ellipse } from "./api/ellipse.js";
|
|
2
2
|
import { __argsVV } from "./internal/args.js";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
function ellipse(...args) {
|
|
4
|
+
return new Ellipse(...__argsVV(args));
|
|
5
5
|
}
|
|
6
|
+
export {
|
|
7
|
+
ellipse
|
|
8
|
+
};
|
package/fit-into-bounds.js
CHANGED
|
@@ -12,68 +12,85 @@ import { __collBounds } from "./internal/bounds.js";
|
|
|
12
12
|
import { mapPoint } from "./map-point.js";
|
|
13
13
|
import { transform } from "./transform.js";
|
|
14
14
|
import { unmapPoint } from "./unmap-point.js";
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
15
|
+
const __translateScale = (tmat, smat, shape, preTrans, postTrans, scale) => transform(
|
|
16
|
+
shape,
|
|
17
|
+
concat([], tmat([], postTrans), smat([], scale), tmat([], preTrans))
|
|
18
|
+
);
|
|
19
|
+
const fitIntoBounds2 = (shape, dest) => {
|
|
20
|
+
const src = bounds(shape);
|
|
21
|
+
if (!src)
|
|
22
|
+
return;
|
|
23
|
+
const c = centroid(src);
|
|
24
|
+
if (!c)
|
|
25
|
+
return;
|
|
26
|
+
return __translateScale(
|
|
27
|
+
translation23,
|
|
28
|
+
scale23,
|
|
29
|
+
shape,
|
|
30
|
+
neg(null, c),
|
|
31
|
+
centroid(dest),
|
|
32
|
+
minNonZero2(
|
|
33
|
+
safeDiv(dest.size[0], src.size[0]),
|
|
34
|
+
safeDiv(dest.size[1], src.size[1])
|
|
35
|
+
)
|
|
36
|
+
);
|
|
32
37
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
const fitIntoBounds3 = (shape, dest) => {
|
|
39
|
+
const src = bounds(shape);
|
|
40
|
+
if (!src)
|
|
41
|
+
return;
|
|
42
|
+
const c = centroid(src);
|
|
43
|
+
if (!c)
|
|
44
|
+
return;
|
|
45
|
+
return __translateScale(
|
|
46
|
+
translation44,
|
|
47
|
+
scale44,
|
|
48
|
+
shape,
|
|
49
|
+
neg(null, c),
|
|
50
|
+
centroid(dest),
|
|
51
|
+
minNonZero3(
|
|
52
|
+
safeDiv(dest.size[0], src.size[0]),
|
|
53
|
+
safeDiv(dest.size[1], src.size[1]),
|
|
54
|
+
safeDiv(dest.size[2], src.size[2])
|
|
55
|
+
)
|
|
56
|
+
);
|
|
47
57
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
58
|
+
const fitAllIntoBounds2 = (shapes, dest) => {
|
|
59
|
+
const sbraw = __collBounds(shapes, bounds);
|
|
60
|
+
if (!sbraw)
|
|
61
|
+
return;
|
|
62
|
+
const src = new Rect(...sbraw);
|
|
63
|
+
const sx = safeDiv(dest.size[0], src.size[0]);
|
|
64
|
+
const sy = safeDiv(dest.size[1], src.size[1]);
|
|
65
|
+
const scale = sx > 0 ? sy > 0 ? Math.min(sx, sy) : sx : sy;
|
|
66
|
+
const smat = scale23([], scale);
|
|
67
|
+
const b = center(transform(src, smat), centroid(dest));
|
|
68
|
+
const c1 = [];
|
|
69
|
+
const c2 = [];
|
|
70
|
+
const res = [];
|
|
71
|
+
for (let i = shapes.length; i-- > 0; ) {
|
|
72
|
+
const s = shapes[i];
|
|
73
|
+
const sc = centroid(s, c1);
|
|
74
|
+
if (sc) {
|
|
75
|
+
unmapPoint(b, mapPoint(src, sc), c2);
|
|
76
|
+
res.push(
|
|
77
|
+
__translateScale(
|
|
78
|
+
translation23,
|
|
79
|
+
scale23,
|
|
80
|
+
s,
|
|
81
|
+
neg(null, c1),
|
|
82
|
+
c2,
|
|
83
|
+
smat
|
|
84
|
+
)
|
|
85
|
+
);
|
|
86
|
+
} else {
|
|
87
|
+
res.push(s);
|
|
77
88
|
}
|
|
78
|
-
|
|
89
|
+
}
|
|
90
|
+
return res;
|
|
91
|
+
};
|
|
92
|
+
export {
|
|
93
|
+
fitAllIntoBounds2,
|
|
94
|
+
fitIntoBounds2,
|
|
95
|
+
fitIntoBounds3
|
|
79
96
|
};
|
package/flip.js
CHANGED
|
@@ -1,30 +1,9 @@
|
|
|
1
1
|
import { DEFAULT, defmulti } from "@thi.ng/defmulti/defmulti";
|
|
2
2
|
import { neg } from "@thi.ng/vectors/neg";
|
|
3
3
|
import { __dispatch } from "./internal/dispatch.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
* @remarks
|
|
9
|
-
* Currently implemented for:
|
|
10
|
-
*
|
|
11
|
-
* - {@link Arc}
|
|
12
|
-
* - {@link Cubic}
|
|
13
|
-
* - {@link Group} (only eligible shapes)
|
|
14
|
-
* - {@link Line}
|
|
15
|
-
* - {@link Path}
|
|
16
|
-
* - {@link Points}
|
|
17
|
-
* - {@link Points3}
|
|
18
|
-
* - {@link Polygon}
|
|
19
|
-
* - {@link Polyline}
|
|
20
|
-
* - {@link Quad}
|
|
21
|
-
* - {@link Quadratic}
|
|
22
|
-
* - {@link Ray}
|
|
23
|
-
* - {@link Triangle}
|
|
24
|
-
*
|
|
25
|
-
* @param shape
|
|
26
|
-
*/
|
|
27
|
-
export const flip = defmulti(__dispatch, {
|
|
4
|
+
const flip = defmulti(
|
|
5
|
+
__dispatch,
|
|
6
|
+
{
|
|
28
7
|
cubic: "points",
|
|
29
8
|
line: "points",
|
|
30
9
|
points3: "points",
|
|
@@ -32,30 +11,34 @@ export const flip = defmulti(__dispatch, {
|
|
|
32
11
|
polyline: "points",
|
|
33
12
|
quad: "points",
|
|
34
13
|
quadratic: "points",
|
|
35
|
-
tri: "points"
|
|
36
|
-
},
|
|
14
|
+
tri: "points"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
37
17
|
[DEFAULT]: (x) => x,
|
|
38
18
|
arc: ($) => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
19
|
+
const t = $.start;
|
|
20
|
+
$.start = $.end;
|
|
21
|
+
$.end = t;
|
|
22
|
+
$.cw = !$.cw;
|
|
23
|
+
return $;
|
|
44
24
|
},
|
|
45
25
|
group: ($) => {
|
|
46
|
-
|
|
47
|
-
|
|
26
|
+
$.children.forEach(flip);
|
|
27
|
+
return $;
|
|
48
28
|
},
|
|
49
29
|
path: ($) => {
|
|
50
|
-
|
|
51
|
-
return $;
|
|
30
|
+
return $;
|
|
52
31
|
},
|
|
53
32
|
points: ($) => {
|
|
54
|
-
|
|
55
|
-
|
|
33
|
+
$.points.reverse();
|
|
34
|
+
return $;
|
|
56
35
|
},
|
|
57
36
|
ray: ($) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
}
|
|
37
|
+
$.dir = neg(null, $.dir);
|
|
38
|
+
return $;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
export {
|
|
43
|
+
flip
|
|
44
|
+
};
|
package/group.js
CHANGED