@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
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Vec } from "@thi.ng/vectors";
|
|
2
|
+
import type { Attribs } from "./api.js";
|
|
3
|
+
import { Path } from "./api/path.js";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new 2d rounded rect {@link Path}, using the given corner radius or
|
|
6
|
+
* radii.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* If multiple `radii` are given, the interpretation logic is the same as:
|
|
10
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/roundRect
|
|
11
|
+
*
|
|
12
|
+
* - number: all corners
|
|
13
|
+
* - `[top-left-and-bottom-right, top-right-and-bottom-left]`
|
|
14
|
+
* - `[top-left, top-right-and-bottom-left, bottom-right]`
|
|
15
|
+
* - `[top-left, top-right, bottom-right, bottom-left]`
|
|
16
|
+
*
|
|
17
|
+
* No arc segments will be generated for those corners where the radius <= 0
|
|
18
|
+
*
|
|
19
|
+
* @param pos
|
|
20
|
+
* @param size
|
|
21
|
+
* @param radii
|
|
22
|
+
* @param attribs
|
|
23
|
+
*/
|
|
24
|
+
export declare const roundedRect: (pos: Vec, [w, h]: Vec, radii: number | [number, number] | [number, number, number] | [number, number, number, number], attribs?: Attribs) => Path;
|
|
25
|
+
//# sourceMappingURL=rounded-rect.d.ts.map
|
package/rounded-rect.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isNumber } from "@thi.ng/checks/is-number";
|
|
2
|
+
import { Path } from "./api/path.js";
|
|
3
|
+
import { pathBuilder } from "./path-builder.js";
|
|
4
|
+
const roundedRect = (pos, [w, h], radii, attribs) => {
|
|
5
|
+
const [tl, tr, br, bl] = isNumber(radii) ? [radii, radii, radii, radii] : radii.length === 2 ? [radii[0], radii[1], radii[0], radii[1]] : radii.length === 3 ? [radii[0], radii[1], radii[2], radii[1]] : radii;
|
|
6
|
+
const b = pathBuilder(attribs).moveTo([pos[0] + tl, pos[1]]).hlineTo(w - tl - tr, true);
|
|
7
|
+
if (tr > 0) b.arcTo([tr, tr], [tr, tr], 0, false, true, true);
|
|
8
|
+
b.vlineTo(h - tr - br, true);
|
|
9
|
+
if (br > 0) b.arcTo([-br, br], [br, br], 0, false, true, true);
|
|
10
|
+
b.hlineTo(-(w - br - bl), true);
|
|
11
|
+
if (bl > 0) b.arcTo([-bl, -bl], [bl, bl], 0, false, true, true);
|
|
12
|
+
b.vlineTo(-(h - bl - tl), true);
|
|
13
|
+
if (tl > 0) b.arcTo([tl, -tl], [tl, tl], 0, false, true, true);
|
|
14
|
+
return b.current().close();
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
roundedRect
|
|
18
|
+
};
|
package/scale-with-center.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IShape } from "
|
|
1
|
+
import type { IShape } from "./api.js";
|
|
2
2
|
import type { ReadonlyVec } from "@thi.ng/vectors";
|
|
3
3
|
/**
|
|
4
4
|
* Applies a sequence of translate and scale operations to return an uniformly
|
|
@@ -16,5 +16,5 @@ import type { ReadonlyVec } from "@thi.ng/vectors";
|
|
|
16
16
|
* @param center
|
|
17
17
|
* @param factor
|
|
18
18
|
*/
|
|
19
|
-
export declare const scaleWithCenter: (shape:
|
|
19
|
+
export declare const scaleWithCenter: <T extends IShape>(shape: T, center: ReadonlyVec, factor: number) => T;
|
|
20
20
|
//# sourceMappingURL=scale-with-center.d.ts.map
|
package/scale.d.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
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, IShape2, IShape3 } from "./api.js";
|
|
4
|
+
import { Circle } from "./api/circle.js";
|
|
5
|
+
import { Ellipse } from "./api/ellipse.js";
|
|
6
|
+
/**
|
|
7
|
+
* Function overrides for {@link scale}.
|
|
8
|
+
*/
|
|
9
|
+
export type ScaleFn = {
|
|
10
|
+
(shape: Circle, factor: number): Circle;
|
|
11
|
+
(shape: Circle, factor: ReadonlyVec): Ellipse;
|
|
12
|
+
<T extends IShape2>(shape: T, factor: number | ReadonlyVec): T;
|
|
13
|
+
<T extends IShape3>(shape: T, factor: number | ReadonlyVec): T;
|
|
14
|
+
} & MultiFn2<IShape, number | ReadonlyVec, IShape>;
|
|
4
15
|
/**
|
|
5
16
|
* Scales given shape uniformly or non-uniformly by given `factor`.
|
|
6
17
|
*
|
|
@@ -12,20 +23,31 @@ import type { ReadonlyVec } from "@thi.ng/vectors";
|
|
|
12
23
|
*
|
|
13
24
|
* - {@link AABB}
|
|
14
25
|
* - {@link Arc}
|
|
26
|
+
* - {@link BPatch}
|
|
15
27
|
* - {@link Circle}
|
|
16
28
|
* - {@link ComplexPolygon}
|
|
17
29
|
* - {@link Cubic}
|
|
30
|
+
* - {@link Cubic3}
|
|
18
31
|
* - {@link Ellipse}
|
|
32
|
+
* - {@link Extra} (returns `undefined`)
|
|
19
33
|
* - {@link Group}
|
|
34
|
+
* - {@link Group3}
|
|
20
35
|
* - {@link Line}
|
|
36
|
+
* - {@link Line3}
|
|
21
37
|
* - {@link Path}
|
|
38
|
+
* - {@link Path3}
|
|
22
39
|
* - {@link Points}
|
|
23
40
|
* - {@link Points3}
|
|
24
41
|
* - {@link Polygon}
|
|
42
|
+
* - {@link Polygon3}
|
|
25
43
|
* - {@link Polyline}
|
|
44
|
+
* - {@link Polyline3}
|
|
26
45
|
* - {@link Quad}
|
|
46
|
+
* - {@link Quad3}
|
|
27
47
|
* - {@link Quadratic}
|
|
48
|
+
* - {@link Quadratic3}
|
|
28
49
|
* - {@link Ray}
|
|
50
|
+
* - {@link Ray3}
|
|
29
51
|
* - {@link Rect}
|
|
30
52
|
* - {@link Sphere}
|
|
31
53
|
* - {@link Text}
|
|
@@ -34,5 +56,5 @@ import type { ReadonlyVec } from "@thi.ng/vectors";
|
|
|
34
56
|
* @param shape
|
|
35
57
|
* @param factor
|
|
36
58
|
*/
|
|
37
|
-
export declare const scale:
|
|
59
|
+
export declare const scale: ScaleFn;
|
|
38
60
|
//# sourceMappingURL=scale.d.ts.map
|
package/scale.js
CHANGED
|
@@ -1,41 +1,50 @@
|
|
|
1
1
|
import { isNumber } from "@thi.ng/checks/is-number";
|
|
2
2
|
import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
3
3
|
import { unsupported } from "@thi.ng/errors/unsupported";
|
|
4
|
-
import { mul2, mul3 } from "@thi.ng/vectors/mul";
|
|
4
|
+
import { mul, mul2, mul3 } from "@thi.ng/vectors/mul";
|
|
5
5
|
import { mulN2, mulN3 } from "@thi.ng/vectors/muln";
|
|
6
|
-
import { normalize2 } from "@thi.ng/vectors/normalize";
|
|
6
|
+
import { normalize2, normalize3 } from "@thi.ng/vectors/normalize";
|
|
7
7
|
import { AABB } from "./api/aabb.js";
|
|
8
8
|
import { Circle } from "./api/circle.js";
|
|
9
|
-
import { ComplexPolygon } from "./api/complex-polygon.js";
|
|
10
|
-
import { Cubic } from "./api/cubic.js";
|
|
11
9
|
import { Ellipse } from "./api/ellipse.js";
|
|
12
|
-
import { Line } from "./api/line.js";
|
|
13
|
-
import { Path } from "./api/path.js";
|
|
14
|
-
import { Points, Points3 } from "./api/points.js";
|
|
15
|
-
import { Polygon } from "./api/polygon.js";
|
|
16
|
-
import { Polyline } from "./api/polyline.js";
|
|
17
|
-
import { Quad } from "./api/quad.js";
|
|
18
|
-
import { Quadratic } from "./api/quadratic.js";
|
|
19
10
|
import { Ray } from "./api/ray.js";
|
|
11
|
+
import { Ray3 } from "./api/ray3.js";
|
|
20
12
|
import { Rect } from "./api/rect.js";
|
|
21
13
|
import { Sphere } from "./api/sphere.js";
|
|
22
14
|
import { Text } from "./api/text.js";
|
|
23
|
-
import { Triangle } from "./api/triangle.js";
|
|
24
15
|
import { __asVec } from "./internal/args.js";
|
|
25
16
|
import { __copyAttribs } from "./internal/copy.js";
|
|
26
17
|
import { __dispatch } from "./internal/dispatch.js";
|
|
27
|
-
import { __scaledShape as tx } from "./internal/scale.js";
|
|
28
18
|
import { __segmentTransformer } from "./internal/transform.js";
|
|
29
19
|
const scale = defmulti(
|
|
30
20
|
__dispatch,
|
|
31
|
-
{
|
|
21
|
+
{
|
|
22
|
+
bpatch: "points",
|
|
23
|
+
complexpoly: "group",
|
|
24
|
+
cubic: "points",
|
|
25
|
+
cubic3: "points3",
|
|
26
|
+
group3: "group",
|
|
27
|
+
line: "points",
|
|
28
|
+
line3: "points3",
|
|
29
|
+
path3: "path",
|
|
30
|
+
poly: "points",
|
|
31
|
+
poly3: "points3",
|
|
32
|
+
polyline: "points",
|
|
33
|
+
polyline3: "points3",
|
|
34
|
+
quad: "points",
|
|
35
|
+
quad3: "points3",
|
|
36
|
+
quadratic: "points",
|
|
37
|
+
quadratic3: "points3",
|
|
38
|
+
tri: "points",
|
|
39
|
+
tri3: "points3"
|
|
40
|
+
},
|
|
32
41
|
{
|
|
33
42
|
aabb: ($, delta) => {
|
|
34
43
|
delta = __asVec(delta, 3);
|
|
35
44
|
return new AABB(
|
|
36
45
|
mul3([], $.pos, delta),
|
|
37
46
|
mul3([], $.size, delta),
|
|
38
|
-
__copyAttribs(
|
|
47
|
+
__copyAttribs($.attribs)
|
|
39
48
|
);
|
|
40
49
|
},
|
|
41
50
|
arc: ($, delta) => {
|
|
@@ -48,51 +57,55 @@ const scale = defmulti(
|
|
|
48
57
|
circle: ($, delta) => isNumber(delta) ? new Circle(
|
|
49
58
|
mulN2([], $.pos, delta),
|
|
50
59
|
$.r * delta,
|
|
51
|
-
__copyAttribs(
|
|
60
|
+
__copyAttribs($.attribs)
|
|
52
61
|
) : new Ellipse(
|
|
53
62
|
mul2([], $.pos, delta),
|
|
54
63
|
mulN2([], delta, $.r),
|
|
55
|
-
__copyAttribs(
|
|
56
|
-
),
|
|
57
|
-
complexpoly: ($, delta) => new ComplexPolygon(
|
|
58
|
-
scale($.boundary, delta),
|
|
59
|
-
$.children.map((child) => scale(child, delta))
|
|
64
|
+
__copyAttribs($.attribs)
|
|
60
65
|
),
|
|
61
|
-
cubic: tx(Cubic),
|
|
62
66
|
ellipse: ($, delta) => {
|
|
63
67
|
delta = __asVec(delta);
|
|
64
68
|
return new Ellipse(
|
|
65
69
|
mul2([], $.pos, delta),
|
|
66
70
|
mul2([], $.r, delta),
|
|
67
|
-
__copyAttribs(
|
|
71
|
+
__copyAttribs($.attribs)
|
|
68
72
|
);
|
|
69
73
|
},
|
|
74
|
+
extra: ($) => $,
|
|
70
75
|
group: ($, delta) => $.copyTransformed((x) => scale(x, delta)),
|
|
71
|
-
line: tx(Line),
|
|
72
76
|
path: ($, delta) => {
|
|
73
77
|
delta = __asVec(delta);
|
|
74
|
-
|
|
75
|
-
(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
$scaleSegments($.segments),
|
|
80
|
-
$.subPaths.map($scaleSegments),
|
|
81
|
-
__copyAttribs($)
|
|
78
|
+
return $.copyTransformed(
|
|
79
|
+
__segmentTransformer(
|
|
80
|
+
(geo) => scale(geo, delta),
|
|
81
|
+
(p) => mul([], p, delta)
|
|
82
|
+
)
|
|
82
83
|
);
|
|
83
84
|
},
|
|
84
|
-
points:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
85
|
+
points: ($, delta) => $.copyTransformed(
|
|
86
|
+
(points) => points.map(
|
|
87
|
+
isNumber(delta) ? (x) => mulN2([], x, delta) : (x) => mul2([], x, delta)
|
|
88
|
+
)
|
|
89
|
+
),
|
|
90
|
+
points3: ($, delta) => $.copyTransformed(
|
|
91
|
+
(points) => points.map(
|
|
92
|
+
isNumber(delta) ? (x) => mulN3([], x, delta) : (x) => mul3([], x, delta)
|
|
93
|
+
)
|
|
94
|
+
),
|
|
90
95
|
ray: ($, delta) => {
|
|
91
96
|
delta = __asVec(delta);
|
|
92
97
|
return new Ray(
|
|
93
98
|
mul2([], $.pos, delta),
|
|
94
99
|
normalize2(null, mul2([], $.dir, delta)),
|
|
95
|
-
__copyAttribs(
|
|
100
|
+
__copyAttribs($.attribs)
|
|
101
|
+
);
|
|
102
|
+
},
|
|
103
|
+
ray3: ($, delta) => {
|
|
104
|
+
delta = __asVec(delta);
|
|
105
|
+
return new Ray3(
|
|
106
|
+
mul3([], $.pos, delta),
|
|
107
|
+
normalize3(null, mul3([], $.dir, delta)),
|
|
108
|
+
__copyAttribs($.attribs)
|
|
96
109
|
);
|
|
97
110
|
},
|
|
98
111
|
rect: ($, delta) => {
|
|
@@ -100,16 +113,19 @@ const scale = defmulti(
|
|
|
100
113
|
return new Rect(
|
|
101
114
|
mul2([], $.pos, delta),
|
|
102
115
|
mul2([], $.size, delta),
|
|
103
|
-
__copyAttribs(
|
|
116
|
+
__copyAttribs($.attribs)
|
|
104
117
|
);
|
|
105
118
|
},
|
|
106
119
|
sphere: ($, delta) => isNumber(delta) ? new Sphere(
|
|
107
120
|
mulN3([], $.pos, delta),
|
|
108
121
|
$.r * delta,
|
|
109
|
-
__copyAttribs(
|
|
122
|
+
__copyAttribs($.attribs)
|
|
110
123
|
) : unsupported("can't non-uniformly scale sphere"),
|
|
111
|
-
text: ($, delta) => new Text(
|
|
112
|
-
|
|
124
|
+
text: ($, delta) => new Text(
|
|
125
|
+
mul2([], $.pos, __asVec(delta)),
|
|
126
|
+
$.body,
|
|
127
|
+
__copyAttribs($.attribs)
|
|
128
|
+
)
|
|
113
129
|
}
|
|
114
130
|
);
|
|
115
131
|
export {
|
package/scatter.d.ts
CHANGED
package/simplify.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { MultiFn1O } from "@thi.ng/defmulti";
|
|
2
|
-
import type { IShape } from "
|
|
2
|
+
import type { IShape, IShape2 } from "./api.js";
|
|
3
|
+
/**
|
|
4
|
+
* Function overrides for {@link simplify}.
|
|
5
|
+
*/
|
|
6
|
+
export type SimplifyFn = {
|
|
7
|
+
<T extends IShape2>(shape: IShape2, eps?: number): T;
|
|
8
|
+
} & MultiFn1O<IShape, number, IShape>;
|
|
3
9
|
/**
|
|
4
10
|
* Simplifies given 2D shape boundary using Douglas-Peucker algorithm
|
|
5
11
|
* (implemented by
|
|
@@ -21,5 +27,5 @@ import type { IShape } from "@thi.ng/geom-api";
|
|
|
21
27
|
* @param shape
|
|
22
28
|
* @param threshold
|
|
23
29
|
*/
|
|
24
|
-
export declare const simplify:
|
|
30
|
+
export declare const simplify: SimplifyFn;
|
|
25
31
|
//# sourceMappingURL=simplify.d.ts.map
|
package/simplify.js
CHANGED
|
@@ -15,7 +15,7 @@ const simplify = defmulti(
|
|
|
15
15
|
complexpoly: ($, eps) => new ComplexPolygon(
|
|
16
16
|
simplify($.boundary, eps),
|
|
17
17
|
$.children.map((child) => simplify(child, eps)),
|
|
18
|
-
__copyAttribs(
|
|
18
|
+
__copyAttribs($.attribs)
|
|
19
19
|
),
|
|
20
20
|
path: ($, eps = 1e-6) => {
|
|
21
21
|
const $simplifySegments = (segments) => {
|
|
@@ -51,11 +51,14 @@ const simplify = defmulti(
|
|
|
51
51
|
return new Path(
|
|
52
52
|
$simplifySegments($.segments),
|
|
53
53
|
$.subPaths.map($simplifySegments),
|
|
54
|
-
__copyAttribs(
|
|
54
|
+
__copyAttribs($.attribs)
|
|
55
55
|
);
|
|
56
56
|
},
|
|
57
|
-
poly: ($, eps = 1e-6) => new Polygon(
|
|
58
|
-
|
|
57
|
+
poly: ($, eps = 1e-6) => new Polygon(
|
|
58
|
+
_simplify($.points, eps, true),
|
|
59
|
+
__copyAttribs($.attribs)
|
|
60
|
+
),
|
|
61
|
+
polyline: ($, eps = 1e-6) => new Polyline(_simplify($.points, eps), __copyAttribs($.attribs))
|
|
59
62
|
}
|
|
60
63
|
);
|
|
61
64
|
export {
|
package/smooth-poly.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ReadonlyVec } from "@thi.ng/vectors";
|
|
2
|
+
import type { Attribs, CubicOpts, SamplingOpts } from "./api.js";
|
|
3
|
+
import { Polygon } from "./api/polygon.js";
|
|
4
|
+
import { Polyline } from "./api/polyline.js";
|
|
5
|
+
import { type AsPathOpts } from "./as-path.js";
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new polygon from given initial `points` and optional `attribs`. The
|
|
8
|
+
* polygon is then first converted into a cubic path using `pathOpts` and then
|
|
9
|
+
* back into a polygon by sampling the path using `polyOpts`. Returns that final
|
|
10
|
+
* polygon result.
|
|
11
|
+
*
|
|
12
|
+
* @param points
|
|
13
|
+
* @param attribs
|
|
14
|
+
* @param pathOpts
|
|
15
|
+
* @param polyOpts
|
|
16
|
+
*/
|
|
17
|
+
export declare const smoothPolygon: (points: ReadonlyVec[], attribs?: Attribs, pathOpts?: Partial<CubicOpts>, polyOpts?: Partial<SamplingOpts>) => Polygon;
|
|
18
|
+
/**
|
|
19
|
+
* Like {@link smoothPolygon}, but for polylines.
|
|
20
|
+
*
|
|
21
|
+
* @param points
|
|
22
|
+
* @param attribs
|
|
23
|
+
* @param pathOpts
|
|
24
|
+
* @param polyOpts
|
|
25
|
+
*/
|
|
26
|
+
export declare const smoothPolyline: (points: ReadonlyVec[], attribs?: Attribs, pathOpts?: Partial<AsPathOpts>, polyOpts?: Partial<SamplingOpts>) => Polyline;
|
|
27
|
+
//# sourceMappingURL=smooth-poly.d.ts.map
|
package/smooth-poly.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Polygon } from "./api/polygon.js";
|
|
2
|
+
import { Polyline } from "./api/polyline.js";
|
|
3
|
+
import { asPath } from "./as-path.js";
|
|
4
|
+
import { asPolygon } from "./as-polygon.js";
|
|
5
|
+
import { asPolyline } from "./as-polyline.js";
|
|
6
|
+
const smoothPolygon = (points, attribs, pathOpts, polyOpts) => asPolygon(asPath(new Polygon(points, attribs), pathOpts), polyOpts)[0];
|
|
7
|
+
const smoothPolyline = (points, attribs, pathOpts, polyOpts) => asPolyline(asPath(new Polyline(points, attribs), pathOpts), polyOpts)[0];
|
|
8
|
+
export {
|
|
9
|
+
smoothPolygon,
|
|
10
|
+
smoothPolyline
|
|
11
|
+
};
|
package/sphere.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Attribs } from "
|
|
1
|
+
import type { Attribs } from "./api.js";
|
|
2
2
|
import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
|
|
3
3
|
import { Sphere } from "./api/sphere.js";
|
|
4
4
|
export declare function sphere(pos: Vec, r: number, attribs?: Attribs): Sphere;
|
package/split-arclength.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { MultiFn2 } from "@thi.ng/defmulti";
|
|
2
|
-
import type { IShape } from "
|
|
2
|
+
import type { IShape } from "./api.js";
|
|
3
3
|
import { Group } from "./api/group.js";
|
|
4
|
+
/**
|
|
5
|
+
* Function overrides for {@link splitArcLength}.
|
|
6
|
+
*/
|
|
7
|
+
export type SplitArcLengthFn = {} & MultiFn2<IShape, number, Group>;
|
|
4
8
|
/**
|
|
5
9
|
* Splits given shape into {@link Polyline} segments of given (max) arc length.
|
|
6
10
|
* Returns a {@link Group} of shapes/polylines.
|
|
@@ -66,5 +70,5 @@ import { Group } from "./api/group.js";
|
|
|
66
70
|
* @param shape
|
|
67
71
|
* @param dist
|
|
68
72
|
*/
|
|
69
|
-
export declare const splitArcLength:
|
|
73
|
+
export declare const splitArcLength: SplitArcLengthFn;
|
|
70
74
|
//# sourceMappingURL=split-arclength.d.ts.map
|
package/split-at.d.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import type { Maybe } from "@thi.ng/api";
|
|
2
2
|
import type { MultiFn2 } from "@thi.ng/defmulti";
|
|
3
|
-
import type { IShape } from "
|
|
3
|
+
import type { IShape, IShape2, IShape3 } from "./api.js";
|
|
4
|
+
import { Arc } from "./api/arc.js";
|
|
5
|
+
import type { Circle } from "./api/circle.js";
|
|
6
|
+
/**
|
|
7
|
+
* Function overrides for {@link splitAt}.
|
|
8
|
+
*/
|
|
9
|
+
export type SplitAtFn = {
|
|
10
|
+
(shape: Arc, t: number): [Arc, Arc];
|
|
11
|
+
(shape: Circle, t: number): [Arc, Arc];
|
|
12
|
+
<T extends IShape2>(shape: T, t: number): T[];
|
|
13
|
+
<T extends IShape3>(shape: T, t: number): T[];
|
|
14
|
+
} & MultiFn2<IShape, number, Maybe<IShape[]>>;
|
|
4
15
|
/**
|
|
5
16
|
* Splits given shape in 2 parts at normalized parametric position `t`.
|
|
6
17
|
*
|
|
@@ -8,13 +19,18 @@ import type { IShape } from "@thi.ng/geom-api";
|
|
|
8
19
|
* Currently only implemented for:
|
|
9
20
|
*
|
|
10
21
|
* - {@link Arc}
|
|
22
|
+
* - {@link Circle}
|
|
11
23
|
* - {@link Cubic}
|
|
24
|
+
* - {@link Cubic3}
|
|
12
25
|
* - {@link Line}
|
|
26
|
+
* - {@link Line3}
|
|
13
27
|
* - {@link Polyline}
|
|
28
|
+
* - {@link Polyline3}
|
|
14
29
|
* - {@link Quadratic}
|
|
30
|
+
* - {@link Quadratic3}
|
|
15
31
|
*
|
|
16
32
|
* @param shape
|
|
17
33
|
* @param t
|
|
18
34
|
*/
|
|
19
|
-
export declare const splitAt:
|
|
35
|
+
export declare const splitAt: SplitAtFn;
|
|
20
36
|
//# sourceMappingURL=split-at.d.ts.map
|
package/split-at.js
CHANGED
|
@@ -2,59 +2,91 @@ import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
|
2
2
|
import { Sampler } from "@thi.ng/geom-resample/sampler";
|
|
3
3
|
import { cubicSplitAt } from "@thi.ng/geom-splines/cubic-split";
|
|
4
4
|
import { quadraticSplitAt } from "@thi.ng/geom-splines/quadratic-split";
|
|
5
|
+
import { absDiff } from "@thi.ng/math/abs";
|
|
6
|
+
import { PI, TAU } from "@thi.ng/math/api";
|
|
5
7
|
import { fit01 } from "@thi.ng/math/fit";
|
|
6
|
-
import {
|
|
8
|
+
import { set2 } from "@thi.ng/vectors/set";
|
|
7
9
|
import { Arc } from "./api/arc.js";
|
|
8
|
-
import { Cubic } from "./api/cubic.js";
|
|
9
|
-
import { Line } from "./api/line.js";
|
|
10
|
-
import { Polyline } from "./api/polyline.js";
|
|
11
|
-
import { Quadratic } from "./api/quadratic.js";
|
|
12
10
|
import { __copyAttribs } from "./internal/copy.js";
|
|
13
11
|
import { __dispatch } from "./internal/dispatch.js";
|
|
14
12
|
import { __pointArraysAsShapes } from "./internal/points-as-shape.js";
|
|
15
|
-
import {
|
|
13
|
+
import { __splitLineAt } from "./internal/split.js";
|
|
16
14
|
const splitAt = defmulti(
|
|
17
15
|
__dispatch,
|
|
18
|
-
{},
|
|
19
16
|
{
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
cubic3: "cubic",
|
|
18
|
+
line3: "line",
|
|
19
|
+
polyline3: "polyline",
|
|
20
|
+
quadratic3: "quadratic"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
arc: ({ pos, r, start, end, axis, cw, attribs }, t) => {
|
|
24
|
+
const theta = fit01(t, start, end);
|
|
22
25
|
return [
|
|
23
26
|
new Arc(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
set2([], pos),
|
|
28
|
+
set2([], r),
|
|
29
|
+
axis,
|
|
30
|
+
start,
|
|
28
31
|
theta,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
__copyAttribs(
|
|
32
|
+
absDiff(start, theta) >= PI,
|
|
33
|
+
cw,
|
|
34
|
+
__copyAttribs(attribs)
|
|
32
35
|
),
|
|
33
36
|
new Arc(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
set2([], pos),
|
|
38
|
+
set2([], r),
|
|
39
|
+
axis,
|
|
37
40
|
theta,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
__copyAttribs(
|
|
41
|
+
end,
|
|
42
|
+
absDiff(theta, end) >= PI,
|
|
43
|
+
cw,
|
|
44
|
+
__copyAttribs(attribs)
|
|
42
45
|
)
|
|
43
46
|
];
|
|
44
47
|
},
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
circle: ({ pos, r, attribs }, t) => {
|
|
49
|
+
const theta = t * TAU;
|
|
50
|
+
return [
|
|
51
|
+
new Arc(
|
|
52
|
+
set2([], pos),
|
|
53
|
+
[r, r],
|
|
54
|
+
0,
|
|
55
|
+
0,
|
|
56
|
+
theta,
|
|
57
|
+
t >= 0.5,
|
|
58
|
+
true,
|
|
59
|
+
__copyAttribs(attribs)
|
|
60
|
+
),
|
|
61
|
+
new Arc(
|
|
62
|
+
set2([], pos),
|
|
63
|
+
[r, r],
|
|
64
|
+
0,
|
|
65
|
+
theta,
|
|
66
|
+
TAU,
|
|
67
|
+
t < 0.5,
|
|
68
|
+
true,
|
|
69
|
+
__copyAttribs(attribs)
|
|
70
|
+
)
|
|
71
|
+
];
|
|
72
|
+
},
|
|
73
|
+
cubic: ({ attribs, points: [a, b, c, d], constructor: ctor }, t) => __pointArraysAsShapes(
|
|
74
|
+
ctor,
|
|
75
|
+
cubicSplitAt(a, b, c, d, t),
|
|
76
|
+
attribs,
|
|
77
|
+
false
|
|
50
78
|
),
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
79
|
+
line: __splitLineAt,
|
|
80
|
+
polyline: ({ attribs, points, constructor: ctor }, t) => __pointArraysAsShapes(
|
|
81
|
+
ctor,
|
|
82
|
+
new Sampler(points).splitAt(t),
|
|
83
|
+
attribs
|
|
55
84
|
),
|
|
56
|
-
quadratic: ({ attribs, points
|
|
57
|
-
|
|
85
|
+
quadratic: ({ attribs, points: [a, b, c], constructor: ctor }, t) => __pointArraysAsShapes(
|
|
86
|
+
ctor,
|
|
87
|
+
quadraticSplitAt(a, b, c, t),
|
|
88
|
+
attribs,
|
|
89
|
+
false
|
|
58
90
|
)
|
|
59
91
|
}
|
|
60
92
|
);
|
package/split-near.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import type { Maybe } from "@thi.ng/api";
|
|
2
2
|
import type { MultiFn2 } from "@thi.ng/defmulti";
|
|
3
|
-
import type { IShape } from "@thi.ng/geom-api";
|
|
4
3
|
import type { ReadonlyVec } from "@thi.ng/vectors";
|
|
4
|
+
import type { IShape, IShape2, IShape3 } from "./api.js";
|
|
5
|
+
/**
|
|
6
|
+
* Function overrides for {@link splitNearPoint}.
|
|
7
|
+
*/
|
|
8
|
+
export type SplitNearPointFn = {
|
|
9
|
+
<T extends IShape2>(shape: T, p: ReadonlyVec): T[];
|
|
10
|
+
<T extends IShape3>(shape: T, p: ReadonlyVec): T[];
|
|
11
|
+
} & MultiFn2<IShape, ReadonlyVec, Maybe<IShape[]>>;
|
|
5
12
|
/**
|
|
6
13
|
* Similar to {@link splitAt}, but instead of taking a normalized parametric
|
|
7
14
|
* split position, splits the given curve at the closest point to `p`.
|
|
@@ -10,12 +17,16 @@ import type { ReadonlyVec } from "@thi.ng/vectors";
|
|
|
10
17
|
* Currently only implemented for:
|
|
11
18
|
*
|
|
12
19
|
* - {@link Cubic}
|
|
20
|
+
* - {@link Cubic3}
|
|
13
21
|
* - {@link Line}
|
|
22
|
+
* - {@link Line3}
|
|
14
23
|
* - {@link Polyline}
|
|
24
|
+
* - {@link Polyline3}
|
|
15
25
|
* - {@link Quadratic}
|
|
26
|
+
* - {@link Quadratic3}
|
|
16
27
|
*
|
|
17
28
|
* @param shape - shape to operate on
|
|
18
29
|
* @param p - split point
|
|
19
30
|
*/
|
|
20
|
-
export declare const splitNearPoint:
|
|
31
|
+
export declare const splitNearPoint: SplitNearPointFn;
|
|
21
32
|
//# sourceMappingURL=split-near.d.ts.map
|