@thi.ng/geom 3.2.6 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -1
- package/README.md +52 -5
- package/aabb.d.ts +3 -0
- package/aabb.js +4 -0
- package/api/aabb.d.ts +3 -1
- package/api/aabb.js +16 -4
- package/api/apc.d.ts +3 -2
- package/api/arc.d.ts +1 -0
- package/api/arc.js +3 -0
- package/api/bpatch.d.ts +3 -2
- package/api/bpatch.js +3 -0
- package/api/circle.d.ts +1 -0
- package/api/circle.js +3 -0
- package/api/cubic.d.ts +3 -2
- package/api/cubic.js +3 -0
- package/api/ellipse.d.ts +1 -0
- package/api/ellipse.js +5 -2
- package/api/group.d.ts +1 -0
- package/api/group.js +3 -0
- package/api/line.d.ts +3 -2
- package/api/line.js +3 -0
- package/api/path.d.ts +1 -0
- package/api/path.js +5 -0
- package/api/plane.d.ts +1 -0
- package/api/plane.js +5 -2
- package/api/points.d.ts +5 -3
- package/api/points.js +6 -0
- package/api/polygon.d.ts +3 -2
- package/api/polygon.js +3 -0
- package/api/polyline.d.ts +2 -1
- package/api/polyline.js +3 -0
- package/api/quad.d.ts +3 -2
- package/api/quad.js +3 -0
- package/api/quad3.d.ts +3 -2
- package/api/quad3.js +3 -0
- package/api/quadratic.d.ts +3 -2
- package/api/quadratic.js +3 -0
- package/api/ray.d.ts +1 -0
- package/api/ray.js +3 -0
- package/api/rect.d.ts +3 -1
- package/api/rect.js +14 -2
- package/api/sphere.d.ts +1 -0
- package/api/sphere.js +3 -0
- package/api/text.d.ts +1 -0
- package/api/text.js +3 -0
- package/api/triangle.d.ts +3 -2
- package/api/triangle.js +3 -0
- package/apply-transforms.d.ts +33 -0
- package/apply-transforms.js +59 -0
- package/arc-length.d.ts +10 -9
- package/arc-length.js +11 -10
- package/area.d.ts +24 -23
- package/area.js +26 -23
- package/as-cubic.d.ts +36 -0
- package/as-cubic.js +45 -4
- package/as-path.d.ts +7 -0
- package/as-path.js +7 -0
- package/as-polygon.d.ts +20 -0
- package/as-polygon.js +20 -0
- package/as-polyline.d.ts +23 -0
- package/as-polyline.js +23 -0
- package/bounds.d.ts +30 -2
- package/bounds.js +50 -17
- package/center.d.ts +11 -0
- package/center.js +11 -0
- package/centroid.d.ts +27 -0
- package/centroid.js +32 -4
- package/classify-point.d.ts +23 -0
- package/classify-point.js +23 -0
- package/clip-convex.d.ts +13 -0
- package/clip-convex.js +16 -1
- package/closest-point.d.ts +26 -0
- package/closest-point.js +27 -0
- package/convex-hull.d.ts +21 -0
- package/convex-hull.js +27 -2
- package/edges.d.ts +26 -0
- package/edges.js +35 -0
- package/fit-into-bounds.d.ts +22 -3
- package/fit-into-bounds.js +25 -5
- package/flip.d.ts +23 -0
- package/flip.js +23 -0
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/internal/args.d.ts +2 -0
- package/internal/args.js +2 -0
- package/internal/bounds.d.ts +4 -4
- package/internal/bounds.js +4 -4
- package/internal/copy.d.ts +3 -1
- package/internal/copy.js +3 -0
- package/internal/dispatch.d.ts +2 -0
- package/internal/dispatch.js +2 -0
- package/internal/rotate.d.ts +5 -0
- package/internal/rotate.js +4 -0
- package/internal/scale.d.ts +5 -0
- package/internal/scale.js +6 -0
- package/intersects.d.ts +27 -2
- package/intersects.js +31 -1
- package/map-point.d.ts +15 -0
- package/map-point.js +15 -0
- package/offset.d.ts +17 -0
- package/offset.js +21 -5
- package/package.json +31 -13
- package/point-at.d.ts +25 -0
- package/point-at.js +25 -0
- package/point-inside.d.ts +19 -0
- package/point-inside.js +19 -0
- package/rect.d.ts +3 -1
- package/rect.js +7 -2
- package/resample.d.ts +19 -0
- package/resample.js +19 -0
- package/rotate.d.ts +30 -0
- package/rotate.js +79 -0
- package/scale.d.ts +37 -0
- package/scale.js +112 -0
- package/scatter.d.ts +13 -0
- package/scatter.js +13 -0
- package/simplify.d.ts +18 -0
- package/simplify.js +21 -3
- package/split-at.d.ts +15 -0
- package/split-at.js +15 -0
- package/split-near.d.ts +6 -6
- package/split-near.js +6 -6
- package/subdiv-curve.d.ts +17 -0
- package/subdiv-curve.js +17 -0
- package/tangent-at.d.ts +19 -0
- package/tangent-at.js +19 -0
- package/tessellate.d.ts +12 -1
- package/tessellate.js +11 -0
- package/transform-vertices.d.ts +35 -10
- package/transform-vertices.js +35 -10
- package/transform.d.ts +34 -8
- package/transform.js +36 -10
- package/translate.d.ts +29 -0
- package/translate.js +29 -0
- package/union.d.ts +10 -0
- package/union.js +10 -0
- package/unmap-point.d.ts +10 -7
- package/unmap-point.js +10 -7
- package/vertices.d.ts +29 -2
- package/vertices.js +33 -5
- package/volume.d.ts +5 -2
- package/volume.js +5 -2
- package/warp-points.d.ts +15 -1
- package/warp-points.js +17 -4
- package/with-attribs.d.ts +10 -1
- package/with-attribs.js +10 -4
package/point-inside.js
CHANGED
|
@@ -2,6 +2,25 @@ import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
|
2
2
|
import { pointInAABB, pointInCircle, pointInPolygon2, pointInRect, pointInSegment, pointInTriangle2, } from "@thi.ng/geom-isec/point";
|
|
3
3
|
import { isInArray } from "@thi.ng/vectors/eqdelta";
|
|
4
4
|
import { __dispatch } from "./internal/dispatch.js";
|
|
5
|
+
/**
|
|
6
|
+
* Returns true if point `p` is inside the given shape.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Currently implemented for:
|
|
10
|
+
*
|
|
11
|
+
* - AABB
|
|
12
|
+
* - Circle
|
|
13
|
+
* - Points (i.e. if `p` is one of the points in the cloud)
|
|
14
|
+
* - Points3 (same as w/ Points)
|
|
15
|
+
* - Polygon
|
|
16
|
+
* - Quad
|
|
17
|
+
* - Rect
|
|
18
|
+
* - Sphere
|
|
19
|
+
* - Triangle
|
|
20
|
+
*
|
|
21
|
+
* @param shape
|
|
22
|
+
* @param p
|
|
23
|
+
*/
|
|
5
24
|
export const pointInside = defmulti(__dispatch, {
|
|
6
25
|
points3: "points",
|
|
7
26
|
quad: "poly",
|
package/rect.d.ts
CHANGED
|
@@ -7,7 +7,9 @@ export declare function rect(pos: Vec, size: number | Vec, attribs?: Attribs): R
|
|
|
7
7
|
export declare function rect(size: number | Vec, attribs?: Attribs): Rect;
|
|
8
8
|
export declare function rect(attribs?: Attribs): Rect;
|
|
9
9
|
export declare const rectFromMinMax: (min: Vec, max: Vec, attribs?: Attribs) => Rect;
|
|
10
|
-
export declare const
|
|
10
|
+
export declare const rectFromMinMaxWithMargin: (min: Vec, max: Vec, margin: number, attribs?: Attribs) => Rect;
|
|
11
|
+
export declare const rectFromCentroid: (centroid: Vec, size: number | Vec, attribs?: Attribs) => Rect;
|
|
12
|
+
export declare const rectFromCentroidWithMargin: (centroid: Vec, size: number | Vec, margin: number, attribs?: Attribs) => Rect;
|
|
11
13
|
/**
|
|
12
14
|
* Returns the intersection rect of given inputs or `undefined` if they
|
|
13
15
|
* are non-overlapping.
|
package/rect.js
CHANGED
|
@@ -9,12 +9,17 @@ import { min2 } from "@thi.ng/vectors/min";
|
|
|
9
9
|
import { sub2 } from "@thi.ng/vectors/sub";
|
|
10
10
|
import { subN2 } from "@thi.ng/vectors/subn";
|
|
11
11
|
import { Rect } from "./api/rect.js";
|
|
12
|
-
import { __argsVV } from "./internal/args.js";
|
|
12
|
+
import { __argsVV, __asVec } from "./internal/args.js";
|
|
13
13
|
export function rect(...args) {
|
|
14
14
|
return new Rect(...__argsVV(args));
|
|
15
15
|
}
|
|
16
16
|
export const rectFromMinMax = (min, max, attribs) => new Rect(min, sub2([], max, min), attribs);
|
|
17
|
-
export const
|
|
17
|
+
export const rectFromMinMaxWithMargin = (min, max, margin, attribs) => rectFromMinMax(min, max, attribs).offset(margin);
|
|
18
|
+
export const rectFromCentroid = (centroid, size, attribs) => {
|
|
19
|
+
size = __asVec(size);
|
|
20
|
+
return new Rect(maddN2([], size, -0.5, centroid), size, attribs);
|
|
21
|
+
};
|
|
22
|
+
export const rectFromCentroidWithMargin = (centroid, size, margin, attribs) => rectFromCentroid(centroid, size, attribs).offset(margin);
|
|
18
23
|
/**
|
|
19
24
|
* Returns the intersection rect of given inputs or `undefined` if they
|
|
20
25
|
* are non-overlapping.
|
package/resample.d.ts
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
import type { MultiFn2 } from "@thi.ng/defmulti";
|
|
2
2
|
import type { IShape, SamplingOpts } from "@thi.ng/geom-api";
|
|
3
|
+
/**
|
|
4
|
+
* Resamples given 2D shape with given options and returns result as polygon (if
|
|
5
|
+
* closed) or polyline (if open).
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Currently implemented for:
|
|
9
|
+
*
|
|
10
|
+
* - {@link Circle}
|
|
11
|
+
* - {@link Ellipse}
|
|
12
|
+
* - {@link Line}
|
|
13
|
+
* - {@link Polygon}
|
|
14
|
+
* - {@link Polyline}
|
|
15
|
+
* - {@link Quad}
|
|
16
|
+
* - {@link Rect}
|
|
17
|
+
* - {@link Triangle}
|
|
18
|
+
*
|
|
19
|
+
* @param shape
|
|
20
|
+
* @param opts
|
|
21
|
+
*/
|
|
3
22
|
export declare const resample: MultiFn2<IShape, number | Partial<SamplingOpts>, IShape>;
|
|
4
23
|
//# sourceMappingURL=resample.d.ts.map
|
package/resample.js
CHANGED
|
@@ -5,6 +5,25 @@ import { Polyline } from "./api/polyline.js";
|
|
|
5
5
|
import { asPolygon } from "./as-polygon.js";
|
|
6
6
|
import { __copyAttribs } from "./internal/copy.js";
|
|
7
7
|
import { __dispatch } from "./internal/dispatch.js";
|
|
8
|
+
/**
|
|
9
|
+
* Resamples given 2D shape with given options and returns result as polygon (if
|
|
10
|
+
* closed) or polyline (if open).
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* Currently implemented for:
|
|
14
|
+
*
|
|
15
|
+
* - {@link Circle}
|
|
16
|
+
* - {@link Ellipse}
|
|
17
|
+
* - {@link Line}
|
|
18
|
+
* - {@link Polygon}
|
|
19
|
+
* - {@link Polyline}
|
|
20
|
+
* - {@link Quad}
|
|
21
|
+
* - {@link Rect}
|
|
22
|
+
* - {@link Triangle}
|
|
23
|
+
*
|
|
24
|
+
* @param shape
|
|
25
|
+
* @param opts
|
|
26
|
+
*/
|
|
8
27
|
export const resample = defmulti(__dispatch, {
|
|
9
28
|
ellipse: "circle",
|
|
10
29
|
line: "polyline",
|
package/rotate.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { MultiFn2 } from "@thi.ng/defmulti";
|
|
2
|
+
import type { IShape } from "@thi.ng/geom-api";
|
|
3
|
+
/**
|
|
4
|
+
* Rotates given 2D shape by `theta` (in radians).
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Currently implemented for:
|
|
8
|
+
*
|
|
9
|
+
* - {@link Arc}
|
|
10
|
+
* - {@link Circle}
|
|
11
|
+
* - {@link Cubic}
|
|
12
|
+
* - {@link Ellipse}
|
|
13
|
+
* - {@link Group}
|
|
14
|
+
* - {@link Line}
|
|
15
|
+
* - {@link Path}
|
|
16
|
+
* - {@link Points}
|
|
17
|
+
* - {@link Polygon}
|
|
18
|
+
* - {@link Polyline}
|
|
19
|
+
* - {@link Quad}
|
|
20
|
+
* - {@link Quadratic}
|
|
21
|
+
* - {@link Ray}
|
|
22
|
+
* - {@link Rect}
|
|
23
|
+
* - {@link Text}
|
|
24
|
+
* - {@link Triangle}
|
|
25
|
+
*
|
|
26
|
+
* @param shape
|
|
27
|
+
* @param theta
|
|
28
|
+
*/
|
|
29
|
+
export declare const rotate: MultiFn2<IShape, number, IShape>;
|
|
30
|
+
//# sourceMappingURL=rotate.d.ts.map
|
package/rotate.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
2
|
+
import { rotate as $rotate } from "@thi.ng/vectors/rotate";
|
|
3
|
+
import { Circle } from "./api/circle.js";
|
|
4
|
+
import { Cubic } from "./api/cubic.js";
|
|
5
|
+
import { Line } from "./api/line.js";
|
|
6
|
+
import { Path } from "./api/path.js";
|
|
7
|
+
import { Points } from "./api/points.js";
|
|
8
|
+
import { Polygon } from "./api/polygon.js";
|
|
9
|
+
import { Polyline } from "./api/polyline.js";
|
|
10
|
+
import { Quad } from "./api/quad.js";
|
|
11
|
+
import { Quadratic } from "./api/quadratic.js";
|
|
12
|
+
import { Ray } from "./api/ray.js";
|
|
13
|
+
import { Text } from "./api/text.js";
|
|
14
|
+
import { Triangle } from "./api/triangle.js";
|
|
15
|
+
import { asPath } from "./as-path.js";
|
|
16
|
+
import { asPolygon } from "./as-polygon.js";
|
|
17
|
+
import { __copyAttribs } from "./internal/copy.js";
|
|
18
|
+
import { __dispatch } from "./internal/dispatch.js";
|
|
19
|
+
import { __rotatedShape as tx } from "./internal/rotate.js";
|
|
20
|
+
/**
|
|
21
|
+
* Rotates given 2D shape by `theta` (in radians).
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* Currently implemented for:
|
|
25
|
+
*
|
|
26
|
+
* - {@link Arc}
|
|
27
|
+
* - {@link Circle}
|
|
28
|
+
* - {@link Cubic}
|
|
29
|
+
* - {@link Ellipse}
|
|
30
|
+
* - {@link Group}
|
|
31
|
+
* - {@link Line}
|
|
32
|
+
* - {@link Path}
|
|
33
|
+
* - {@link Points}
|
|
34
|
+
* - {@link Polygon}
|
|
35
|
+
* - {@link Polyline}
|
|
36
|
+
* - {@link Quad}
|
|
37
|
+
* - {@link Quadratic}
|
|
38
|
+
* - {@link Ray}
|
|
39
|
+
* - {@link Rect}
|
|
40
|
+
* - {@link Text}
|
|
41
|
+
* - {@link Triangle}
|
|
42
|
+
*
|
|
43
|
+
* @param shape
|
|
44
|
+
* @param theta
|
|
45
|
+
*/
|
|
46
|
+
export const rotate = defmulti(__dispatch, {}, {
|
|
47
|
+
arc: ($, theta) => {
|
|
48
|
+
const a = $.copy();
|
|
49
|
+
$rotate(null, a.pos, theta);
|
|
50
|
+
return a;
|
|
51
|
+
},
|
|
52
|
+
circle: ($, theta) => new Circle($rotate([], $.pos, theta), $.r, __copyAttribs($)),
|
|
53
|
+
cubic: tx(Cubic),
|
|
54
|
+
ellipse: ($, theta) => rotate(asPath($), theta),
|
|
55
|
+
group: ($, theta) => $.copyTransformed((x) => rotate(x, theta)),
|
|
56
|
+
line: tx(Line),
|
|
57
|
+
path: ($, theta) => {
|
|
58
|
+
return new Path($.segments.map((s) => s.geo
|
|
59
|
+
? {
|
|
60
|
+
type: s.type,
|
|
61
|
+
geo: rotate(s.geo, theta),
|
|
62
|
+
}
|
|
63
|
+
: {
|
|
64
|
+
type: s.type,
|
|
65
|
+
point: $rotate([], s.point, theta),
|
|
66
|
+
}), __copyAttribs($));
|
|
67
|
+
},
|
|
68
|
+
points: tx(Points),
|
|
69
|
+
poly: tx(Polygon),
|
|
70
|
+
polyline: tx(Polyline),
|
|
71
|
+
quad: tx(Quad),
|
|
72
|
+
quadratic: tx(Quadratic),
|
|
73
|
+
ray: ($, theta) => {
|
|
74
|
+
return new Ray($rotate([], $.pos, theta), $rotate([], $.dir, theta), __copyAttribs($));
|
|
75
|
+
},
|
|
76
|
+
rect: ($, theta) => rotate(asPolygon($), theta),
|
|
77
|
+
text: ($, theta) => new Text($rotate([], $.pos, theta), $.body, __copyAttribs($)),
|
|
78
|
+
tri: tx(Triangle),
|
|
79
|
+
});
|
package/scale.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { MultiFn2 } from "@thi.ng/defmulti";
|
|
2
|
+
import type { IShape } from "@thi.ng/geom-api";
|
|
3
|
+
import type { ReadonlyVec } from "@thi.ng/vectors";
|
|
4
|
+
/**
|
|
5
|
+
* Scales given shape uniformly or non-uniformly by given `factor`.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Scaling non-uniformly might result in different result types, e.g.
|
|
9
|
+
* {@link Circle} => {@link Ellipse}.
|
|
10
|
+
*
|
|
11
|
+
* Currently implemented for:
|
|
12
|
+
*
|
|
13
|
+
* - {@link AABB}
|
|
14
|
+
* - {@link Arc}
|
|
15
|
+
* - {@link Circle}
|
|
16
|
+
* - {@link Cubic}
|
|
17
|
+
* - {@link Ellipse}
|
|
18
|
+
* - {@link Group}
|
|
19
|
+
* - {@link Line}
|
|
20
|
+
* - {@link Path}
|
|
21
|
+
* - {@link Points}
|
|
22
|
+
* - {@link Points3}
|
|
23
|
+
* - {@link Polygon}
|
|
24
|
+
* - {@link Polyline}
|
|
25
|
+
* - {@link Quad}
|
|
26
|
+
* - {@link Quadratic}
|
|
27
|
+
* - {@link Ray}
|
|
28
|
+
* - {@link Rect}
|
|
29
|
+
* - {@link Sphere}
|
|
30
|
+
* - {@link Text}
|
|
31
|
+
* - {@link Triangle}
|
|
32
|
+
*
|
|
33
|
+
* @param shape
|
|
34
|
+
* @param factor
|
|
35
|
+
*/
|
|
36
|
+
export declare const scale: MultiFn2<IShape, number | ReadonlyVec, IShape>;
|
|
37
|
+
//# sourceMappingURL=scale.d.ts.map
|
package/scale.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { isNumber } from "@thi.ng/checks/is-number";
|
|
2
|
+
import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
3
|
+
import { unsupported } from "@thi.ng/errors/unsupported";
|
|
4
|
+
import { mul2, mul3 } from "@thi.ng/vectors/mul";
|
|
5
|
+
import { mulN2, mulN3 } from "@thi.ng/vectors/muln";
|
|
6
|
+
import { normalize } from "@thi.ng/vectors/normalize";
|
|
7
|
+
import { AABB } from "./api/aabb.js";
|
|
8
|
+
import { Circle } from "./api/circle.js";
|
|
9
|
+
import { Cubic } from "./api/cubic.js";
|
|
10
|
+
import { Ellipse } from "./api/ellipse.js";
|
|
11
|
+
import { Line } from "./api/line.js";
|
|
12
|
+
import { Path } from "./api/path.js";
|
|
13
|
+
import { Points, Points3 } from "./api/points.js";
|
|
14
|
+
import { Polygon } from "./api/polygon.js";
|
|
15
|
+
import { Polyline } from "./api/polyline.js";
|
|
16
|
+
import { Quad } from "./api/quad.js";
|
|
17
|
+
import { Quadratic } from "./api/quadratic.js";
|
|
18
|
+
import { Ray } from "./api/ray.js";
|
|
19
|
+
import { Rect } from "./api/rect.js";
|
|
20
|
+
import { Sphere } from "./api/sphere.js";
|
|
21
|
+
import { Text } from "./api/text.js";
|
|
22
|
+
import { Triangle } from "./api/triangle.js";
|
|
23
|
+
import { __asVec } from "./internal/args.js";
|
|
24
|
+
import { __copyAttribs } from "./internal/copy.js";
|
|
25
|
+
import { __dispatch } from "./internal/dispatch.js";
|
|
26
|
+
import { __scaledShape as tx } from "./internal/scale.js";
|
|
27
|
+
/**
|
|
28
|
+
* Scales given shape uniformly or non-uniformly by given `factor`.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* Scaling non-uniformly might result in different result types, e.g.
|
|
32
|
+
* {@link Circle} => {@link Ellipse}.
|
|
33
|
+
*
|
|
34
|
+
* Currently implemented for:
|
|
35
|
+
*
|
|
36
|
+
* - {@link AABB}
|
|
37
|
+
* - {@link Arc}
|
|
38
|
+
* - {@link Circle}
|
|
39
|
+
* - {@link Cubic}
|
|
40
|
+
* - {@link Ellipse}
|
|
41
|
+
* - {@link Group}
|
|
42
|
+
* - {@link Line}
|
|
43
|
+
* - {@link Path}
|
|
44
|
+
* - {@link Points}
|
|
45
|
+
* - {@link Points3}
|
|
46
|
+
* - {@link Polygon}
|
|
47
|
+
* - {@link Polyline}
|
|
48
|
+
* - {@link Quad}
|
|
49
|
+
* - {@link Quadratic}
|
|
50
|
+
* - {@link Ray}
|
|
51
|
+
* - {@link Rect}
|
|
52
|
+
* - {@link Sphere}
|
|
53
|
+
* - {@link Text}
|
|
54
|
+
* - {@link Triangle}
|
|
55
|
+
*
|
|
56
|
+
* @param shape
|
|
57
|
+
* @param factor
|
|
58
|
+
*/
|
|
59
|
+
export const scale = defmulti(__dispatch, {}, {
|
|
60
|
+
aabb: ($, delta) => {
|
|
61
|
+
delta = __asVec(delta, 3);
|
|
62
|
+
return new AABB(mul3([], $.pos, delta), mul3([], $.size, delta), __copyAttribs($));
|
|
63
|
+
},
|
|
64
|
+
arc: ($, delta) => {
|
|
65
|
+
delta = __asVec(delta);
|
|
66
|
+
const a = $.copy();
|
|
67
|
+
mul2(null, a.pos, delta);
|
|
68
|
+
mul2(null, a.r, delta);
|
|
69
|
+
return a;
|
|
70
|
+
},
|
|
71
|
+
circle: ($, delta) => isNumber(delta)
|
|
72
|
+
? new Circle(mulN2([], $.pos, delta), $.r * delta, __copyAttribs($))
|
|
73
|
+
: new Ellipse(mul2([], $.pos, delta), mulN2([], delta, $.r), __copyAttribs($)),
|
|
74
|
+
cubic: tx(Cubic),
|
|
75
|
+
ellipse: ($, delta) => {
|
|
76
|
+
delta = __asVec(delta);
|
|
77
|
+
return new Ellipse(mul2([], $.pos, delta), mul2([], $.r, delta), __copyAttribs($));
|
|
78
|
+
},
|
|
79
|
+
group: ($, delta) => $.copyTransformed((x) => scale(x, delta)),
|
|
80
|
+
line: tx(Line),
|
|
81
|
+
path: ($, delta) => {
|
|
82
|
+
delta = __asVec(delta);
|
|
83
|
+
return new Path($.segments.map((s) => s.geo
|
|
84
|
+
? {
|
|
85
|
+
type: s.type,
|
|
86
|
+
geo: scale(s.geo, delta),
|
|
87
|
+
}
|
|
88
|
+
: {
|
|
89
|
+
type: s.type,
|
|
90
|
+
point: mul2([], s.point, delta),
|
|
91
|
+
}), __copyAttribs($));
|
|
92
|
+
},
|
|
93
|
+
points: tx(Points),
|
|
94
|
+
points3: tx(Points3),
|
|
95
|
+
poly: tx(Polygon),
|
|
96
|
+
polyline: tx(Polyline),
|
|
97
|
+
quad: tx(Quad),
|
|
98
|
+
quadratic: tx(Quadratic),
|
|
99
|
+
ray: ($, delta) => {
|
|
100
|
+
delta = __asVec(delta);
|
|
101
|
+
return new Ray(mul2([], $.pos, delta), normalize(null, mul2([], $.dir, delta)), __copyAttribs($));
|
|
102
|
+
},
|
|
103
|
+
rect: ($, delta) => {
|
|
104
|
+
delta = __asVec(delta);
|
|
105
|
+
return new Rect(mul2([], $.pos, delta), mul2([], $.size, delta), __copyAttribs($));
|
|
106
|
+
},
|
|
107
|
+
sphere: ($, delta) => isNumber(delta)
|
|
108
|
+
? new Sphere(mulN3([], $.pos, delta), $.r * delta, __copyAttribs($))
|
|
109
|
+
: unsupported("can't non-uniformly scale sphere"),
|
|
110
|
+
text: ($, delta) => new Text(mul2([], $.pos, __asVec(delta)), $.body, __copyAttribs($)),
|
|
111
|
+
tri: tx(Triangle),
|
|
112
|
+
});
|
package/scatter.d.ts
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import type { IShape } from "@thi.ng/geom-api";
|
|
2
2
|
import type { Vec } from "@thi.ng/vectors";
|
|
3
|
+
/**
|
|
4
|
+
* Produces `num` random points for which {@link pointInside} succeeeds for the
|
|
5
|
+
* given `shape`. Writes results into `out` array (or creates a new one).
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Samples are only created with the shapes bounding box and are chosen using
|
|
9
|
+
* optionall yprovided `rnd` {@link @thi.ng/random#IRandom} instance.
|
|
10
|
+
*
|
|
11
|
+
* @param shape
|
|
12
|
+
* @param num
|
|
13
|
+
* @param rnd
|
|
14
|
+
* @param out
|
|
15
|
+
*/
|
|
3
16
|
export declare const scatter: (shape: IShape, num: number, rnd?: import("@thi.ng/random/system").SystemRandom, out?: Vec[]) => Vec[] | undefined;
|
|
4
17
|
//# sourceMappingURL=scatter.d.ts.map
|
package/scatter.js
CHANGED
|
@@ -2,6 +2,19 @@ import { SYSTEM } from "@thi.ng/random/system";
|
|
|
2
2
|
import { randMinMax } from "@thi.ng/vectors/random";
|
|
3
3
|
import { bounds } from "./bounds.js";
|
|
4
4
|
import { pointInside } from "./point-inside.js";
|
|
5
|
+
/**
|
|
6
|
+
* Produces `num` random points for which {@link pointInside} succeeeds for the
|
|
7
|
+
* given `shape`. Writes results into `out` array (or creates a new one).
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Samples are only created with the shapes bounding box and are chosen using
|
|
11
|
+
* optionall yprovided `rnd` {@link @thi.ng/random#IRandom} instance.
|
|
12
|
+
*
|
|
13
|
+
* @param shape
|
|
14
|
+
* @param num
|
|
15
|
+
* @param rnd
|
|
16
|
+
* @param out
|
|
17
|
+
*/
|
|
5
18
|
export const scatter = (shape, num, rnd = SYSTEM, out = []) => {
|
|
6
19
|
const b = bounds(shape);
|
|
7
20
|
if (!b)
|
package/simplify.d.ts
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
import type { MultiFn2 } from "@thi.ng/defmulti";
|
|
2
2
|
import type { IShape } from "@thi.ng/geom-api";
|
|
3
|
+
/**
|
|
4
|
+
* Simplifies given 2D shape boundary using Douglas-Peucker algorithm
|
|
5
|
+
* (implemented by {@link @thi.ng/geom-resample#simplify}) and given `threshold`
|
|
6
|
+
* distance (default: 0, which removes only co-linear vertices).
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Currently only implemented for:
|
|
10
|
+
*
|
|
11
|
+
* - {@link Path}
|
|
12
|
+
* - {@link Polygon}
|
|
13
|
+
* - {@link Polyline}
|
|
14
|
+
*
|
|
15
|
+
* Use {@link asPath}, {@link asPolygon} or {@link asPolyline} to convert other
|
|
16
|
+
* shape types first.
|
|
17
|
+
*
|
|
18
|
+
* @param shape
|
|
19
|
+
* @param threshold
|
|
20
|
+
*/
|
|
3
21
|
export declare const simplify: MultiFn2<IShape, number, IShape>;
|
|
4
22
|
//# sourceMappingURL=simplify.d.ts.map
|
package/simplify.js
CHANGED
|
@@ -7,8 +7,26 @@ import { Polyline } from "./api/polyline.js";
|
|
|
7
7
|
import { __copyAttribs } from "./internal/copy.js";
|
|
8
8
|
import { __dispatch } from "./internal/dispatch.js";
|
|
9
9
|
import { vertices } from "./vertices.js";
|
|
10
|
+
/**
|
|
11
|
+
* Simplifies given 2D shape boundary using Douglas-Peucker algorithm
|
|
12
|
+
* (implemented by {@link @thi.ng/geom-resample#simplify}) and given `threshold`
|
|
13
|
+
* distance (default: 0, which removes only co-linear vertices).
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Currently only implemented for:
|
|
17
|
+
*
|
|
18
|
+
* - {@link Path}
|
|
19
|
+
* - {@link Polygon}
|
|
20
|
+
* - {@link Polyline}
|
|
21
|
+
*
|
|
22
|
+
* Use {@link asPath}, {@link asPolygon} or {@link asPolyline} to convert other
|
|
23
|
+
* shape types first.
|
|
24
|
+
*
|
|
25
|
+
* @param shape
|
|
26
|
+
* @param threshold
|
|
27
|
+
*/
|
|
10
28
|
export const simplify = defmulti(__dispatch, {}, {
|
|
11
|
-
path: ($, eps = 0
|
|
29
|
+
path: ($, eps = 0) => {
|
|
12
30
|
const res = [];
|
|
13
31
|
const orig = $.segments;
|
|
14
32
|
const n = orig.length;
|
|
@@ -43,6 +61,6 @@ export const simplify = defmulti(__dispatch, {}, {
|
|
|
43
61
|
}
|
|
44
62
|
return new Path(res, __copyAttribs($));
|
|
45
63
|
},
|
|
46
|
-
poly: ($, eps = 0
|
|
47
|
-
polyline: ($, eps = 0
|
|
64
|
+
poly: ($, eps = 0) => new Polygon(_simplify($.points, eps, true), __copyAttribs($)),
|
|
65
|
+
polyline: ($, eps = 0) => new Polyline(_simplify($.points, eps), __copyAttribs($)),
|
|
48
66
|
});
|
package/split-at.d.ts
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
import type { MultiFn2 } from "@thi.ng/defmulti";
|
|
2
2
|
import type { IShape } from "@thi.ng/geom-api";
|
|
3
|
+
/**
|
|
4
|
+
* Splits given shape in 2 parts at normalized parametric position `t`.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Currently only implemented for:
|
|
8
|
+
*
|
|
9
|
+
* - {@link Arc}
|
|
10
|
+
* - {@link Cubic}
|
|
11
|
+
* - {@link Line}
|
|
12
|
+
* - {@link Polyline}
|
|
13
|
+
* - {@link Quadratic}
|
|
14
|
+
*
|
|
15
|
+
* @param shape
|
|
16
|
+
* @param t
|
|
17
|
+
*/
|
|
3
18
|
export declare const splitAt: MultiFn2<IShape, number, IShape[] | undefined>;
|
|
4
19
|
//# sourceMappingURL=split-at.d.ts.map
|
package/split-at.js
CHANGED
|
@@ -13,6 +13,21 @@ import { __copyAttribs } from "./internal/copy.js";
|
|
|
13
13
|
import { __dispatch } from "./internal/dispatch.js";
|
|
14
14
|
import { __pointArraysAsShapes } from "./internal/points-as-shape.js";
|
|
15
15
|
import { __splitLine } from "./internal/split.js";
|
|
16
|
+
/**
|
|
17
|
+
* Splits given shape in 2 parts at normalized parametric position `t`.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* Currently only implemented for:
|
|
21
|
+
*
|
|
22
|
+
* - {@link Arc}
|
|
23
|
+
* - {@link Cubic}
|
|
24
|
+
* - {@link Line}
|
|
25
|
+
* - {@link Polyline}
|
|
26
|
+
* - {@link Quadratic}
|
|
27
|
+
*
|
|
28
|
+
* @param shape
|
|
29
|
+
* @param t
|
|
30
|
+
*/
|
|
16
31
|
export const splitAt = defmulti(__dispatch, {}, {
|
|
17
32
|
arc: ($, t) => {
|
|
18
33
|
const theta = fit01(t, $.start, $.end);
|
package/split-near.d.ts
CHANGED
|
@@ -4,14 +4,14 @@ import type { ReadonlyVec } from "@thi.ng/vectors";
|
|
|
4
4
|
/**
|
|
5
5
|
* Similar to {@link splitAt}, but instead of taking a normalized parametric
|
|
6
6
|
* split position, splits the given curve at the closest point to `p`.
|
|
7
|
-
* Returns tuple of split shapes of same type as `shape`.
|
|
8
7
|
*
|
|
9
|
-
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Currently only implemented for:
|
|
10
10
|
*
|
|
11
|
-
* - Cubic
|
|
12
|
-
* - Line
|
|
13
|
-
* - Polyline
|
|
14
|
-
* - Quadratic
|
|
11
|
+
* - {@link Cubic}
|
|
12
|
+
* - {@link Line}
|
|
13
|
+
* - {@link Polyline}
|
|
14
|
+
* - {@link Quadratic}
|
|
15
15
|
*
|
|
16
16
|
* @param shape - shape to operate on
|
|
17
17
|
* @param p - split point
|
package/split-near.js
CHANGED
|
@@ -15,14 +15,14 @@ import { __splitLine } from "./internal/split.js";
|
|
|
15
15
|
/**
|
|
16
16
|
* Similar to {@link splitAt}, but instead of taking a normalized parametric
|
|
17
17
|
* split position, splits the given curve at the closest point to `p`.
|
|
18
|
-
* Returns tuple of split shapes of same type as `shape`.
|
|
19
18
|
*
|
|
20
|
-
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* Currently only implemented for:
|
|
21
21
|
*
|
|
22
|
-
* - Cubic
|
|
23
|
-
* - Line
|
|
24
|
-
* - Polyline
|
|
25
|
-
* - Quadratic
|
|
22
|
+
* - {@link Cubic}
|
|
23
|
+
* - {@link Line}
|
|
24
|
+
* - {@link Polyline}
|
|
25
|
+
* - {@link Quadratic}
|
|
26
26
|
*
|
|
27
27
|
* @param shape - shape to operate on
|
|
28
28
|
* @param p - split point
|
package/subdiv-curve.d.ts
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import type { MultiFn2O } from "@thi.ng/defmulti";
|
|
2
2
|
import type { IShape, SubdivKernel } from "@thi.ng/geom-api";
|
|
3
|
+
/**
|
|
4
|
+
* Recursively applies {@link @thi.ng/geom-api#SubdivKernel} to given
|
|
5
|
+
* shape/boundary. See {@link @thi.ng/geom-subdiv-curve#} package for further
|
|
6
|
+
* details.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* By default only applies a single iteration.
|
|
10
|
+
*
|
|
11
|
+
* Currently only implemented for:
|
|
12
|
+
*
|
|
13
|
+
* - {@link Polygon}
|
|
14
|
+
* - {@link Polyline}
|
|
15
|
+
*
|
|
16
|
+
* @param shape
|
|
17
|
+
* @param kernel
|
|
18
|
+
* @param iter
|
|
19
|
+
*/
|
|
3
20
|
export declare const subdivCurve: MultiFn2O<IShape, SubdivKernel, number, IShape>;
|
|
4
21
|
//# sourceMappingURL=subdiv-curve.d.ts.map
|
package/subdiv-curve.js
CHANGED
|
@@ -4,6 +4,23 @@ import { Polygon } from "./api/polygon.js";
|
|
|
4
4
|
import { Polyline } from "./api/polyline.js";
|
|
5
5
|
import { __copyAttribs } from "./internal/copy.js";
|
|
6
6
|
import { __dispatch } from "./internal/dispatch.js";
|
|
7
|
+
/**
|
|
8
|
+
* Recursively applies {@link @thi.ng/geom-api#SubdivKernel} to given
|
|
9
|
+
* shape/boundary. See {@link @thi.ng/geom-subdiv-curve#} package for further
|
|
10
|
+
* details.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* By default only applies a single iteration.
|
|
14
|
+
*
|
|
15
|
+
* Currently only implemented for:
|
|
16
|
+
*
|
|
17
|
+
* - {@link Polygon}
|
|
18
|
+
* - {@link Polyline}
|
|
19
|
+
*
|
|
20
|
+
* @param shape
|
|
21
|
+
* @param kernel
|
|
22
|
+
* @param iter
|
|
23
|
+
*/
|
|
7
24
|
export const subdivCurve = defmulti(__dispatch, {}, {
|
|
8
25
|
poly: ($, kernel, iter = 1) => new Polygon(subdivide($.points, kernel, iter), __copyAttribs($)),
|
|
9
26
|
polyline: ($, kernel, iter = 1) => new Polyline(subdivide($.points, kernel, iter), __copyAttribs($)),
|
package/tangent-at.d.ts
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
import type { MultiFn2 } from "@thi.ng/defmulti";
|
|
2
2
|
import type { IShape } from "@thi.ng/geom-api";
|
|
3
3
|
import type { Vec } from "@thi.ng/vectors";
|
|
4
|
+
/**
|
|
5
|
+
* Computes tangent on shape/boundary at normalized parametric position `t`.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Currently implemented for:
|
|
9
|
+
*
|
|
10
|
+
* - {@link Circle}
|
|
11
|
+
* - {@link Cubic}
|
|
12
|
+
* - {@link Line}
|
|
13
|
+
* - {@link Polygon}
|
|
14
|
+
* - {@link Polyline}
|
|
15
|
+
* - {@link Quad}
|
|
16
|
+
* - {@link Quadratic}
|
|
17
|
+
* - {@link Rect}
|
|
18
|
+
* - {@link Triangle}
|
|
19
|
+
*
|
|
20
|
+
* @param shape
|
|
21
|
+
* @param t
|
|
22
|
+
*/
|
|
4
23
|
export declare const tangentAt: MultiFn2<IShape, number, Vec | undefined>;
|
|
5
24
|
//# sourceMappingURL=tangent-at.d.ts.map
|
package/tangent-at.js
CHANGED
|
@@ -7,6 +7,25 @@ import { HALF_PI, TAU } from "@thi.ng/math/api";
|
|
|
7
7
|
import { direction } from "@thi.ng/vectors/direction";
|
|
8
8
|
import { __dispatch } from "./internal/dispatch.js";
|
|
9
9
|
import { vertices } from "./vertices.js";
|
|
10
|
+
/**
|
|
11
|
+
* Computes tangent on shape/boundary at normalized parametric position `t`.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* Currently implemented for:
|
|
15
|
+
*
|
|
16
|
+
* - {@link Circle}
|
|
17
|
+
* - {@link Cubic}
|
|
18
|
+
* - {@link Line}
|
|
19
|
+
* - {@link Polygon}
|
|
20
|
+
* - {@link Polyline}
|
|
21
|
+
* - {@link Quad}
|
|
22
|
+
* - {@link Quadratic}
|
|
23
|
+
* - {@link Rect}
|
|
24
|
+
* - {@link Triangle}
|
|
25
|
+
*
|
|
26
|
+
* @param shape
|
|
27
|
+
* @param t
|
|
28
|
+
*/
|
|
10
29
|
export const tangentAt = defmulti(__dispatch, {
|
|
11
30
|
quad: "poly",
|
|
12
31
|
tri: "poly",
|
package/tessellate.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import type { IShape, Tessellator } from "@thi.ng/geom-api";
|
|
2
2
|
import type { Vec } from "@thi.ng/vectors";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Recursively tessellates shape using provided
|
|
5
|
+
* {@link @thi.ng/geom-api#Tessellator} functions. See
|
|
6
|
+
* {@link @thi.ng/geom-tessellate#} package for more details.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Implemented for all shapes supported by {@link vertices}.
|
|
10
|
+
*
|
|
11
|
+
* @param shape
|
|
12
|
+
* @param tessellators
|
|
13
|
+
*/
|
|
14
|
+
export declare const tessellate: import("@thi.ng/defmulti").MultiFn2<IShape<IShape<any>>, Tessellator[], Vec[][]>;
|
|
4
15
|
//# sourceMappingURL=tessellate.d.ts.map
|