@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.
Files changed (251) hide show
  1. package/CHANGELOG.md +190 -1
  2. package/README.md +349 -112
  3. package/aabb.d.ts +26 -1
  4. package/api/aabb.d.ts +5 -4
  5. package/api/aabb.js +10 -7
  6. package/api/apc.d.ts +5 -3
  7. package/api/arc.d.ts +6 -5
  8. package/api/arc.js +3 -4
  9. package/api/bpatch.d.ts +6 -3
  10. package/api/bpatch.js +5 -3
  11. package/api/circle.d.ts +4 -3
  12. package/api/circle.js +9 -6
  13. package/api/complex-polygon.d.ts +7 -3
  14. package/api/complex-polygon.js +14 -4
  15. package/api/cubic.d.ts +8 -5
  16. package/api/cubic.js +12 -6
  17. package/api/cubic3.d.ts +15 -0
  18. package/api/cubic3.js +38 -0
  19. package/api/ellipse.d.ts +4 -3
  20. package/api/ellipse.js +7 -8
  21. package/api/extra.d.ts +15 -0
  22. package/api/extra.js +19 -0
  23. package/api/group.d.ts +12 -11
  24. package/api/group.js +4 -5
  25. package/api/group3.d.ts +30 -0
  26. package/api/group3.js +48 -0
  27. package/api/line.d.ts +8 -5
  28. package/api/line.js +8 -8
  29. package/api/line3.d.ts +15 -0
  30. package/api/line3.js +29 -0
  31. package/api/path.d.ts +14 -11
  32. package/api/path.js +17 -12
  33. package/api/path3.d.ts +28 -0
  34. package/api/path3.js +91 -0
  35. package/api/plane.d.ts +4 -3
  36. package/api/plane.js +7 -4
  37. package/api/points.d.ts +8 -10
  38. package/api/points.js +7 -20
  39. package/api/points3.d.ts +13 -0
  40. package/api/points3.js +21 -0
  41. package/api/polygon.d.ts +7 -4
  42. package/api/polygon.js +5 -3
  43. package/api/polygon3.d.ts +14 -0
  44. package/api/polygon3.js +24 -0
  45. package/api/polyline.d.ts +18 -4
  46. package/api/polyline.js +8 -5
  47. package/api/polyline3.d.ts +28 -0
  48. package/api/polyline3.js +31 -0
  49. package/api/quad.d.ts +7 -4
  50. package/api/quad.js +5 -3
  51. package/api/quad3.d.ts +7 -4
  52. package/api/quad3.js +6 -4
  53. package/api/quadratic.d.ts +8 -5
  54. package/api/quadratic.js +12 -6
  55. package/api/quadratic3.d.ts +15 -0
  56. package/api/quadratic3.js +38 -0
  57. package/api/ray.d.ts +4 -3
  58. package/api/ray.js +6 -7
  59. package/api/ray3.d.ts +14 -0
  60. package/api/ray3.js +33 -0
  61. package/api/rect.d.ts +5 -3
  62. package/api/rect.js +11 -8
  63. package/api/sphere.d.ts +4 -3
  64. package/api/sphere.js +8 -5
  65. package/api/text.d.ts +4 -3
  66. package/api/text.js +8 -5
  67. package/api/triangle.d.ts +7 -4
  68. package/api/triangle.js +5 -3
  69. package/api/triangle3.d.ts +14 -0
  70. package/api/triangle3.js +26 -0
  71. package/api.d.ts +193 -0
  72. package/api.js +10 -0
  73. package/apply-transforms.d.ts +33 -11
  74. package/apply-transforms.js +24 -4
  75. package/arc-length.d.ts +18 -4
  76. package/arc-length.js +18 -3
  77. package/arc.d.ts +1 -1
  78. package/area.d.ts +6 -10
  79. package/area.js +3 -3
  80. package/as-cubic.d.ts +31 -5
  81. package/as-cubic.js +86 -24
  82. package/as-path.d.ts +14 -7
  83. package/as-path.js +49 -24
  84. package/as-polygon.d.ts +20 -5
  85. package/as-polygon.js +46 -12
  86. package/as-polyline.d.ts +18 -5
  87. package/as-polyline.js +29 -23
  88. package/as-sector.d.ts +13 -0
  89. package/as-sector.js +18 -0
  90. package/as-svg.d.ts +31 -9
  91. package/as-svg.js +21 -18
  92. package/bounds.d.ts +12 -2
  93. package/bounds.js +15 -0
  94. package/bpatch.d.ts +26 -1
  95. package/center-of-weight.d.ts +22 -0
  96. package/center-of-weight.js +23 -0
  97. package/center.d.ts +11 -5
  98. package/center.js +9 -4
  99. package/centroid-of-bounds.d.ts +12 -0
  100. package/centroid-of-bounds.js +9 -0
  101. package/centroid.d.ts +14 -4
  102. package/centroid.js +16 -17
  103. package/circle.d.ts +1 -1
  104. package/classify-point.d.ts +3 -1
  105. package/classify-point.js +7 -4
  106. package/clip-convex.d.ts +27 -8
  107. package/clip-convex.js +52 -17
  108. package/closest-point.d.ts +1 -1
  109. package/complex-polygon-from-path.d.ts +1 -1
  110. package/complex-polygon.d.ts +1 -1
  111. package/convex-hull.d.ts +9 -2
  112. package/convex-hull.js +3 -3
  113. package/convolve.d.ts +72 -0
  114. package/convolve.js +33 -0
  115. package/cubic.d.ts +1 -1
  116. package/cubic.js +7 -7
  117. package/cubic3.d.ts +8 -0
  118. package/cubic3.js +14 -0
  119. package/edges.d.ts +2 -2
  120. package/ellipse.d.ts +1 -1
  121. package/extra.d.ts +14 -0
  122. package/extra.js +5 -0
  123. package/fit-into-bounds.d.ts +14 -4
  124. package/fit-into-bounds.js +6 -6
  125. package/flip.d.ts +21 -5
  126. package/flip.js +19 -12
  127. package/from-tessellation.d.ts +54 -0
  128. package/from-tessellation.js +27 -0
  129. package/group.d.ts +2 -2
  130. package/group3.d.ts +16 -0
  131. package/group3.js +5 -0
  132. package/index.d.ts +35 -1
  133. package/index.js +35 -1
  134. package/internal/bounds.d.ts +3 -4
  135. package/internal/copy.d.ts +8 -7
  136. package/internal/copy.js +3 -7
  137. package/internal/dispatch.d.ts +1 -1
  138. package/internal/error.d.ts +3 -0
  139. package/internal/error.js +6 -0
  140. package/internal/pclike.d.ts +3 -2
  141. package/internal/pclike.js +6 -0
  142. package/internal/points-as-shape.d.ts +11 -2
  143. package/internal/points-as-shape.js +10 -1
  144. package/internal/split.d.ts +2 -2
  145. package/internal/split.js +13 -8
  146. package/internal/transform.d.ts +6 -22
  147. package/internal/transform.js +2 -21
  148. package/internal/vertices.d.ts +3 -2
  149. package/internal/vertices.js +3 -1
  150. package/intersects.d.ts +5 -4
  151. package/intersects.js +6 -4
  152. package/line.d.ts +1 -1
  153. package/line3.d.ts +6 -0
  154. package/line3.js +9 -0
  155. package/map-point.d.ts +1 -1
  156. package/normalized-path.d.ts +17 -0
  157. package/normalized-path.js +23 -0
  158. package/offset.d.ts +16 -2
  159. package/offset.js +2 -2
  160. package/package.json +149 -35
  161. package/path-builder.d.ts +42 -13
  162. package/path-builder.js +68 -42
  163. package/path-from-cubics.d.ts +26 -0
  164. package/path-from-cubics.js +39 -0
  165. package/path-from-svg.d.ts +1 -1
  166. package/path-from-svg.js +29 -29
  167. package/path.d.ts +2 -52
  168. package/path.js +1 -58
  169. package/path3.d.ts +16 -0
  170. package/path3.js +5 -0
  171. package/plane.d.ts +11 -1
  172. package/plane.js +3 -0
  173. package/point-at.d.ts +1 -1
  174. package/point-inside.d.ts +3 -1
  175. package/point-inside.js +4 -1
  176. package/points.d.ts +2 -3
  177. package/points.js +2 -4
  178. package/points3.d.ts +5 -0
  179. package/points3.js +5 -0
  180. package/polygon.d.ts +5 -5
  181. package/polygon3.d.ts +5 -0
  182. package/polygon3.js +5 -0
  183. package/polyline.d.ts +2 -2
  184. package/polyline3.d.ts +5 -0
  185. package/polyline3.js +5 -0
  186. package/proximity.d.ts +5 -3
  187. package/proximity.js +2 -2
  188. package/quad.d.ts +2 -7
  189. package/quad.js +1 -29
  190. package/quad3.d.ts +8 -0
  191. package/quad3.js +30 -0
  192. package/quadratic.d.ts +1 -1
  193. package/quadratic3.d.ts +7 -0
  194. package/quadratic3.js +11 -0
  195. package/ray.d.ts +1 -1
  196. package/ray.js +2 -2
  197. package/ray3.d.ts +5 -0
  198. package/ray3.js +6 -0
  199. package/rect.d.ts +1 -1
  200. package/resample.d.ts +45 -4
  201. package/resample.js +26 -16
  202. package/rotate-around-axis.d.ts +33 -0
  203. package/rotate-around-axis.js +57 -0
  204. package/rotate.d.ts +15 -2
  205. package/rotate.js +47 -45
  206. package/rounded-rect.d.ts +25 -0
  207. package/rounded-rect.js +18 -0
  208. package/scale-with-center.d.ts +2 -2
  209. package/scale.d.ts +24 -2
  210. package/scale.js +59 -43
  211. package/scatter.d.ts +1 -1
  212. package/simplify.d.ts +8 -2
  213. package/simplify.js +7 -4
  214. package/smooth-poly.d.ts +27 -0
  215. package/smooth-poly.js +11 -0
  216. package/sphere.d.ts +1 -1
  217. package/split-arclength.d.ts +6 -2
  218. package/split-at.d.ts +18 -2
  219. package/split-at.js +66 -34
  220. package/split-near.d.ts +13 -2
  221. package/split-near.js +23 -27
  222. package/subdiv-curve.d.ts +81 -27
  223. package/subdiv-curve.js +44 -28
  224. package/tangent-at.d.ts +1 -1
  225. package/tessellate.d.ts +72 -18
  226. package/tessellate.js +53 -8
  227. package/text.d.ts +1 -1
  228. package/transform-vertices.d.ts +30 -6
  229. package/transform-vertices.js +36 -38
  230. package/transform.d.ts +30 -2
  231. package/transform.js +54 -40
  232. package/translate.d.ts +12 -2
  233. package/translate.js +42 -43
  234. package/triangle.d.ts +1 -1
  235. package/triangle3.d.ts +6 -0
  236. package/triangle3.js +8 -0
  237. package/union.d.ts +11 -2
  238. package/union.js +6 -7
  239. package/unmap-point.d.ts +1 -1
  240. package/vertices.d.ts +3 -3
  241. package/vertices.js +14 -4
  242. package/volume.d.ts +1 -1
  243. package/warp-points.d.ts +35 -4
  244. package/warp-points.js +2 -0
  245. package/with-attribs.d.ts +4 -5
  246. package/internal/rotate.d.ts +0 -5
  247. package/internal/rotate.js +0 -8
  248. package/internal/scale.d.ts +0 -5
  249. package/internal/scale.js +0 -12
  250. package/internal/translate.d.ts +0 -5
  251. 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
