@thi.ng/geom 7.0.1 → 8.0.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 +190 -1
- package/README.md +349 -112
- 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 +54 -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 +35 -1
- package/index.js +35 -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/api.d.ts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import type { Fn, ICopy, IToHiccup } from "@thi.ng/api";
|
|
2
|
+
import * as isec from "@thi.ng/geom-isec/api";
|
|
3
|
+
import * as sample from "@thi.ng/geom-resample/api";
|
|
4
|
+
import type * as sdc from "@thi.ng/geom-subdiv-curve";
|
|
5
|
+
import type * as tess from "@thi.ng/geom-tessellate";
|
|
6
|
+
import type { ReadonlyMat } from "@thi.ng/matrices";
|
|
7
|
+
import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
|
|
8
|
+
export type IntersectionResult = isec.IntersectionResult;
|
|
9
|
+
export declare const IntersectionType: typeof isec.IntersectionType;
|
|
10
|
+
export declare const NONE: isec.IntersectionResult;
|
|
11
|
+
/**
|
|
12
|
+
* Sets number of default samples for all operations involving shape sampling
|
|
13
|
+
* (e.g. {@link vertices}, {@link asPolygon}, {@link asPolyline}).
|
|
14
|
+
*
|
|
15
|
+
* @param num
|
|
16
|
+
*/
|
|
17
|
+
export declare const setDefaultSamples: (n: number) => number;
|
|
18
|
+
export type SamplingOpts = sample.SamplingOpts;
|
|
19
|
+
export type SubdivKernel = sdc.SubdivKernel;
|
|
20
|
+
export type Tessellator = tess.Tessellator;
|
|
21
|
+
export type ITessellation = tess.ITessellation;
|
|
22
|
+
export interface Attribs {
|
|
23
|
+
/**
|
|
24
|
+
* Shape resampling options/resolution.
|
|
25
|
+
*/
|
|
26
|
+
__samples?: Partial<SamplingOpts> | number;
|
|
27
|
+
/**
|
|
28
|
+
* Control attribute to define the number of fractional digits for numeric
|
|
29
|
+
* values in the serialized SVG string.
|
|
30
|
+
*
|
|
31
|
+
* @defaultValue 3
|
|
32
|
+
*/
|
|
33
|
+
__prec?: number;
|
|
34
|
+
/**
|
|
35
|
+
* 2D rotation angle (in radians)
|
|
36
|
+
*/
|
|
37
|
+
rotate?: number;
|
|
38
|
+
/**
|
|
39
|
+
* 3D X rotation angle (in radians)
|
|
40
|
+
*/
|
|
41
|
+
rotateX?: number;
|
|
42
|
+
/**
|
|
43
|
+
* 3D Y rotation angle (in radians)
|
|
44
|
+
*/
|
|
45
|
+
rotateY?: number;
|
|
46
|
+
/**
|
|
47
|
+
* 3D Z rotation angle (in radians)
|
|
48
|
+
*/
|
|
49
|
+
rotateZ?: number;
|
|
50
|
+
/**
|
|
51
|
+
* Uniform or non-uniform scale factor.
|
|
52
|
+
*/
|
|
53
|
+
scale?: number | ReadonlyVec;
|
|
54
|
+
/**
|
|
55
|
+
* Translation offset.
|
|
56
|
+
*/
|
|
57
|
+
translate?: ReadonlyVec;
|
|
58
|
+
/**
|
|
59
|
+
* Transformation matrix (2x3 for 2D, 4x4 for 3D).
|
|
60
|
+
*/
|
|
61
|
+
transform?: ReadonlyVec;
|
|
62
|
+
/**
|
|
63
|
+
* Fill color
|
|
64
|
+
*/
|
|
65
|
+
fill?: any;
|
|
66
|
+
/**
|
|
67
|
+
* Stroke color
|
|
68
|
+
*/
|
|
69
|
+
stroke?: any;
|
|
70
|
+
/**
|
|
71
|
+
* Stroke weight
|
|
72
|
+
*/
|
|
73
|
+
weight?: number;
|
|
74
|
+
[id: string]: any;
|
|
75
|
+
}
|
|
76
|
+
export interface GroupAttribs extends Attribs {
|
|
77
|
+
/**
|
|
78
|
+
* Currently only used by thi.ng/hiccup-canvas. Canvas background color,
|
|
79
|
+
* should only should be used for a root group.
|
|
80
|
+
*/
|
|
81
|
+
__background?: any;
|
|
82
|
+
/**
|
|
83
|
+
* Only used by thi.ng/hiccup-canvas. Force clearing of the canvas before
|
|
84
|
+
* drawing. Takes priority over {@link GroupAttribs.__background} and should
|
|
85
|
+
* only should be used for a root group.
|
|
86
|
+
*
|
|
87
|
+
* @defaultValue false
|
|
88
|
+
*/
|
|
89
|
+
__clear?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Only used for SVG serialization. Inkscape payer name
|
|
92
|
+
*/
|
|
93
|
+
__inkscapeLayer?: string;
|
|
94
|
+
}
|
|
95
|
+
export interface IAttributed<T> {
|
|
96
|
+
attribs?: Attribs;
|
|
97
|
+
withAttribs(attribs: Attribs): T;
|
|
98
|
+
}
|
|
99
|
+
export interface ICopyTransformed<A, B = A> {
|
|
100
|
+
copyTransformed(fn: Fn<A, B>): this;
|
|
101
|
+
}
|
|
102
|
+
export interface IShape<T extends IShape = IShape<any>> extends IAttributed<T>, ICopy<T> {
|
|
103
|
+
readonly type: number | string;
|
|
104
|
+
readonly dim: number;
|
|
105
|
+
}
|
|
106
|
+
export type IShape2<T extends IShape2 = IShape2<any>> = IShape<T> & {
|
|
107
|
+
readonly dim: 2;
|
|
108
|
+
};
|
|
109
|
+
export type IShape3<T extends IShape3 = IShape3<any>> = IShape<T> & {
|
|
110
|
+
readonly dim: 3;
|
|
111
|
+
};
|
|
112
|
+
export interface AABBLike extends IShape<AABBLike> {
|
|
113
|
+
pos: Vec;
|
|
114
|
+
size: Vec;
|
|
115
|
+
min(): Vec;
|
|
116
|
+
max(): Vec;
|
|
117
|
+
offset(x: number): this;
|
|
118
|
+
}
|
|
119
|
+
export interface SphereLike extends IShape<SphereLike> {
|
|
120
|
+
pos: Vec;
|
|
121
|
+
r: number;
|
|
122
|
+
}
|
|
123
|
+
export interface PCLike extends IShape<PCLike> {
|
|
124
|
+
points: Vec[];
|
|
125
|
+
}
|
|
126
|
+
export interface PCLikeConstructor<T extends PCLike = PCLike> {
|
|
127
|
+
new (pts: Vec[], attribs?: Attribs): T;
|
|
128
|
+
}
|
|
129
|
+
export interface IHiccupShape extends IShape, IToHiccup {
|
|
130
|
+
}
|
|
131
|
+
export type IHiccupShape2<T extends IHiccupShape2 = IHiccupShape2<any>> = IHiccupShape & IShape2<T>;
|
|
132
|
+
export type IHiccupShape3<T extends IHiccupShape3 = IHiccupShape3<any>> = IHiccupShape & IShape3<T>;
|
|
133
|
+
export type SegmentType2 = "m" | "l" | "p" | "a" | "c" | "q" | "z";
|
|
134
|
+
/**
|
|
135
|
+
* Currently no 3D arc segments supported
|
|
136
|
+
*/
|
|
137
|
+
export type SegmentType3 = Exclude<SegmentType2, "a">;
|
|
138
|
+
export type PathSegment = PathSegment2 | PathSegment3;
|
|
139
|
+
export interface PathSegment2 {
|
|
140
|
+
type: SegmentType2;
|
|
141
|
+
point?: Vec;
|
|
142
|
+
geo?: IShape2 & IHiccupPathSegment;
|
|
143
|
+
}
|
|
144
|
+
export interface PathSegment3 {
|
|
145
|
+
type: SegmentType3;
|
|
146
|
+
point?: Vec;
|
|
147
|
+
geo?: IShape3 & IHiccupPathSegment;
|
|
148
|
+
}
|
|
149
|
+
export interface IHiccupPathSegment {
|
|
150
|
+
toHiccupPathSegments(): HiccupPathSegment[];
|
|
151
|
+
}
|
|
152
|
+
export type HiccupPathSegment = [string, ...any[]];
|
|
153
|
+
export interface IPath<S extends PathSegment> extends IShape {
|
|
154
|
+
segments: S[];
|
|
155
|
+
subPaths: S[][];
|
|
156
|
+
readonly closed: boolean;
|
|
157
|
+
close(): this;
|
|
158
|
+
addSegments(...segments: S[]): this;
|
|
159
|
+
addSubPaths(...paths: S[][]): this;
|
|
160
|
+
isComplex(): boolean;
|
|
161
|
+
}
|
|
162
|
+
export interface PathConstructor<P extends IPath<S>, S extends PathSegment> {
|
|
163
|
+
new (segments: S[], subPaths: S[][], attribs?: Attribs): P;
|
|
164
|
+
}
|
|
165
|
+
export interface CubicOpts {
|
|
166
|
+
/**
|
|
167
|
+
* Controls behavior of curve conversion/interpolation:
|
|
168
|
+
*
|
|
169
|
+
* - `default`: Original vertices are used control points (see
|
|
170
|
+
* [`closedCubicFromControlPoints()`](https://docs.thi.ng/umbrella/geom-splines/functions/closedCubicFromControlPoints.html))
|
|
171
|
+
* - `break`: Original vertices are used as curve points, tangents are
|
|
172
|
+
* computed automatically (see
|
|
173
|
+
* [`closedCubicFromBreakPoints()`](https://docs.thi.ng/umbrella/geom-splines/functions/closedCubicFromBreakPoints.html))
|
|
174
|
+
* - `hobby`: Use John Hobby's interpolation algorithm (see
|
|
175
|
+
* [`cubicHobby2()`](https://docs.thi.ng/umbrella/geom-splines/functions/cubicHobby2.html))
|
|
176
|
+
*/
|
|
177
|
+
mode: "default" | "break" | "hobby";
|
|
178
|
+
/**
|
|
179
|
+
* True, to enable uniform tangent scaling. If false (default), each
|
|
180
|
+
* tangent will be also scaled by the length of its related parent
|
|
181
|
+
* edge in the source shape.
|
|
182
|
+
*
|
|
183
|
+
* @remarks
|
|
184
|
+
* Unused for `hobby` mode.
|
|
185
|
+
*/
|
|
186
|
+
uniform: boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Tangent scale factor. Actual length in uniform scaling mode.
|
|
189
|
+
*/
|
|
190
|
+
scale: number;
|
|
191
|
+
}
|
|
192
|
+
export type TransformVertexFn = Fn<ReadonlyVec, ReadonlyMat>;
|
|
193
|
+
//# sourceMappingURL=api.d.ts.map
|
package/api.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as isec from "@thi.ng/geom-isec/api";
|
|
2
|
+
import * as sample from "@thi.ng/geom-resample/api";
|
|
3
|
+
const IntersectionType = isec.IntersectionType;
|
|
4
|
+
const NONE = isec.NONE;
|
|
5
|
+
const setDefaultSamples = sample.setDefaultSamples;
|
|
6
|
+
export {
|
|
7
|
+
IntersectionType,
|
|
8
|
+
NONE,
|
|
9
|
+
setDefaultSamples
|
|
10
|
+
};
|
package/apply-transforms.d.ts
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import type { MultiFn1 } from "@thi.ng/defmulti";
|
|
2
|
-
import type { IShape } from "
|
|
2
|
+
import type { IShape, IShape2, IShape3 } from "./api.js";
|
|
3
|
+
import type { Arc } from "./api/arc.js";
|
|
4
|
+
import type { Circle } from "./api/circle.js";
|
|
5
|
+
import type { Ellipse } from "./api/ellipse.js";
|
|
6
|
+
import type { Rect } from "./api/rect.js";
|
|
7
|
+
/**
|
|
8
|
+
* Function overrides for {@link applyTransforms}.
|
|
9
|
+
*/
|
|
10
|
+
export type ApplyTransformsFn = {
|
|
11
|
+
(shape: Arc): IShape2;
|
|
12
|
+
(shape: Circle): IShape2;
|
|
13
|
+
(shape: Ellipse): IShape2;
|
|
14
|
+
(shape: Rect): IShape2;
|
|
15
|
+
<T extends IShape2>(shape: T): T;
|
|
16
|
+
<T extends IShape3>(shape: T): T;
|
|
17
|
+
} & MultiFn1<IShape, IShape>;
|
|
3
18
|
/**
|
|
4
19
|
* Applies any spatial transformation attributes defined (if any) for the given
|
|
5
20
|
* shape. If no such attributes exist, the original shape is returned as is.
|
|
@@ -7,10 +22,11 @@ import type { IShape } from "@thi.ng/geom-api";
|
|
|
7
22
|
* @remarks
|
|
8
23
|
* The following attributes are considered:
|
|
9
24
|
*
|
|
10
|
-
* - transform
|
|
11
|
-
* - translate
|
|
12
|
-
* - scale
|
|
13
|
-
* - rotate
|
|
25
|
+
* - `transform`: A 2x3 (for 2D) or 4x4 (for 3D) transformation matrix
|
|
26
|
+
* - `translate`: Translation/offset vector
|
|
27
|
+
* - `scale`: A scale factor (scalar for uniform or vector for non-uniform)
|
|
28
|
+
* - `rotate`: Rotation angle (in radians, 2D only)
|
|
29
|
+
* - `rotate[XYZ]`: Rotation angle (in radians, 3D only)
|
|
14
30
|
*
|
|
15
31
|
* If the `transform` attrib is given, the others will be ignored. If any of the
|
|
16
32
|
* other 3 attribs is provided, the order of application is: rotate, scale,
|
|
@@ -18,16 +34,22 @@ import type { IShape } from "@thi.ng/geom-api";
|
|
|
18
34
|
* transformed shapes to ensure idempotent behavior.
|
|
19
35
|
*
|
|
20
36
|
* For (@link group} shapes, the children are processed in depth-first order
|
|
21
|
-
* with any transformations to the group itself applied
|
|
37
|
+
* with any transformations to the group itself applied post-order.
|
|
22
38
|
*
|
|
23
|
-
* Note: Where possible, this function delegates to {@link rotate},
|
|
24
|
-
* {@link
|
|
25
|
-
*
|
|
26
|
-
*
|
|
39
|
+
* Note: Where possible, this function delegates to {@link rotate} (for 2D),
|
|
40
|
+
* {@link rotateX}, {@link rotateY}, {@link rotateZ} (all for 3D), {@link scale}
|
|
41
|
+
* and {@link translate} to realize individual/partial transformation aspects to
|
|
42
|
+
* increase the likelihood of retaining original shape types. E.g. uniformly
|
|
43
|
+
* scaling a circle with a scalar factor retains a circle, but scaling
|
|
27
44
|
* non-uniformly will convert it to an ellipse... Similarly, rotating a rect
|
|
28
45
|
* will convert it to a quad etc.
|
|
29
46
|
*
|
|
47
|
+
* For those shape types for which a shape conversion _might_ be involved, the
|
|
48
|
+
* function only returns a generic `IShape2` or `IShape3` type. To find out if a
|
|
49
|
+
* shape conversion will apply, please consult the docs for the above linked
|
|
50
|
+
* transformation functions.
|
|
51
|
+
*
|
|
30
52
|
* @param shape
|
|
31
53
|
*/
|
|
32
|
-
export declare const applyTransforms:
|
|
54
|
+
export declare const applyTransforms: ApplyTransformsFn;
|
|
33
55
|
//# sourceMappingURL=apply-transforms.d.ts.map
|
package/apply-transforms.js
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
import { withoutKeysObj } from "@thi.ng/associative/without-keys";
|
|
2
2
|
import { DEFAULT, defmulti } from "@thi.ng/defmulti/defmulti";
|
|
3
3
|
import { __dispatch } from "./internal/dispatch.js";
|
|
4
|
+
import { rotateX, rotateY, rotateZ } from "./rotate-around-axis.js";
|
|
4
5
|
import { rotate } from "./rotate.js";
|
|
5
6
|
import { scale } from "./scale.js";
|
|
6
7
|
import { transform } from "./transform.js";
|
|
7
8
|
import { translate } from "./translate.js";
|
|
8
|
-
const TX_ATTRIBS = [
|
|
9
|
+
const TX_ATTRIBS = [
|
|
10
|
+
"rotate",
|
|
11
|
+
"rotateX",
|
|
12
|
+
"rotateY",
|
|
13
|
+
"rotateZ",
|
|
14
|
+
"scale",
|
|
15
|
+
"transform",
|
|
16
|
+
"translate"
|
|
17
|
+
];
|
|
9
18
|
const __apply = ($) => {
|
|
10
19
|
let attribs = $.attribs;
|
|
11
20
|
if (!attribs) return $;
|
|
12
|
-
const {
|
|
21
|
+
const {
|
|
22
|
+
transform: tx,
|
|
23
|
+
translate: t,
|
|
24
|
+
rotate: r,
|
|
25
|
+
scale: s,
|
|
26
|
+
rotateX: rx,
|
|
27
|
+
rotateY: ry,
|
|
28
|
+
rotateZ: rz
|
|
29
|
+
} = attribs;
|
|
13
30
|
if (tx)
|
|
14
31
|
return transform(
|
|
15
32
|
$.withAttribs(withoutKeysObj(attribs, TX_ATTRIBS)),
|
|
@@ -17,14 +34,17 @@ const __apply = ($) => {
|
|
|
17
34
|
);
|
|
18
35
|
if (!(t || r || s)) return $;
|
|
19
36
|
$ = $.withAttribs(withoutKeysObj(attribs, TX_ATTRIBS));
|
|
20
|
-
if (r) $ = rotate($, r);
|
|
37
|
+
if (r != null && $.dim === 2) $ = rotate($, r);
|
|
38
|
+
if (rx != null && $.dim === 3) $ = rotateX($, rx);
|
|
39
|
+
if (ry != null && $.dim === 3) $ = rotateY($, ry);
|
|
40
|
+
if (rz != null && $.dim === 3) $ = rotateZ($, rz);
|
|
21
41
|
if (s) $ = scale($, s);
|
|
22
42
|
if (t) $ = translate($, t);
|
|
23
43
|
return $;
|
|
24
44
|
};
|
|
25
45
|
const applyTransforms = defmulti(
|
|
26
46
|
__dispatch,
|
|
27
|
-
{},
|
|
47
|
+
{ group3: "group" },
|
|
28
48
|
{
|
|
29
49
|
[DEFAULT]: __apply,
|
|
30
50
|
group: ($) => __apply($.copyTransformed((x) => applyTransforms(x)))
|
package/arc-length.d.ts
CHANGED
|
@@ -1,22 +1,36 @@
|
|
|
1
1
|
import type { MultiFn1 } from "@thi.ng/defmulti";
|
|
2
|
-
import type { IShape } from "
|
|
2
|
+
import type { IShape } from "./api.js";
|
|
3
3
|
/**
|
|
4
|
-
* Returns the arc length / perimeter / circumference of the given
|
|
5
|
-
*
|
|
6
|
-
* sum of results.
|
|
4
|
+
* Returns the arc length / perimeter / circumference of the given shape. For
|
|
5
|
+
* groups calls {@link arcLength} for each child and returns the sum of results.
|
|
7
6
|
*
|
|
8
7
|
* Implemented for:
|
|
9
8
|
*
|
|
9
|
+
* - {@link Arc}
|
|
10
10
|
* - {@link Circle}
|
|
11
11
|
* - {@link ComplexPolygon}
|
|
12
|
+
* - {@link Cubic}
|
|
13
|
+
* - {@link Cubic3}
|
|
12
14
|
* - {@link Ellipse}
|
|
13
15
|
* - {@link Group} (total sum of child circumferences)
|
|
16
|
+
* - {@link Group3} (total sum of child circumferences)
|
|
14
17
|
* - {@link Line}
|
|
18
|
+
* - {@link Line3}
|
|
19
|
+
* - {@link Path}
|
|
20
|
+
* - {@link Path3}
|
|
15
21
|
* - {@link Polygon}
|
|
22
|
+
* - {@link Polygon3}
|
|
16
23
|
* - {@link Polyline}
|
|
24
|
+
* - {@link Polyline3}
|
|
17
25
|
* - {@link Quad}
|
|
26
|
+
* - {@link Quad3}
|
|
27
|
+
* - {@link Quadratic}
|
|
28
|
+
* - {@link Quadratic3}
|
|
18
29
|
* - {@link Rect}
|
|
19
30
|
* - {@link Triangle}
|
|
31
|
+
* - {@link Triangle3}
|
|
32
|
+
*
|
|
33
|
+
* For all other types the function returns 0.
|
|
20
34
|
*
|
|
21
35
|
* @param shape
|
|
22
36
|
*/
|
package/arc-length.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defmulti } from "@thi.ng/defmulti/defmulti";
|
|
1
|
+
import { DEFAULT, defmulti } from "@thi.ng/defmulti/defmulti";
|
|
2
2
|
import { perimeter } from "@thi.ng/geom-poly-utils/perimeter";
|
|
3
3
|
import { PI, TAU } from "@thi.ng/math/api";
|
|
4
4
|
import { dist } from "@thi.ng/vectors/dist";
|
|
@@ -8,10 +8,25 @@ import { __dispatch } from "./internal/dispatch.js";
|
|
|
8
8
|
const arcLength = defmulti(
|
|
9
9
|
__dispatch,
|
|
10
10
|
{
|
|
11
|
+
arc: "$aspolyline",
|
|
12
|
+
cubic: "$aspolyline",
|
|
13
|
+
cubic3: "$aspolyline",
|
|
14
|
+
group3: "group",
|
|
15
|
+
line3: "line",
|
|
16
|
+
path3: "path",
|
|
17
|
+
poly3: "poly",
|
|
18
|
+
polyline3: "polyline",
|
|
11
19
|
quad: "poly",
|
|
12
|
-
|
|
20
|
+
quad3: "poly",
|
|
21
|
+
quadratic: "$aspolyline",
|
|
22
|
+
quadratic3: "$aspolyline",
|
|
23
|
+
tri: "poly",
|
|
24
|
+
tri3: "tri"
|
|
13
25
|
},
|
|
14
26
|
{
|
|
27
|
+
[DEFAULT]: () => 0,
|
|
28
|
+
$aspoly: ($) => asPolygon($).reduce((acc, p) => acc + arcLength(p), 0),
|
|
29
|
+
$aspolyline: ($) => asPolyline($).reduce((acc, p) => acc + arcLength(p), 0),
|
|
15
30
|
circle: ($) => TAU * $.r,
|
|
16
31
|
complexpoly: ($) => [$.boundary, ...$.children].reduce(
|
|
17
32
|
(acc, c) => acc + arcLength(c),
|
|
@@ -31,7 +46,7 @@ const arcLength = defmulti(
|
|
|
31
46
|
);
|
|
32
47
|
},
|
|
33
48
|
poly: ({ points }) => perimeter(points, points.length, true),
|
|
34
|
-
polyline: ({ points }) => perimeter(points
|
|
49
|
+
polyline: ({ points }) => perimeter(points),
|
|
35
50
|
rect: ({ size: [w, h] }) => 2 * (w + h),
|
|
36
51
|
tri: ({ points }) => dist(points[0], points[1]) + dist(points[1], points[2]) + dist(points[2], points[0])
|
|
37
52
|
}
|
package/arc.d.ts
CHANGED
package/area.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MultiFn1O } from "@thi.ng/defmulti";
|
|
2
|
-
import type { IShape } from "
|
|
2
|
+
import type { IShape } from "./api.js";
|
|
3
3
|
/**
|
|
4
4
|
* Computes the possibly signed (unsigned by default) surface area of given
|
|
5
5
|
* `shape`. For groups calls itself for each child and returns sum of unsigned
|
|
@@ -9,29 +9,25 @@ import type { IShape } from "@thi.ng/geom-api";
|
|
|
9
9
|
* In general, for polygons and triangles, the sign of the result can be used as
|
|
10
10
|
* indication of the shapes orientation (clockwise / counterclockwise).
|
|
11
11
|
*
|
|
12
|
-
* For curves, lines, point clouds and rays the function returns 0.
|
|
13
|
-
*
|
|
14
12
|
* Currently implemented for:
|
|
15
13
|
*
|
|
16
14
|
* - {@link AABB}
|
|
15
|
+
* - {@link Arc} (sector area)
|
|
17
16
|
* - {@link Circle}
|
|
18
17
|
* - {@link ComplexPolygon}
|
|
19
|
-
* - {@link Cubic}
|
|
20
18
|
* - {@link Ellipse}
|
|
21
19
|
* - {@link Group}
|
|
22
|
-
* - {@link
|
|
20
|
+
* - {@link Group3}
|
|
23
21
|
* - {@link Path} (closed only & via poly conversion)
|
|
24
|
-
* - {@link Plane}
|
|
25
|
-
* - {@link Points}
|
|
22
|
+
* - {@link Plane} (infinity)
|
|
26
23
|
* - {@link Polygon}
|
|
27
|
-
* - {@link Polyline}
|
|
28
24
|
* - {@link Quad}
|
|
29
|
-
* - {@link Quadratic}
|
|
30
|
-
* - {@link Ray}
|
|
31
25
|
* - {@link Rect}
|
|
32
26
|
* - {@link Sphere}
|
|
33
27
|
* - {@link Triangle}
|
|
34
28
|
*
|
|
29
|
+
* For all other shape types the function returns 0.
|
|
30
|
+
*
|
|
35
31
|
* @param shape - shape to operate on
|
|
36
32
|
* @param signed - true, if signed area
|
|
37
33
|
*/
|
package/area.js
CHANGED
|
@@ -6,8 +6,9 @@ import { asPolygon } from "./as-polygon.js";
|
|
|
6
6
|
import { __dispatch } from "./internal/dispatch.js";
|
|
7
7
|
const area = defmulti(
|
|
8
8
|
__dispatch,
|
|
9
|
-
{ quad: "poly" },
|
|
9
|
+
{ group3: "group", quad: "poly" },
|
|
10
10
|
{
|
|
11
|
+
[DEFAULT]: () => 0,
|
|
11
12
|
aabb: ({ size: [w, h, d] }) => 2 * (w * h + w * d + h * d),
|
|
12
13
|
arc: (
|
|
13
14
|
// http://cut-the-knot.org/Generalization/Cavalieri2.shtml
|
|
@@ -30,8 +31,7 @@ const area = defmulti(
|
|
|
30
31
|
tri: ($, signed) => {
|
|
31
32
|
const area2 = 0.5 * signedArea2(...$.points);
|
|
32
33
|
return signed ? area2 : Math.abs(area2);
|
|
33
|
-
}
|
|
34
|
-
[DEFAULT]: () => 0
|
|
34
|
+
}
|
|
35
35
|
}
|
|
36
36
|
);
|
|
37
37
|
export {
|
package/as-cubic.d.ts
CHANGED
|
@@ -1,43 +1,69 @@
|
|
|
1
1
|
import type { MultiFn1O } from "@thi.ng/defmulti";
|
|
2
|
-
import type { CubicOpts, IShape } from "
|
|
2
|
+
import type { CubicOpts, IShape, IShape2, IShape3 } from "./api.js";
|
|
3
3
|
import { Cubic } from "./api/cubic.js";
|
|
4
|
+
import { Cubic3 } from "./api/cubic3.js";
|
|
5
|
+
export interface AsCubicOpts extends CubicOpts {
|
|
6
|
+
attribs: boolean;
|
|
7
|
+
}
|
|
4
8
|
/**
|
|
5
|
-
*
|
|
6
|
-
|
|
9
|
+
* Function overrides for {@link asCubic}.
|
|
10
|
+
*/
|
|
11
|
+
export type AsCubicFn = {
|
|
12
|
+
<T extends IShape2>(shape: T, opts?: Partial<AsCubicOpts>): Cubic[];
|
|
13
|
+
<T extends IShape3>(shape: T, opts?: Partial<AsCubicOpts>): Cubic3[];
|
|
14
|
+
} & MultiFn1O<IShape, Partial<AsCubicOpts>, (Cubic | Cubic3)[]>;
|
|
15
|
+
/**
|
|
16
|
+
* Converts given shape boundary into an array of {@link Cubic} or
|
|
17
|
+
* {@link Cubic3} curves. For some shapes (see below) the conversion supports
|
|
18
|
+
* optionally provided {@link CubicOpts}.
|
|
7
19
|
*
|
|
8
20
|
* @remarks
|
|
9
21
|
* Currently implemented for:
|
|
10
22
|
*
|
|
11
23
|
* - {@link Arc}
|
|
24
|
+
* - {@link BPatch}
|
|
12
25
|
* - {@link Circle}
|
|
13
26
|
* - {@link ComplexPolygon}
|
|
14
27
|
* - {@link Cubic}
|
|
28
|
+
* - {@link Cubic3}
|
|
15
29
|
* - {@link Ellipse}
|
|
16
30
|
* - {@link Group}
|
|
31
|
+
* - {@link Group3}
|
|
17
32
|
* - {@link Line}
|
|
33
|
+
* - {@link Line3}
|
|
18
34
|
* - {@link Path}
|
|
35
|
+
* - {@link Path3}
|
|
19
36
|
* - {@link Polygon}
|
|
37
|
+
* - {@link Polygon3}
|
|
20
38
|
* - {@link Polyline}
|
|
39
|
+
* - {@link Polyline3}
|
|
21
40
|
* - {@link Quad}
|
|
41
|
+
* - {@link Quad3}
|
|
22
42
|
* - {@link Quadratic}
|
|
43
|
+
* - {@link Quadratic3}
|
|
23
44
|
* - {@link Rect}
|
|
24
45
|
* - {@link Triangle}
|
|
46
|
+
* - {@link Triangle3}
|
|
25
47
|
*
|
|
26
48
|
* Shape types supporting custom conversion options (see
|
|
27
49
|
* [@thi.ng/geom-splines](https://github.com/thi-ng/umbrella/tree/develop/packages/geom-splines#cubic-curve-conversion-from-polygons--polylines)
|
|
28
50
|
* for more details):
|
|
29
51
|
*
|
|
30
52
|
* - {@link Group} (only used for eligible children)
|
|
53
|
+
* - {@link Group3} (only used for eligible children)
|
|
31
54
|
* - {@link ComplexPolygon}
|
|
32
55
|
* - {@link Polygon}
|
|
56
|
+
* - {@link Polygon3}
|
|
33
57
|
* - {@link Polyline}
|
|
58
|
+
* - {@link Polyline3}
|
|
34
59
|
* - {@link Quad}
|
|
35
|
-
* - {@link
|
|
60
|
+
* - {@link Quad3}
|
|
36
61
|
* - {@link Rect}
|
|
37
62
|
* - {@link Triangle}
|
|
63
|
+
* - {@link Triangle3}
|
|
38
64
|
*
|
|
39
65
|
* @param shape
|
|
40
66
|
* @param opts
|
|
41
67
|
*/
|
|
42
|
-
export declare const asCubic:
|
|
68
|
+
export declare const asCubic: AsCubicFn;
|
|
43
69
|
//# sourceMappingURL=as-cubic.d.ts.map
|