@thi.ng/geom 7.0.1 → 8.0.1
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 +196 -1
- package/README.md +357 -114
- package/aabb.d.ts +26 -1
- package/api/aabb.d.ts +5 -4
- package/api/aabb.js +10 -7
- package/api/apc.d.ts +5 -3
- package/api/arc.d.ts +6 -5
- package/api/arc.js +3 -4
- package/api/bpatch.d.ts +6 -3
- package/api/bpatch.js +5 -3
- package/api/circle.d.ts +4 -3
- package/api/circle.js +9 -6
- package/api/complex-polygon.d.ts +7 -3
- package/api/complex-polygon.js +14 -4
- package/api/cubic.d.ts +8 -5
- package/api/cubic.js +12 -6
- package/api/cubic3.d.ts +15 -0
- package/api/cubic3.js +38 -0
- package/api/ellipse.d.ts +4 -3
- package/api/ellipse.js +7 -8
- package/api/extra.d.ts +15 -0
- package/api/extra.js +19 -0
- package/api/group.d.ts +12 -11
- package/api/group.js +4 -5
- package/api/group3.d.ts +30 -0
- package/api/group3.js +48 -0
- package/api/line.d.ts +8 -5
- package/api/line.js +8 -8
- package/api/line3.d.ts +15 -0
- package/api/line3.js +29 -0
- package/api/path.d.ts +14 -11
- package/api/path.js +17 -12
- package/api/path3.d.ts +28 -0
- package/api/path3.js +91 -0
- package/api/plane.d.ts +4 -3
- package/api/plane.js +7 -4
- package/api/points.d.ts +8 -10
- package/api/points.js +7 -20
- package/api/points3.d.ts +13 -0
- package/api/points3.js +21 -0
- package/api/polygon.d.ts +7 -4
- package/api/polygon.js +5 -3
- package/api/polygon3.d.ts +14 -0
- package/api/polygon3.js +24 -0
- package/api/polyline.d.ts +18 -4
- package/api/polyline.js +8 -5
- package/api/polyline3.d.ts +28 -0
- package/api/polyline3.js +31 -0
- package/api/quad.d.ts +7 -4
- package/api/quad.js +5 -3
- package/api/quad3.d.ts +7 -4
- package/api/quad3.js +6 -4
- package/api/quadratic.d.ts +8 -5
- package/api/quadratic.js +12 -6
- package/api/quadratic3.d.ts +15 -0
- package/api/quadratic3.js +38 -0
- package/api/ray.d.ts +4 -3
- package/api/ray.js +6 -7
- package/api/ray3.d.ts +14 -0
- package/api/ray3.js +33 -0
- package/api/rect.d.ts +5 -3
- package/api/rect.js +11 -8
- package/api/sphere.d.ts +4 -3
- package/api/sphere.js +8 -5
- package/api/text.d.ts +4 -3
- package/api/text.js +8 -5
- package/api/triangle.d.ts +7 -4
- package/api/triangle.js +5 -3
- package/api/triangle3.d.ts +14 -0
- package/api/triangle3.js +26 -0
- package/api.d.ts +193 -0
- package/api.js +10 -0
- package/apply-transforms.d.ts +33 -11
- package/apply-transforms.js +24 -4
- package/arc-length.d.ts +18 -4
- package/arc-length.js +18 -3
- package/arc.d.ts +1 -1
- package/area.d.ts +6 -10
- package/area.js +3 -3
- package/as-cubic.d.ts +31 -5
- package/as-cubic.js +86 -24
- package/as-path.d.ts +14 -7
- package/as-path.js +49 -24
- package/as-polygon.d.ts +20 -5
- package/as-polygon.js +46 -12
- package/as-polyline.d.ts +18 -5
- package/as-polyline.js +29 -23
- package/as-sector.d.ts +13 -0
- package/as-sector.js +18 -0
- package/as-svg.d.ts +31 -9
- package/as-svg.js +21 -18
- package/bounds.d.ts +12 -2
- package/bounds.js +15 -0
- package/bpatch.d.ts +26 -1
- package/center-of-weight.d.ts +22 -0
- package/center-of-weight.js +23 -0
- package/center.d.ts +11 -5
- package/center.js +9 -4
- package/centroid-of-bounds.d.ts +12 -0
- package/centroid-of-bounds.js +9 -0
- package/centroid.d.ts +14 -4
- package/centroid.js +16 -17
- package/circle.d.ts +1 -1
- package/classify-point.d.ts +3 -1
- package/classify-point.js +7 -4
- package/clip-convex.d.ts +27 -8
- package/clip-convex.js +52 -17
- package/closest-point.d.ts +1 -1
- package/complex-polygon-from-path.d.ts +1 -1
- package/complex-polygon.d.ts +1 -1
- package/convex-hull.d.ts +9 -2
- package/convex-hull.js +3 -3
- package/convolve.d.ts +72 -0
- package/convolve.js +33 -0
- package/cubic.d.ts +1 -1
- package/cubic.js +7 -7
- package/cubic3.d.ts +8 -0
- package/cubic3.js +14 -0
- package/edges.d.ts +2 -2
- package/ellipse.d.ts +1 -1
- package/extra.d.ts +14 -0
- package/extra.js +5 -0
- package/fit-into-bounds.d.ts +14 -4
- package/fit-into-bounds.js +6 -6
- package/flip.d.ts +21 -5
- package/flip.js +19 -12
- package/from-tessellation.d.ts +81 -0
- package/from-tessellation.js +27 -0
- package/group.d.ts +2 -2
- package/group3.d.ts +16 -0
- package/group3.js +5 -0
- package/index.d.ts +36 -1
- package/index.js +36 -1
- package/internal/bounds.d.ts +3 -4
- package/internal/copy.d.ts +8 -7
- package/internal/copy.js +3 -7
- package/internal/dispatch.d.ts +1 -1
- package/internal/error.d.ts +3 -0
- package/internal/error.js +6 -0
- package/internal/pclike.d.ts +3 -2
- package/internal/pclike.js +6 -0
- package/internal/points-as-shape.d.ts +11 -2
- package/internal/points-as-shape.js +10 -1
- package/internal/split.d.ts +2 -2
- package/internal/split.js +13 -8
- package/internal/transform.d.ts +6 -22
- package/internal/transform.js +2 -21
- package/internal/vertices.d.ts +3 -2
- package/internal/vertices.js +3 -1
- package/intersects.d.ts +5 -4
- package/intersects.js +6 -4
- package/line.d.ts +1 -1
- package/line3.d.ts +6 -0
- package/line3.js +9 -0
- package/map-point.d.ts +1 -1
- package/normalized-path.d.ts +17 -0
- package/normalized-path.js +23 -0
- package/offset.d.ts +16 -2
- package/offset.js +2 -2
- package/package.json +149 -35
- package/path-builder.d.ts +42 -13
- package/path-builder.js +68 -42
- package/path-from-cubics.d.ts +26 -0
- package/path-from-cubics.js +39 -0
- package/path-from-svg.d.ts +1 -1
- package/path-from-svg.js +29 -29
- package/path.d.ts +2 -52
- package/path.js +1 -58
- package/path3.d.ts +16 -0
- package/path3.js +5 -0
- package/plane.d.ts +11 -1
- package/plane.js +3 -0
- package/point-at.d.ts +1 -1
- package/point-inside.d.ts +3 -1
- package/point-inside.js +4 -1
- package/points.d.ts +2 -3
- package/points.js +2 -4
- package/points3.d.ts +5 -0
- package/points3.js +5 -0
- package/polygon.d.ts +5 -5
- package/polygon3.d.ts +5 -0
- package/polygon3.js +5 -0
- package/polyline.d.ts +2 -2
- package/polyline3.d.ts +5 -0
- package/polyline3.js +5 -0
- package/proximity.d.ts +5 -3
- package/proximity.js +2 -2
- package/quad.d.ts +2 -7
- package/quad.js +1 -29
- package/quad3.d.ts +8 -0
- package/quad3.js +30 -0
- package/quadratic.d.ts +1 -1
- package/quadratic3.d.ts +7 -0
- package/quadratic3.js +11 -0
- package/ray.d.ts +1 -1
- package/ray.js +2 -2
- package/ray3.d.ts +5 -0
- package/ray3.js +6 -0
- package/rect.d.ts +1 -1
- package/resample.d.ts +45 -4
- package/resample.js +26 -16
- package/rotate-around-axis.d.ts +33 -0
- package/rotate-around-axis.js +57 -0
- package/rotate.d.ts +15 -2
- package/rotate.js +47 -45
- package/rounded-rect.d.ts +25 -0
- package/rounded-rect.js +18 -0
- package/scale-with-center.d.ts +2 -2
- package/scale.d.ts +24 -2
- package/scale.js +59 -43
- package/scatter.d.ts +1 -1
- package/simplify.d.ts +8 -2
- package/simplify.js +7 -4
- package/smooth-poly.d.ts +27 -0
- package/smooth-poly.js +11 -0
- package/sphere.d.ts +1 -1
- package/split-arclength.d.ts +6 -2
- package/split-at.d.ts +18 -2
- package/split-at.js +66 -34
- package/split-near.d.ts +13 -2
- package/split-near.js +23 -27
- package/subdiv-curve.d.ts +81 -27
- package/subdiv-curve.js +44 -28
- package/tangent-at.d.ts +1 -1
- package/tessellate.d.ts +72 -18
- package/tessellate.js +53 -8
- package/text.d.ts +1 -1
- package/transform-vertices.d.ts +30 -6
- package/transform-vertices.js +36 -38
- package/transform.d.ts +30 -2
- package/transform.js +54 -40
- package/translate.d.ts +12 -2
- package/translate.js +42 -43
- package/triangle.d.ts +1 -1
- package/triangle3.d.ts +6 -0
- package/triangle3.js +8 -0
- package/union.d.ts +11 -2
- package/union.js +6 -7
- package/unmap-point.d.ts +1 -1
- package/vertices.d.ts +3 -3
- package/vertices.js +14 -4
- package/volume.d.ts +1 -1
- package/warp-points.d.ts +35 -4
- package/warp-points.js +2 -0
- package/with-attribs.d.ts +4 -5
- package/internal/rotate.d.ts +0 -5
- package/internal/rotate.js +0 -8
- package/internal/scale.d.ts +0 -5
- package/internal/scale.js +0 -12
- package/internal/translate.d.ts +0 -5
- package/internal/translate.js +0 -8
package/transform-vertices.js
CHANGED
|
@@ -1,57 +1,55 @@
|
|
|
1
1
|
import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
2
|
-
import { ComplexPolygon } from "./api/complex-polygon.js";
|
|
3
|
-
import { Cubic } from "./api/cubic.js";
|
|
4
|
-
import { Line } from "./api/line.js";
|
|
5
2
|
import { Path } from "./api/path.js";
|
|
6
|
-
import { Points
|
|
3
|
+
import { Points } from "./api/points.js";
|
|
7
4
|
import { Polygon } from "./api/polygon.js";
|
|
8
5
|
import { Polyline } from "./api/polyline.js";
|
|
9
|
-
import { Quad } from "./api/quad.js";
|
|
10
|
-
import { Quadratic } from "./api/quadratic.js";
|
|
11
|
-
import { Triangle } from "./api/triangle.js";
|
|
12
6
|
import { asPolygon } from "./as-polygon.js";
|
|
13
7
|
import { asPolyline } from "./as-polyline.js";
|
|
14
|
-
import { __copyAttribs } from "./internal/copy.js";
|
|
15
8
|
import { __dispatch } from "./internal/dispatch.js";
|
|
9
|
+
import { __ensureNoArc } from "./internal/error.js";
|
|
16
10
|
import {
|
|
17
11
|
__segmentTransformer,
|
|
18
|
-
|
|
19
|
-
__transformedShapePoints3 as tx3
|
|
12
|
+
__transformedPointsWith
|
|
20
13
|
} from "./internal/transform.js";
|
|
21
14
|
const transformVertices = defmulti(
|
|
22
15
|
__dispatch,
|
|
23
16
|
{
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
arc: "$aspolyline",
|
|
18
|
+
circle: "$aspoly",
|
|
19
|
+
complexpoly: "group",
|
|
20
|
+
ellipse: "$aspoly",
|
|
21
|
+
group3: "group",
|
|
22
|
+
bpatch: "points",
|
|
23
|
+
cubic: "points",
|
|
24
|
+
cubic3: "points",
|
|
25
|
+
line: "points",
|
|
26
|
+
line3: "points",
|
|
27
|
+
path3: "path",
|
|
28
|
+
points3: "points",
|
|
29
|
+
poly: "points",
|
|
30
|
+
poly3: "points",
|
|
31
|
+
polyline: "points",
|
|
32
|
+
polyline3: "points",
|
|
33
|
+
quad: "points",
|
|
34
|
+
quad3: "points",
|
|
35
|
+
quadratic: "points",
|
|
36
|
+
quadratic3: "points",
|
|
37
|
+
rect: "$aspoly",
|
|
38
|
+
tri: "points",
|
|
39
|
+
tri3: "points"
|
|
26
40
|
},
|
|
27
41
|
{
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
$.children.map((child) => transformVertices(child, fn))
|
|
32
|
-
),
|
|
33
|
-
cubic: tx(Cubic),
|
|
42
|
+
$aspoly: ($, fn) => transformVertices(asPolygon($)[0], fn),
|
|
43
|
+
$aspolyline: ($, fn) => transformVertices(asPolyline($)[0], fn),
|
|
44
|
+
extra: ($) => $,
|
|
34
45
|
group: ($, fn) => $.copyTransformed((x) => transformVertices(x, fn)),
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
$transformSegments($.segments),
|
|
43
|
-
$.subPaths.map($transformSegments),
|
|
44
|
-
__copyAttribs($)
|
|
45
|
-
);
|
|
46
|
-
},
|
|
47
|
-
points: tx(Points),
|
|
48
|
-
points3: tx3(Points3),
|
|
49
|
-
poly: tx(Polygon),
|
|
50
|
-
polyline: tx(Polyline),
|
|
51
|
-
quad: tx(Quad),
|
|
52
|
-
quadratic: tx(Quadratic),
|
|
53
|
-
rect: ($, fn) => transformVertices(asPolygon($)[0], fn),
|
|
54
|
-
tri: tx(Triangle)
|
|
46
|
+
path: ($, fn) => $.copyTransformed(
|
|
47
|
+
__segmentTransformer((geo) => {
|
|
48
|
+
__ensureNoArc(geo);
|
|
49
|
+
return transformVertices(geo, fn);
|
|
50
|
+
}, fn)
|
|
51
|
+
),
|
|
52
|
+
points: ($, fn) => $.copyTransformed((pts) => __transformedPointsWith(pts, fn))
|
|
55
53
|
}
|
|
56
54
|
);
|
|
57
55
|
export {
|
package/transform.d.ts
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
import type { MultiFn2 } from "@thi.ng/defmulti";
|
|
2
|
-
import type { IShape } from "@thi.ng/geom-api";
|
|
3
2
|
import type { ReadonlyMat } from "@thi.ng/matrices";
|
|
3
|
+
import type { IShape, IShape2, IShape3 } from "./api.js";
|
|
4
|
+
import type { Arc } from "./api/arc.js";
|
|
5
|
+
import type { Circle } from "./api/circle.js";
|
|
6
|
+
import type { Ellipse } from "./api/ellipse.js";
|
|
7
|
+
import { Path } from "./api/path.js";
|
|
8
|
+
import { Quad } from "./api/quad.js";
|
|
9
|
+
import type { Rect } from "./api/rect.js";
|
|
10
|
+
/**
|
|
11
|
+
* Function overrides for {@link transform}.
|
|
12
|
+
*/
|
|
13
|
+
export type TransformFn = {
|
|
14
|
+
(shape: Arc, mat: ReadonlyMat): Path;
|
|
15
|
+
(shape: Circle, mat: ReadonlyMat): Path;
|
|
16
|
+
(shape: Ellipse, mat: ReadonlyMat): Path;
|
|
17
|
+
(shape: Rect, mat: ReadonlyMat): Quad;
|
|
18
|
+
<T extends IShape2>(shape: T, mat: ReadonlyMat): T;
|
|
19
|
+
<T extends IShape3>(shape: T, mat: ReadonlyMat): T;
|
|
20
|
+
} & MultiFn2<IShape, ReadonlyMat, IShape>;
|
|
4
21
|
/**
|
|
5
22
|
* Transforms given shape with provided matrix.
|
|
6
23
|
*
|
|
@@ -18,26 +35,37 @@ import type { ReadonlyMat } from "@thi.ng/matrices";
|
|
|
18
35
|
* Currently implemented for:
|
|
19
36
|
*
|
|
20
37
|
* - {@link Arc}
|
|
38
|
+
* - {@link BPatch}
|
|
21
39
|
* - {@link Circle}
|
|
22
40
|
* - {@link ComplexPolygon}
|
|
23
41
|
* - {@link Cubic}
|
|
42
|
+
* - {@link Cubic3}
|
|
24
43
|
* - {@link Ellipse}
|
|
44
|
+
* - {@link Extra}
|
|
25
45
|
* - {@link Group}
|
|
46
|
+
* - {@link Group3}
|
|
26
47
|
* - {@link Line}
|
|
48
|
+
* - {@link Line3}
|
|
27
49
|
* - {@link Path}
|
|
50
|
+
* - {@link Path3}
|
|
28
51
|
* - {@link Points}
|
|
29
52
|
* - {@link Points3}
|
|
30
53
|
* - {@link Polygon}
|
|
54
|
+
* - {@link Polygon3}
|
|
31
55
|
* - {@link Polyline}
|
|
56
|
+
* - {@link Polyline3}
|
|
32
57
|
* - {@link Quad}
|
|
58
|
+
* - {@link Quad3}
|
|
33
59
|
* - {@link Quadratic}
|
|
60
|
+
* - {@link Quadratic3}
|
|
34
61
|
* - {@link Ray}
|
|
35
62
|
* - {@link Rect}
|
|
36
63
|
* - {@link Text}
|
|
37
64
|
* - {@link Triangle}
|
|
65
|
+
* - {@link Triangle3}
|
|
38
66
|
*
|
|
39
67
|
* @param shape
|
|
40
68
|
* @param mat
|
|
41
69
|
*/
|
|
42
|
-
export declare const transform:
|
|
70
|
+
export declare const transform: TransformFn;
|
|
43
71
|
//# sourceMappingURL=transform.d.ts.map
|
package/transform.js
CHANGED
|
@@ -1,60 +1,74 @@
|
|
|
1
1
|
import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
2
|
-
import {
|
|
3
|
-
import { ComplexPolygon } from "./api/complex-polygon.js";
|
|
4
|
-
import { Cubic } from "./api/cubic.js";
|
|
5
|
-
import { Line } from "./api/line.js";
|
|
2
|
+
import { mulV23, mulV344 } from "@thi.ng/matrices/mulv";
|
|
6
3
|
import { Path } from "./api/path.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
4
|
+
import { Path3 } from "./api/path3.js";
|
|
5
|
+
import { Points } from "./api/points.js";
|
|
6
|
+
import { Points3 } from "./api/points3.js";
|
|
10
7
|
import { Quad } from "./api/quad.js";
|
|
11
|
-
import { Quadratic } from "./api/quadratic.js";
|
|
12
8
|
import { Text } from "./api/text.js";
|
|
13
|
-
import { Triangle } from "./api/triangle.js";
|
|
14
9
|
import { asPath } from "./as-path.js";
|
|
15
10
|
import { __copyAttribs } from "./internal/copy.js";
|
|
16
11
|
import { __dispatch } from "./internal/dispatch.js";
|
|
12
|
+
import { __ensureNoArc } from "./internal/error.js";
|
|
17
13
|
import {
|
|
18
14
|
__segmentTransformer,
|
|
19
|
-
|
|
20
|
-
__transformedShape3 as tx3
|
|
15
|
+
__transformedPoints
|
|
21
16
|
} from "./internal/transform.js";
|
|
22
17
|
import { vertices } from "./vertices.js";
|
|
23
18
|
const transform = defmulti(
|
|
24
19
|
__dispatch,
|
|
25
20
|
{
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
arc: "$aspath",
|
|
22
|
+
circle: "$aspath",
|
|
23
|
+
complexpoly: "group",
|
|
24
|
+
bpatch: "points",
|
|
25
|
+
cubic: "points",
|
|
26
|
+
cubic3: "points3",
|
|
27
|
+
ellipse: "$aspath",
|
|
28
|
+
group3: "group",
|
|
29
|
+
line: "points",
|
|
30
|
+
line3: "points3",
|
|
31
|
+
poly: "points",
|
|
32
|
+
poly3: "points3",
|
|
33
|
+
polyline: "points",
|
|
34
|
+
polyline3: "points3",
|
|
35
|
+
quad: "points",
|
|
36
|
+
quad3: "points3",
|
|
37
|
+
quadratic: "points",
|
|
38
|
+
quadratic3: "points3",
|
|
39
|
+
tri: "points",
|
|
40
|
+
tri3: "points3"
|
|
28
41
|
},
|
|
29
42
|
{
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
transform($.boundary, mat),
|
|
33
|
-
$.children.map((child) => transform(child, mat))
|
|
34
|
-
),
|
|
35
|
-
cubic: tx(Cubic),
|
|
43
|
+
$aspath: ($, mat) => transform(asPath($), mat),
|
|
44
|
+
extra: ($) => $,
|
|
36
45
|
group: ($, mat) => $.copyTransformed((x) => transform(x, mat)),
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
46
|
+
path: ($, mat) => $.copyTransformed(
|
|
47
|
+
__segmentTransformer(
|
|
48
|
+
(geo) => {
|
|
49
|
+
__ensureNoArc(geo);
|
|
50
|
+
return transform(geo, mat);
|
|
51
|
+
},
|
|
52
|
+
(p) => mulV23([], mat, p)
|
|
53
|
+
)
|
|
54
|
+
),
|
|
55
|
+
path3: ($, mat) => $.copyTransformed(
|
|
56
|
+
__segmentTransformer(
|
|
57
|
+
(geo) => {
|
|
58
|
+
__ensureNoArc(geo);
|
|
59
|
+
return transform(geo, mat);
|
|
60
|
+
},
|
|
61
|
+
(p) => mulV344([], mat, p)
|
|
62
|
+
)
|
|
63
|
+
),
|
|
64
|
+
points: ($, mat) => $.copyTransformed(
|
|
65
|
+
(points) => __transformedPoints(points, mat, mulV23)
|
|
66
|
+
),
|
|
67
|
+
points3: ($, mat) => $.copyTransformed(
|
|
68
|
+
(points) => __transformedPoints(points, mat, mulV344)
|
|
69
|
+
),
|
|
70
|
+
rect: ($, mat) => transform(new Quad(vertices($), __copyAttribs($.attribs)), mat),
|
|
71
|
+
text: ($, mat) => new Text(mulV23([], mat, $.pos), $.body, __copyAttribs($.attribs))
|
|
58
72
|
}
|
|
59
73
|
);
|
|
60
74
|
export {
|
package/translate.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { MultiFn2 } from "@thi.ng/defmulti";
|
|
2
|
-
import type { IShape } from "@thi.ng/geom-api";
|
|
3
2
|
import type { ReadonlyVec } from "@thi.ng/vectors";
|
|
3
|
+
import type { IShape } from "./api.js";
|
|
4
|
+
/**
|
|
5
|
+
* Function overrides for {@link translate}.
|
|
6
|
+
*/
|
|
7
|
+
export type TranslateFn = {
|
|
8
|
+
<T extends IShape>(shape: T, offset: ReadonlyVec): T;
|
|
9
|
+
} & MultiFn2<IShape, ReadonlyVec, IShape>;
|
|
4
10
|
/**
|
|
5
11
|
* Translates given shape by given `offset` vector.
|
|
6
12
|
*
|
|
@@ -9,11 +15,15 @@ import type { ReadonlyVec } from "@thi.ng/vectors";
|
|
|
9
15
|
*
|
|
10
16
|
* - {@link AABB}
|
|
11
17
|
* - {@link Arc}
|
|
18
|
+
* - {@link BPatch}
|
|
12
19
|
* - {@link Circle}
|
|
13
20
|
* - {@link ComplexPolygon}
|
|
14
21
|
* - {@link Cubic}
|
|
22
|
+
* - {@link Cubic3}
|
|
15
23
|
* - {@link Ellipse}
|
|
24
|
+
* - {@link Extra}
|
|
16
25
|
* - {@link Group}
|
|
26
|
+
* - {@link Group3}
|
|
17
27
|
* - {@link Line}
|
|
18
28
|
* - {@link Path}
|
|
19
29
|
* - {@link Points}
|
|
@@ -31,5 +41,5 @@ import type { ReadonlyVec } from "@thi.ng/vectors";
|
|
|
31
41
|
* @param shape
|
|
32
42
|
* @param offset
|
|
33
43
|
*/
|
|
34
|
-
export declare const translate:
|
|
44
|
+
export declare const translate: TranslateFn;
|
|
35
45
|
//# sourceMappingURL=translate.d.ts.map
|
package/translate.js
CHANGED
|
@@ -1,80 +1,79 @@
|
|
|
1
1
|
import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
2
|
-
import { add2, add3 } from "@thi.ng/vectors/add";
|
|
2
|
+
import { add, add2, add3 } from "@thi.ng/vectors/add";
|
|
3
3
|
import { set2, set3 } from "@thi.ng/vectors/set";
|
|
4
4
|
import { AABB } from "./api/aabb.js";
|
|
5
5
|
import { Circle } from "./api/circle.js";
|
|
6
|
-
import { ComplexPolygon } from "./api/complex-polygon.js";
|
|
7
|
-
import { Cubic } from "./api/cubic.js";
|
|
8
6
|
import { Ellipse } from "./api/ellipse.js";
|
|
9
|
-
import { Line } from "./api/line.js";
|
|
10
|
-
import { Path } from "./api/path.js";
|
|
11
|
-
import { Points, Points3 } from "./api/points.js";
|
|
12
|
-
import { Polygon } from "./api/polygon.js";
|
|
13
|
-
import { Polyline } from "./api/polyline.js";
|
|
14
|
-
import { Quad } from "./api/quad.js";
|
|
15
|
-
import { Quadratic } from "./api/quadratic.js";
|
|
16
7
|
import { Ray } from "./api/ray.js";
|
|
8
|
+
import { Ray3 } from "./api/ray3.js";
|
|
17
9
|
import { Rect } from "./api/rect.js";
|
|
18
10
|
import { Sphere } from "./api/sphere.js";
|
|
19
11
|
import { Text } from "./api/text.js";
|
|
20
|
-
import { Triangle } from "./api/triangle.js";
|
|
21
12
|
import { __copyAttribs } from "./internal/copy.js";
|
|
22
13
|
import { __dispatch } from "./internal/dispatch.js";
|
|
23
14
|
import { __segmentTransformer } from "./internal/transform.js";
|
|
24
|
-
import { __translatedShape as tx } from "./internal/translate.js";
|
|
25
15
|
const translate = defmulti(
|
|
26
16
|
__dispatch,
|
|
27
|
-
{
|
|
17
|
+
{
|
|
18
|
+
bpatch: "points",
|
|
19
|
+
cubic: "points",
|
|
20
|
+
cubic3: "points3",
|
|
21
|
+
complexpoly: "group",
|
|
22
|
+
group3: "group",
|
|
23
|
+
line: "points",
|
|
24
|
+
line3: "points3",
|
|
25
|
+
path3: "path",
|
|
26
|
+
poly: "points",
|
|
27
|
+
poly3: "points3",
|
|
28
|
+
polyline: "points",
|
|
29
|
+
polyline3: "points3",
|
|
30
|
+
quad: "points",
|
|
31
|
+
quad3: "points3",
|
|
32
|
+
quadratic: "points",
|
|
33
|
+
quadratic3: "points3",
|
|
34
|
+
tri: "points",
|
|
35
|
+
tri3: "points3"
|
|
36
|
+
},
|
|
28
37
|
{
|
|
29
38
|
aabb: ($, delta) => new AABB(
|
|
30
39
|
add3([], $.pos, delta),
|
|
31
40
|
set3([], $.size),
|
|
32
|
-
__copyAttribs(
|
|
41
|
+
__copyAttribs($.attribs)
|
|
33
42
|
),
|
|
34
43
|
arc: ($, delta) => {
|
|
35
44
|
const a = $.copy();
|
|
36
45
|
add2(null, a.pos, delta);
|
|
37
46
|
return a;
|
|
38
47
|
},
|
|
39
|
-
circle: ($, delta) => new Circle(add2([], $.pos, delta), $.r, __copyAttribs(
|
|
40
|
-
complexpoly: ($, delta) => new ComplexPolygon(
|
|
41
|
-
translate($.boundary, delta),
|
|
42
|
-
$.children.map((child) => translate(child, delta))
|
|
43
|
-
),
|
|
44
|
-
cubic: tx(Cubic),
|
|
48
|
+
circle: ($, delta) => new Circle(add2([], $.pos, delta), $.r, __copyAttribs($.attribs)),
|
|
45
49
|
ellipse: ($, delta) => new Ellipse(
|
|
46
50
|
add2([], $.pos, delta),
|
|
47
51
|
set2([], $.r),
|
|
48
|
-
__copyAttribs(
|
|
52
|
+
__copyAttribs($.attribs)
|
|
49
53
|
),
|
|
54
|
+
extra: ($) => $,
|
|
50
55
|
group: ($, delta) => $.copyTransformed((x) => translate(x, delta)),
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const $translateSegments = __segmentTransformer(
|
|
56
|
+
path: ($, delta) => $.copyTransformed(
|
|
57
|
+
__segmentTransformer(
|
|
54
58
|
(geo) => translate(geo, delta),
|
|
55
|
-
(p) =>
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
polyline: tx(Polyline),
|
|
67
|
-
quad: tx(Quad),
|
|
68
|
-
quadratic: tx(Quadratic),
|
|
69
|
-
ray: ($, delta) => new Ray(add2([], $.pos, delta), $.dir, __copyAttribs($)),
|
|
59
|
+
(p) => add([], p, delta)
|
|
60
|
+
)
|
|
61
|
+
),
|
|
62
|
+
points: ($, delta) => $.copyTransformed(
|
|
63
|
+
(points) => points.map((x) => add2([], x, delta))
|
|
64
|
+
),
|
|
65
|
+
points3: ($, delta) => $.copyTransformed(
|
|
66
|
+
(points) => points.map((x) => add3([], x, delta))
|
|
67
|
+
),
|
|
68
|
+
ray: ($, delta) => new Ray(add2([], $.pos, delta), $.dir, __copyAttribs($.attribs)),
|
|
69
|
+
ray3: ($, delta) => new Ray3(add3([], $.pos, delta), $.dir, __copyAttribs($.attribs)),
|
|
70
70
|
rect: ($, delta) => new Rect(
|
|
71
71
|
add2([], $.pos, delta),
|
|
72
72
|
set2([], $.size),
|
|
73
|
-
__copyAttribs(
|
|
73
|
+
__copyAttribs($.attribs)
|
|
74
74
|
),
|
|
75
|
-
sphere: ($, delta) => new Sphere(add3([], $.pos, delta), $.r, __copyAttribs(
|
|
76
|
-
text: ($, delta) => new Text(add2([], $.pos, delta), $.body, __copyAttribs(
|
|
77
|
-
tri: tx(Triangle)
|
|
75
|
+
sphere: ($, delta) => new Sphere(add3([], $.pos, delta), $.r, __copyAttribs($.attribs)),
|
|
76
|
+
text: ($, delta) => new Text(add2([], $.pos, delta), $.body, __copyAttribs($.attribs))
|
|
78
77
|
}
|
|
79
78
|
);
|
|
80
79
|
export {
|
package/triangle.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Attribs } from "
|
|
1
|
+
import type { Attribs } from "./api.js";
|
|
2
2
|
import type { Vec } from "@thi.ng/vectors";
|
|
3
3
|
import { Triangle } from "./api/triangle.js";
|
|
4
4
|
export declare function triangle(a: Vec, b: Vec, c: Vec, attribs?: Attribs): Triangle;
|
package/triangle3.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Attribs } from "./api.js";
|
|
2
|
+
import type { Vec } from "@thi.ng/vectors";
|
|
3
|
+
import { Triangle3 } from "./api/triangle3.js";
|
|
4
|
+
export declare function triangle3(a: Vec, b: Vec, c: Vec, attribs?: Attribs): Triangle3;
|
|
5
|
+
export declare function triangle3(pts: Iterable<Vec>, attribs?: Attribs): Triangle3;
|
|
6
|
+
//# sourceMappingURL=triangle3.d.ts.map
|
package/triangle3.js
ADDED
package/union.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import type { MultiFn2 } from "@thi.ng/defmulti";
|
|
2
|
-
import type { IShape } from "
|
|
2
|
+
import type { IShape } from "./api.js";
|
|
3
|
+
import { AABB } from "./api/aabb.js";
|
|
4
|
+
import { Rect } from "./api/rect.js";
|
|
5
|
+
/**
|
|
6
|
+
* Function overrides for {@link union}.
|
|
7
|
+
*/
|
|
8
|
+
export type UnionFn = {
|
|
9
|
+
(a: AABB, b: AABB): AABB;
|
|
10
|
+
(a: Rect, b: Rect): Rect;
|
|
11
|
+
} & MultiFn2<IShape, IShape, IShape>;
|
|
3
12
|
/**
|
|
4
13
|
* Computes shape "union" of given 2 shapes.
|
|
5
14
|
*
|
|
@@ -10,5 +19,5 @@ import type { IShape } from "@thi.ng/geom-api";
|
|
|
10
19
|
* @param a
|
|
11
20
|
* @param b
|
|
12
21
|
*/
|
|
13
|
-
export declare const union:
|
|
22
|
+
export declare const union: UnionFn;
|
|
14
23
|
//# sourceMappingURL=union.d.ts.map
|
package/union.js
CHANGED
|
@@ -5,14 +5,13 @@ import { __unionBounds } from "./internal/bounds.js";
|
|
|
5
5
|
import { __dispatch } from "./internal/dispatch.js";
|
|
6
6
|
const union = defmulti(
|
|
7
7
|
__dispatch,
|
|
8
|
-
{},
|
|
9
8
|
{
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
rect: "aabb"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
aabb: (a, b) => new a.constructor(
|
|
13
|
+
...__unionBounds(a.pos, a.size, b.pos, b.size)
|
|
14
|
+
)
|
|
16
15
|
}
|
|
17
16
|
);
|
|
18
17
|
export {
|
package/unmap-point.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MultiFn2O } from "@thi.ng/defmulti";
|
|
2
|
-
import type { IShape } from "
|
|
2
|
+
import type { IShape } from "./api.js";
|
|
3
3
|
import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
|
|
4
4
|
/**
|
|
5
5
|
* Projects given point `uv` (normalized coords) into the target space defined
|
package/vertices.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { MultiFn1O } from "@thi.ng/defmulti";
|
|
2
|
-
import type { IShape } from "@thi.ng/geom-api";
|
|
3
|
-
import { type SamplingOpts } from "@thi.ng/geom-api/sample";
|
|
4
2
|
import type { Vec } from "@thi.ng/vectors";
|
|
3
|
+
import type { IShape, SamplingOpts } from "./api.js";
|
|
5
4
|
/**
|
|
6
5
|
* Extracts/samples vertices from given shape's boundary and returns them as
|
|
7
6
|
* array. Some shapes also support
|
|
8
|
-
* [`SamplingOpts`](https://docs.thi.ng/umbrella/geom-
|
|
7
|
+
* [`SamplingOpts`](https://docs.thi.ng/umbrella/geom-resample/interfaces/SamplingOpts.html).
|
|
9
8
|
*
|
|
10
9
|
* @remarks
|
|
11
10
|
* The given sampling options (if any) can also be overridden per shape using
|
|
@@ -21,6 +20,7 @@ import type { Vec } from "@thi.ng/vectors";
|
|
|
21
20
|
* - {@link ComplexPolygon}
|
|
22
21
|
* - {@link Cubic}
|
|
23
22
|
* - {@link Ellipse}
|
|
23
|
+
* - {@link Extra}
|
|
24
24
|
* - {@link Group}
|
|
25
25
|
* - {@link Line}
|
|
26
26
|
* - {@link Path}
|
package/vertices.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { peek } from "@thi.ng/arrays/peek";
|
|
1
2
|
import { isArray } from "@thi.ng/checks/is-array";
|
|
2
3
|
import { isNumber } from "@thi.ng/checks/is-number";
|
|
3
4
|
import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
4
|
-
import { DEFAULT_SAMPLES } from "@thi.ng/geom-api/sample";
|
|
5
5
|
import { sample as _arcVertices } from "@thi.ng/geom-arc/sample";
|
|
6
|
+
import { DEFAULT_SAMPLES } from "@thi.ng/geom-resample/api";
|
|
6
7
|
import { resample } from "@thi.ng/geom-resample/resample";
|
|
7
8
|
import { sampleCubic } from "@thi.ng/geom-splines/cubic-sample";
|
|
8
9
|
import { sampleQuadratic } from "@thi.ng/geom-splines/quadratic-sample";
|
|
@@ -16,15 +17,23 @@ import { ComplexPolygon } from "./api/complex-polygon.js";
|
|
|
16
17
|
import { Polygon } from "./api/polygon.js";
|
|
17
18
|
import { __dispatch } from "./internal/dispatch.js";
|
|
18
19
|
import { __circleOpts, __sampleAttribs } from "./internal/vertices.js";
|
|
19
|
-
import { peek } from "@thi.ng/arrays/peek";
|
|
20
20
|
const vertices = defmulti(
|
|
21
21
|
__dispatch,
|
|
22
22
|
{
|
|
23
|
-
line: "polyline",
|
|
24
23
|
bpatch: "points",
|
|
24
|
+
cubic3: "cubic",
|
|
25
|
+
group3: "group",
|
|
26
|
+
line: "polyline",
|
|
27
|
+
line3: "polyline",
|
|
28
|
+
path3: "path",
|
|
25
29
|
points3: "points",
|
|
30
|
+
poly3: "poly",
|
|
31
|
+
polyline3: "polyline",
|
|
26
32
|
quad: "poly",
|
|
27
|
-
|
|
33
|
+
quad3: "poly",
|
|
34
|
+
quadratic3: "quadratic",
|
|
35
|
+
tri: "poly",
|
|
36
|
+
tri3: "poly"
|
|
28
37
|
},
|
|
29
38
|
{
|
|
30
39
|
// e +----+ h
|
|
@@ -100,6 +109,7 @@ const vertices = defmulti(
|
|
|
100
109
|
}
|
|
101
110
|
return buf;
|
|
102
111
|
},
|
|
112
|
+
extra: () => [],
|
|
103
113
|
group: ($, opts) => {
|
|
104
114
|
opts = __sampleAttribs(opts, $.attribs);
|
|
105
115
|
return $.children.reduce(
|
package/volume.d.ts
CHANGED
package/warp-points.d.ts
CHANGED
|
@@ -1,16 +1,47 @@
|
|
|
1
|
-
import type { IShape } from "@thi.ng/geom-api";
|
|
2
1
|
import type { ReadonlyVec, Vec } from "@thi.ng/vectors/api";
|
|
2
|
+
import type { IShape } from "./api.js";
|
|
3
3
|
import type { BPatch } from "./api/bpatch.js";
|
|
4
4
|
import type { Rect } from "./api/rect.js";
|
|
5
5
|
/**
|
|
6
|
-
* Transfers/remaps
|
|
7
|
-
* be relative to the space of `dest` shape. Writes results to `out` (or
|
|
8
|
-
* new
|
|
6
|
+
* Transfers/remaps point `p` (in world space) given in relation to `src` shape
|
|
7
|
+
* to be relative to the space of `dest` shape. Writes results to `out` (or
|
|
8
|
+
* creates new vector).
|
|
9
9
|
*
|
|
10
10
|
* @remarks
|
|
11
11
|
* The type of `src` must be supported by {@link mapPoint}. The type of `dest`
|
|
12
12
|
* must be supported by {@link unmapPoint}.
|
|
13
13
|
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts tangle:../export/warp-point.ts
|
|
16
|
+
* import { rect, warpPoint } from "@thi.ng/geom";
|
|
17
|
+
*
|
|
18
|
+
* const p = [1075, -1975];
|
|
19
|
+
*
|
|
20
|
+
* // source rect [1000,-2000] .. [1100,-1900]
|
|
21
|
+
* const src = rect([1000,-2000], 100);
|
|
22
|
+
*
|
|
23
|
+
* // destination rect [0,0] .. [0.5,0.5]
|
|
24
|
+
* const dest = rect(0.5);
|
|
25
|
+
*
|
|
26
|
+
* // map `p` into the space of `dest` via `src`
|
|
27
|
+
* console.log(warpPoint(p, dest, src));
|
|
28
|
+
* // [ 0.375, 0.125 ]
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @param p
|
|
32
|
+
* @param dest
|
|
33
|
+
* @param src
|
|
34
|
+
* @param out
|
|
35
|
+
*/
|
|
36
|
+
export declare const warpPoint: (p: ReadonlyVec, dest: IShape, src: IShape, out?: Vec) => Vec;
|
|
37
|
+
/**
|
|
38
|
+
* Array version of {@link warpPoint}, transferring all points in the array from
|
|
39
|
+
* world space to the local space of `dest` via the local space of `src`.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* Note: Different arg orderThe type of `src` must be supported by {@link mapPoint}. The type of `dest`
|
|
43
|
+
* must be supported by {@link unmapPoint}.
|
|
44
|
+
*
|
|
14
45
|
* @param pts
|
|
15
46
|
* @param dest
|
|
16
47
|
* @param src
|
package/warp-points.js
CHANGED
|
@@ -2,6 +2,7 @@ import { bounds2 } from "@thi.ng/geom-poly-utils/bounds";
|
|
|
2
2
|
import { mapPoint } from "./map-point.js";
|
|
3
3
|
import { rectFromMinMax } from "./rect.js";
|
|
4
4
|
import { unmapPoint } from "./unmap-point.js";
|
|
5
|
+
const warpPoint = (p, dest, src, out) => unmapPoint(dest, mapPoint(src, p), out);
|
|
5
6
|
const warpPoints = (pts, dest, src, out = []) => {
|
|
6
7
|
for (let n = pts.length, i = 0; i < n; i++) {
|
|
7
8
|
out.push(unmapPoint(dest, mapPoint(src, pts[i])));
|
|
@@ -16,6 +17,7 @@ const warpPointsBPatch = (pts, dest, src, out = []) => {
|
|
|
16
17
|
return out;
|
|
17
18
|
};
|
|
18
19
|
export {
|
|
20
|
+
warpPoint,
|
|
19
21
|
warpPoints,
|
|
20
22
|
warpPointsBPatch
|
|
21
23
|
};
|