+ };
@@ -1,5 +1,20 @@
1
1
  import type { MultiFn1 } from "@thi.ng/defmulti";
2
- import type { IShape } from "@thi.ng/geom-api";
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: A 2x3 (for 2D) or 4x4 (for 3D) transformation matrix
11
- * - translate: Translation/offset vector
12
- * - scale: A scale factor (scalar or vector)
13
- * - rotate: Rotation angle (in radians)
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 last.
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 scale}, {@link translate} to realize individual/partial transformation
25
- * aspects to increase the likelihodd of retaining original shape types. E.g.
26
- * uniformly scaling a circle with a scalar factor retains a circle, but scaling
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: MultiFn1<IShape, IShape>;
54
+ export declare const applyTransforms: ApplyTransformsFn;
33
55
  //# sourceMappingURL=apply-transforms.d.ts.map
@@ -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 = ["transform", "translate", "rotate", "scale"];
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 { transform: tx, translate: t, rotate: r, scale: s } = attribs;
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 "@thi.ng/geom-api";
2
+ import type { IShape } from "./api.js";
3
3
  /**
4
- * Returns the arc length / perimeter / circumference of the given
5
- * shape. For groups calls {@link arcLength} for each child and returns the
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
- tri: "poly"
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, points.length),
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
@@ -1,4 +1,4 @@
1
- import type { Attribs } from "@thi.ng/geom-api";
1
+ import type { Attribs } from "./api.js";
2
2
  import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
3
3
  import { Arc } from "./api/arc.js";
4
4
  /**
package/area.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { MultiFn1O } from "@thi.ng/defmulti";
2
- import type { IShape } from "@thi.ng/geom-api";
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 Line}
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 "@thi.ng/geom-api";
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
- * Converts given shape into an array of {@link Cubic} curves. For some shapes
6
- * (see below) the conversion supports optionally provided {@link CubicOpts}.
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 Quadratic}
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: MultiFn1O<IShape, Partial<CubicOpts>, Cubic[]>;
68
+ export declare const asCubic: AsCubicFn;
43
69
  //# sourceMappingURL=as-cubic.d.ts.map