@bitbybit-dev/base 1.2.0 → 1.3.0-rc.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 (55) hide show
  1. package/lib/api/GlobalCDNProvider.js +1 -1
  2. package/lib/api/inputs/base-inputs.d.ts +13 -12
  3. package/lib/api/inputs/color-inputs.d.ts +97 -48
  4. package/lib/api/inputs/color-inputs.js +95 -46
  5. package/lib/api/inputs/dates-inputs.d.ts +67 -26
  6. package/lib/api/inputs/dates-inputs.js +57 -16
  7. package/lib/api/inputs/io-inputs.d.ts +13 -15
  8. package/lib/api/inputs/io-inputs.js +7 -8
  9. package/lib/api/inputs/line-inputs.d.ts +88 -33
  10. package/lib/api/inputs/line-inputs.js +61 -11
  11. package/lib/api/inputs/lists-inputs.d.ts +207 -96
  12. package/lib/api/inputs/lists-inputs.js +153 -45
  13. package/lib/api/inputs/logic-inputs.d.ts +52 -22
  14. package/lib/api/inputs/logic-inputs.js +41 -12
  15. package/lib/api/inputs/math-inputs.d.ts +113 -52
  16. package/lib/api/inputs/math-inputs.js +112 -51
  17. package/lib/api/inputs/mesh-inputs.d.ts +30 -11
  18. package/lib/api/inputs/mesh-inputs.js +21 -3
  19. package/lib/api/inputs/point-inputs.d.ts +240 -107
  20. package/lib/api/inputs/point-inputs.js +199 -73
  21. package/lib/api/inputs/polyline-inputs.d.ts +68 -28
  22. package/lib/api/inputs/polyline-inputs.js +48 -13
  23. package/lib/api/inputs/text-inputs.d.ts +117 -46
  24. package/lib/api/inputs/text-inputs.js +111 -41
  25. package/lib/api/inputs/transforms-inputs.d.ts +65 -23
  26. package/lib/api/inputs/transforms-inputs.js +64 -22
  27. package/lib/api/inputs/vector-inputs.d.ts +154 -76
  28. package/lib/api/inputs/vector-inputs.js +132 -57
  29. package/lib/api/models/point/hex-grid-data.d.ts +1 -1
  30. package/lib/api/models/point/hex-grid-data.js +1 -1
  31. package/lib/api/services/color.d.ts +149 -70
  32. package/lib/api/services/color.js +149 -70
  33. package/lib/api/services/dates.d.ts +313 -150
  34. package/lib/api/services/dates.js +313 -150
  35. package/lib/api/services/line.d.ts +138 -68
  36. package/lib/api/services/line.js +138 -68
  37. package/lib/api/services/lists.d.ts +357 -177
  38. package/lib/api/services/lists.js +357 -177
  39. package/lib/api/services/logic.d.ts +98 -45
  40. package/lib/api/services/logic.js +98 -45
  41. package/lib/api/services/math.d.ts +363 -211
  42. package/lib/api/services/math.js +363 -211
  43. package/lib/api/services/mesh.d.ts +73 -31
  44. package/lib/api/services/mesh.js +73 -31
  45. package/lib/api/services/point.d.ts +367 -147
  46. package/lib/api/services/point.js +367 -147
  47. package/lib/api/services/polyline.d.ts +146 -71
  48. package/lib/api/services/polyline.js +146 -71
  49. package/lib/api/services/text.d.ts +320 -165
  50. package/lib/api/services/text.js +320 -165
  51. package/lib/api/services/transforms.d.ts +145 -58
  52. package/lib/api/services/transforms.js +145 -58
  53. package/lib/api/services/vector.d.ts +381 -156
  54. package/lib/api/services/vector.js +381 -156
  55. package/package.json +1 -1
@@ -1,7 +1,8 @@
1
1
  /**
2
- * Contains various methods for points. Point in bitbybit is simply an array containing 3 numbers for [x, y,
3
- * z]. Because of this form Point can be interchanged with Vector, which also is an array in [x, y, z] form.
4
- * When creating 2D points, z coordinate is simply set to 0 - [x, y, 0].
2
+ * Points as plain number arrays. A point is `[x, y, z]` with Y pointing up, the same shape as a
3
+ * vector, so the two can be passed to each other's methods; a 2D point is `[x, y]`. Every method
4
+ * returns new points or numbers and never changes its inputs. Angles are in degrees and lengths in
5
+ * model units.
5
6
  */
6
7
  export class Point {
7
8
  constructor(geometryHelper, transforms, vector, lists) {
@@ -11,13 +12,21 @@ export class Point {
11
12
  this.lists = lists;
12
13
  }
13
14
  /**
14
- * Applies transformation matrix to a single point (rotates, scales, or translates).
15
- * Example: point=[0,0,0] with translation [5,5,0] → [5,5,0]
16
- * @param inputs Contains a point and the transformations to apply
17
- * @returns Transformed point
15
+ * Applies a transformation matrix, or a list of them in order, to one point.
16
+ *
17
+ * Example: point [0,0,0] with a translation by [5,5,0] -> [5,5,0]
18
+ * @param inputs - The point and the transformation to apply
19
+ * @returns The transformed point
18
20
  * @group transforms
19
21
  * @shortname transform point
20
22
  * @drawable true
23
+ * @example
24
+ * ```typescript
25
+ * const moved = bitbybit.point.transformPoint({
26
+ * point: [0, 0, 0],
27
+ * transformation: bitbybit.transforms.translationXYZ({ translation: [5, 5, 0] }),
28
+ * });
29
+ * ```
21
30
  */
22
31
  transformPoint(inputs) {
23
32
  const transformation = inputs.transformation;
@@ -26,26 +35,43 @@ export class Point {
26
35
  return transformedControlPoints[0];
27
36
  }
28
37
  /**
29
- * Applies same transformation matrix to multiple points (batch transform).
30
- * Example: 5 points with rotation 90° → all 5 points rotated together
31
- * @param inputs Contains points and the transformations to apply
32
- * @returns Transformed points
38
+ * Applies the same transformation matrix, or list of them in order, to every point.
39
+ *
40
+ * Example: five points with a 90 degree rotation -> all five rotated together
41
+ * @param inputs - The points and the transformation to apply to each
42
+ * @returns The transformed points, in the same order
33
43
  * @group transforms
34
44
  * @shortname transform points
35
45
  * @drawable true
46
+ * @example
47
+ * ```typescript
48
+ * const rotated = bitbybit.point.transformPoints({
49
+ * points: [[1, 0, 0], [2, 0, 0]],
50
+ * transformation: bitbybit.transforms.rotationCenterAxis({ center: [0, 0, 0], axis: [0, 1, 0], angle: 90 }),
51
+ * });
52
+ * ```
36
53
  */
37
54
  transformPoints(inputs) {
38
55
  return this.geometryHelper.transformControlPoints(inputs.transformation, inputs.points);
39
56
  }
40
57
  /**
41
- * Applies different transformation matrices to corresponding points (one transform per point).
42
- * Arrays must have equal length.
43
- * Example: 3 points with 3 different translations → each point moved independently
44
- * @param inputs Contains points and the transformations to apply
45
- * @returns Transformed points
58
+ * Applies a different transformation to each point: the first transformation to the first
59
+ * point, and so on.
60
+ *
61
+ * The two lists must have the same length, or an error is thrown.
62
+ * Example: three points with three translations -> each point moved by its own translation
63
+ * @param inputs - The points and one transformation per point
64
+ * @returns The transformed points, in the same order
46
65
  * @group transforms
47
66
  * @shortname transforms for points
48
67
  * @drawable true
68
+ * @example
69
+ * ```typescript
70
+ * const placed = bitbybit.point.transformsForPoints({
71
+ * points: [[0, 0, 0], [1, 0, 0]],
72
+ * transformation: bitbybit.transforms.translationsXYZ({ translations: [[0, 1, 0], [0, 2, 0]] }),
73
+ * });
74
+ * ```
49
75
  */
50
76
  transformsForPoints(inputs) {
51
77
  if (inputs.points.length !== inputs.transformation.length) {
@@ -56,27 +82,40 @@ export class Point {
56
82
  });
57
83
  }
58
84
  /**
59
- * Moves multiple points by a translation vector (same offset for all points).
60
- * Example: points=[[0,0,0], [1,0,0]], translation=[5,5,0] → [[5,5,0], [6,5,0]]
61
- * @param inputs Contains points and the translation vector
62
- * @returns Translated points
85
+ * Moves every point by the same vector.
86
+ *
87
+ * Example: points [[0,0,0], [1,0,0]] by [5,5,0] -> [[5,5,0], [6,5,0]]
88
+ * @param inputs - The points and the vector to move them by
89
+ * @returns The moved points, in the same order
63
90
  * @group transforms
64
91
  * @shortname translate points
65
92
  * @drawable true
93
+ * @example
94
+ * ```typescript
95
+ * const moved = bitbybit.point.translatePoints({ points: [[0, 0, 0], [1, 0, 0]], translation: [5, 5, 0] });
96
+ * ```
66
97
  */
67
98
  translatePoints(inputs) {
68
99
  const translationTransform = this.transforms.translationXYZ({ translation: inputs.translation });
69
100
  return this.geometryHelper.transformControlPoints(translationTransform, inputs.points);
70
101
  }
71
102
  /**
72
- * Moves multiple points by corresponding translation vectors (one vector per point).
73
- * Arrays must have equal length.
74
- * Example: 3 points with 3 different vectors → each point moved by its corresponding vector
75
- * @param inputs Contains points and the translation vector
76
- * @returns Translated points
103
+ * Moves each point by its own vector: the first point by the first vector, and so on.
104
+ *
105
+ * The two lists must have the same length, or an error is thrown.
106
+ * Example: three points with three vectors -> each point moved by its own vector
107
+ * @param inputs - The points and one vector per point
108
+ * @returns The moved points, in the same order
77
109
  * @group transforms
78
110
  * @shortname translate points with vectors
79
111
  * @drawable true
112
+ * @example
113
+ * ```typescript
114
+ * const moved = bitbybit.point.translatePointsWithVectors({
115
+ * points: [[0, 0, 0], [1, 0, 0]],
116
+ * translations: [[0, 1, 0], [0, 2, 0]],
117
+ * });
118
+ * ```
80
119
  */
81
120
  translatePointsWithVectors(inputs) {
82
121
  if (inputs.points.length !== inputs.translations.length) {
@@ -88,65 +127,108 @@ export class Point {
88
127
  });
89
128
  }
90
129
  /**
91
- * Moves multiple points by separate X, Y, Z values (convenience method for translation).
92
- * Example: points=[[0,0,0]], x=10, y=5, z=0 → [[10,5,0]]
93
- * @param inputs Contains points and the translation in x y and z
94
- * @returns Translated points
130
+ * Moves every point by the given x, y and z amounts.
131
+ *
132
+ * Example: point [0,0,0] with x=10, y=5, z=0 -> [10,5,0]
133
+ * @param inputs - The points and the distance to move along each axis
134
+ * @returns The moved points, in the same order
95
135
  * @group transforms
96
136
  * @shortname translate xyz points
97
137
  * @drawable true
138
+ * @example
139
+ * ```typescript
140
+ * const lifted = bitbybit.point.translateXYZPoints({ points: [[0, 0, 0], [1, 0, 0]], x: 0, y: 5, z: 0 });
141
+ * ```
98
142
  */
99
143
  translateXYZPoints(inputs) {
100
144
  const translationTransform = this.transforms.translationXYZ({ translation: [inputs.x, inputs.y, inputs.z] });
101
145
  return this.geometryHelper.transformControlPoints(translationTransform, inputs.points);
102
146
  }
103
147
  /**
104
- * Scales multiple points around a center point with different factors per axis.
105
- * Example: points=[[10,0,0]], center=[5,0,0], scaleXyz=[2,1,1] → [[15,0,0]] (doubles X distance from center)
106
- * @param inputs Contains points, center point and scale factors
107
- * @returns Scaled points
148
+ * Scales points away from or toward a center, with its own factor per axis.
149
+ *
150
+ * Example: point [10,0,0] about center [5,0,0] with factors [2,1,1] -> [15,0,0]
151
+ * @param inputs - The points, the center to scale about and the factor per axis
152
+ * @returns The scaled points, in the same order
108
153
  * @group transforms
109
154
  * @shortname scale points on center
110
155
  * @drawable true
156
+ * @example
157
+ * ```typescript
158
+ * const stretched = bitbybit.point.scalePointsCenterXYZ({
159
+ * points: [[10, 0, 0], [0, 10, 0]],
160
+ * center: [0, 0, 0],
161
+ * scaleXyz: [2, 1, 1],
162
+ * });
163
+ * ```
111
164
  */
112
165
  scalePointsCenterXYZ(inputs) {
113
166
  const scaleTransforms = this.transforms.scaleCenterXYZ({ center: inputs.center, scaleXyz: inputs.scaleXyz });
114
167
  return this.geometryHelper.transformControlPoints(scaleTransforms, inputs.points);
115
168
  }
116
169
  /**
117
- * Stretches multiple points along a direction from a center point (directional scaling).
118
- * Example: points=[[10,0,0]], center=[0,0,0], direction=[1,0,0], scale=2 → [[20,0,0]]
119
- * @param inputs Contains points, center point, direction and scale factor
120
- * @returns Stretched points
170
+ * Stretches points along one direction, measured from a center; distances across that direction
171
+ * stay as they are.
172
+ *
173
+ * Example: point [10,0,0] from center [0,0,0] along [1,0,0] with scale 2 -> [20,0,0]
174
+ * @param inputs - The points, the center, the direction to stretch along and the factor
175
+ * @returns The stretched points, in the same order
121
176
  * @group transforms
122
177
  * @shortname stretch points dir from center
123
178
  * @drawable true
179
+ * @example
180
+ * ```typescript
181
+ * const taller = bitbybit.point.stretchPointsDirFromCenter({
182
+ * points: [[0, 1, 0], [0, 2, 0]],
183
+ * center: [0, 0, 0],
184
+ * direction: [0, 1, 0],
185
+ * scale: 2,
186
+ * });
187
+ * ```
124
188
  */
125
189
  stretchPointsDirFromCenter(inputs) {
126
190
  const stretchTransforms = this.transforms.stretchDirFromCenter({ center: inputs.center, scale: inputs.scale, direction: inputs.direction });
127
191
  return this.geometryHelper.transformControlPoints(stretchTransforms, inputs.points);
128
192
  }
129
193
  /**
130
- * Rotates multiple points around a center point along a custom axis.
131
- * Example: points=[[10,0,0]], center=[0,0,0], axis=[0,1,0], angle=90° → [[0,0,-10]]
132
- * @param inputs Contains points, axis, center point and angle of rotation
133
- * @returns Rotated points
194
+ * Rotates points around an axis that passes through a center.
195
+ *
196
+ * The angle is in degrees and turns counter-clockwise when the axis points toward you.
197
+ * Example: point [10,0,0] around the Y axis through [0,0,0] by 90 -> [0,0,-10]
198
+ * @param inputs - The points, the axis direction, the center it passes through and the angle in degrees
199
+ * @returns The rotated points, in the same order
134
200
  * @group transforms
135
201
  * @shortname rotate points center axis
136
202
  * @drawable true
203
+ * @example
204
+ * ```typescript
205
+ * const turned = bitbybit.point.rotatePointsCenterAxis({
206
+ * points: [[10, 0, 0]],
207
+ * center: [0, 0, 0],
208
+ * axis: [0, 1, 0],
209
+ * angle: 90,
210
+ * });
211
+ * ```
137
212
  */
138
213
  rotatePointsCenterAxis(inputs) {
139
214
  const rotationTransforms = this.transforms.rotationCenterAxis({ center: inputs.center, axis: inputs.axis, angle: inputs.angle });
140
215
  return this.geometryHelper.transformControlPoints(rotationTransforms, inputs.points);
141
216
  }
142
217
  /**
143
- * Calculates axis-aligned bounding box containing all points (min, max, center, width, height, length).
144
- * Example: points=[[0,0,0], [10,5,3]] → {min:[0,0,0], max:[10,5,3], center:[5,2.5,1.5], width:10, height:5, length:3}
145
- * @param inputs Points
146
- * @returns Bounding box of points
218
+ * Finds the smallest axis-aligned box that holds all the points.
219
+ *
220
+ * The result carries the min and max corners, the center, and the width (X), height (Y) and
221
+ * length (Z).
222
+ * Example: points [[0,0,0], [10,5,3]] -> min [0,0,0], max [10,5,3], center [5,2.5,1.5]
223
+ * @param inputs - The points to enclose
224
+ * @returns The bounding box with its corners, center and sizes
147
225
  * @group extract
148
226
  * @shortname bounding box pts
149
227
  * @drawable true
228
+ * @example
229
+ * ```typescript
230
+ * const box = bitbybit.point.boundingBoxOfPoints({ points: [[0, 0, 0], [10, 5, 3], [-2, 1, 1]] });
231
+ * ```
150
232
  */
151
233
  boundingBoxOfPoints(inputs) {
152
234
  const xVals = [];
@@ -177,49 +259,69 @@ export class Point {
177
259
  };
178
260
  }
179
261
  /**
180
- * Calculates distance to the nearest point in a collection.
181
- * Example: point=[0,0,0], points=[[5,0,0], [10,0,0], [3,0,0]] → 3 (distance to [3,0,0])
182
- * @param inputs Point from which to measure and points to measure the distance against
183
- * @returns Distance to closest point
262
+ * Measures the distance from a point to the nearest point in a list.
263
+ *
264
+ * Example: point [0,0,0] and points [[5,0,0], [10,0,0], [3,0,0]] -> 3
265
+ * @param inputs - The point to measure from and the points to search
266
+ * @returns The distance to the nearest point, in model units
184
267
  * @group extract
185
268
  * @shortname distance to closest pt
186
269
  * @drawable false
270
+ * @example
271
+ * ```typescript
272
+ * const nearest = bitbybit.point.closestPointFromPointsDistance({ point: [0, 0, 0], points: [[5, 0, 0], [3, 0, 0]] });
273
+ * ```
187
274
  */
188
275
  closestPointFromPointsDistance(inputs) {
189
276
  return this.closestPointFromPointData(inputs).distance;
190
277
  }
191
278
  /**
192
- * Finds array index of the nearest point in a collection (1-based index, not 0-based).
193
- * Example: point=[0,0,0], points=[[5,0,0], [10,0,0], [3,0,0]] → 3 (index of [3,0,0])
194
- * @param inputs Point from which to find the index in a collection of points
195
- * @returns Closest point index
279
+ * Finds the position of the nearest point in a list, counted from 1.
280
+ *
281
+ * Example: point [0,0,0] and points [[5,0,0], [10,0,0], [3,0,0]] -> 3
282
+ * @param inputs - The point to measure from and the points to search
283
+ * @returns The 1-based index of the nearest point
196
284
  * @group extract
197
285
  * @shortname index of closest pt
198
286
  * @drawable false
287
+ * @example
288
+ * ```typescript
289
+ * const index = bitbybit.point.closestPointFromPointsIndex({ point: [0, 0, 0], points: [[5, 0, 0], [3, 0, 0]] });
290
+ * ```
199
291
  */
200
292
  closestPointFromPointsIndex(inputs) {
201
293
  return this.closestPointFromPointData(inputs).index;
202
294
  }
203
295
  /**
204
- * Finds the nearest point in a collection to a reference point.
205
- * Example: point=[0,0,0], points=[[5,0,0], [10,0,0], [3,0,0]] → [3,0,0]
206
- * @param inputs Point and points collection to find the closest point in
207
- * @returns Closest point
296
+ * Finds the nearest point in a list to a given point.
297
+ *
298
+ * Example: point [0,0,0] and points [[5,0,0], [10,0,0], [3,0,0]] -> [3,0,0]
299
+ * @param inputs - The point to measure from and the points to search
300
+ * @returns The nearest point
208
301
  * @group extract
209
302
  * @shortname closest pt
210
303
  * @drawable true
304
+ * @example
305
+ * ```typescript
306
+ * const nearest = bitbybit.point.closestPointFromPoints({ point: [0, 0, 0], points: [[5, 0, 0], [3, 0, 0]] });
307
+ * ```
211
308
  */
212
309
  closestPointFromPoints(inputs) {
213
310
  return this.closestPointFromPointData(inputs).point;
214
311
  }
215
312
  /**
216
- * Calculates Euclidean distance between two points.
217
- * Example: start=[0,0,0], end=[3,4,0] → 5 (using Pythagorean theorem: √(3²+4²))
218
- * @param inputs Coordinates of start and end points
219
- * @returns Distance
313
+ * Measures the straight-line distance between two points.
314
+ *
315
+ * Example: [0,0,0] to [3,4,0] -> 5
316
+ * @param inputs - The two points
317
+ * @returns The distance in model units
220
318
  * @group measure
221
319
  * @shortname distance
222
320
  * @drawable false
321
+ * @example
322
+ * ```typescript
323
+ * const d = bitbybit.point.distance({ startPoint: [0, 0, 0], endPoint: [3, 4, 0] });
324
+ * ```
223
325
  */
224
326
  distance(inputs) {
225
327
  const x = inputs.endPoint[0] - inputs.startPoint[0];
@@ -228,13 +330,18 @@ export class Point {
228
330
  return Math.sqrt(x * x + y * y + z * z);
229
331
  }
230
332
  /**
231
- * Calculates distances from a start point to multiple end points.
232
- * Example: start=[0,0,0], endPoints=[[3,0,0], [0,4,0], [5,0,0]] → [3, 4, 5]
233
- * @param inputs Coordinates of start and end points
234
- * @returns Distances
333
+ * Measures the distance from one point to each point in a list.
334
+ *
335
+ * Example: start [0,0,0] and end points [[3,0,0], [0,4,0], [5,0,0]] -> [3, 4, 5]
336
+ * @param inputs - The start point and the points to measure to
337
+ * @returns One distance per end point, in the same order
235
338
  * @group measure
236
339
  * @shortname distances to points
237
340
  * @drawable false
341
+ * @example
342
+ * ```typescript
343
+ * const distances = bitbybit.point.distancesToPoints({ startPoint: [0, 0, 0], endPoints: [[3, 0, 0], [0, 4, 0]] });
344
+ * ```
238
345
  */
239
346
  distancesToPoints(inputs) {
240
347
  return inputs.endPoints.map(pt => {
@@ -242,13 +349,18 @@ export class Point {
242
349
  });
243
350
  }
244
351
  /**
245
- * Duplicates a point N times (creates array with N copies of the same point).
246
- * Example: point=[5,5,0], amountOfPoints=3 → [[5,5,0], [5,5,0], [5,5,0]]
247
- * @param inputs The point to be multiplied and the amount of points to create
248
- * @returns Distance
352
+ * Repeats one point a given number of times in a list.
353
+ *
354
+ * Example: point [5,5,0] three times -> [[5,5,0], [5,5,0], [5,5,0]]
355
+ * @param inputs - The point and how many copies to make
356
+ * @returns The list of copies
249
357
  * @group transforms
250
358
  * @shortname multiply point
251
359
  * @drawable true
360
+ * @example
361
+ * ```typescript
362
+ * const copies = bitbybit.point.multiplyPoint({ point: [5, 5, 0], amountOfPoints: 3 });
363
+ * ```
252
364
  */
253
365
  multiplyPoint(inputs) {
254
366
  const points = [];
@@ -258,10 +370,11 @@ export class Point {
258
370
  return points;
259
371
  }
260
372
  /**
261
- * Extracts X coordinate from a point.
262
- * Example: point=[5,10,3] → 5
263
- * @param inputs The point
264
- * @returns X coordinate
373
+ * Reads the X value of a point.
374
+ *
375
+ * Example: [5,10,3] -> 5
376
+ * @param inputs - The point
377
+ * @returns The X value
265
378
  * @group get
266
379
  * @shortname x coord
267
380
  * @drawable false
@@ -270,10 +383,11 @@ export class Point {
270
383
  return inputs.point[0];
271
384
  }
272
385
  /**
273
- * Extracts Y coordinate from a point.
274
- * Example: point=[5,10,3] → 10
275
- * @param inputs The point
276
- * @returns Y coordinate
386
+ * Reads the Y value of a point, the one that points up.
387
+ *
388
+ * Example: [5,10,3] -> 10
389
+ * @param inputs - The point
390
+ * @returns The Y value
277
391
  * @group get
278
392
  * @shortname y coord
279
393
  * @drawable false
@@ -282,10 +396,11 @@ export class Point {
282
396
  return inputs.point[1];
283
397
  }
284
398
  /**
285
- * Extracts Z coordinate from a point.
286
- * Example: point=[5,10,3] → 3
287
- * @param inputs The point
288
- * @returns Z coordinate
399
+ * Reads the Z value of a point.
400
+ *
401
+ * Example: [5,10,3] -> 3
402
+ * @param inputs - The point
403
+ * @returns The Z value
289
404
  * @group get
290
405
  * @shortname z coord
291
406
  * @drawable false
@@ -294,13 +409,18 @@ export class Point {
294
409
  return inputs.point[2];
295
410
  }
296
411
  /**
297
- * Calculates centroid (average position) of multiple points.
298
- * Example: points=[[0,0,0], [10,0,0], [10,10,0]] → [6.67,3.33,0]
299
- * @param inputs The points
300
- * @returns point
412
+ * Finds the average of the points, which is their center of mass when they weigh the same.
413
+ *
414
+ * Example: [[0,0,0], [10,0,0], [10,10,0]] -> [6.67,3.33,0]
415
+ * @param inputs - The points to average
416
+ * @returns The average point
301
417
  * @group extract
302
418
  * @shortname average point
303
419
  * @drawable true
420
+ * @example
421
+ * ```typescript
422
+ * const center = bitbybit.point.averagePoint({ points: [[0, 0, 0], [10, 0, 0], [10, 10, 0]] });
423
+ * ```
304
424
  */
305
425
  averagePoint(inputs) {
306
426
  const xVals = [];
@@ -318,38 +438,54 @@ export class Point {
318
438
  ];
319
439
  }
320
440
  /**
321
- * Creates a 3D point from X, Y, Z coordinates.
322
- * Example: x=10, y=5, z=3 → [10,5,3]
323
- * @param inputs xyz information
324
- * @returns point 3d
441
+ * Builds a 3D point from its x, y and z values.
442
+ *
443
+ * Example: x=10, y=5, z=3 -> [10,5,3]
444
+ * @param inputs - The three values
445
+ * @returns The point `[x, y, z]`
325
446
  * @group create
326
447
  * @shortname point xyz
327
448
  * @drawable true
449
+ * @example
450
+ * ```typescript
451
+ * const point = bitbybit.point.pointXYZ({ x: 10, y: 5, z: 3 });
452
+ * ```
328
453
  */
329
454
  pointXYZ(inputs) {
330
455
  return [inputs.x, inputs.y, inputs.z];
331
456
  }
332
457
  /**
333
- * Creates a 2D point from X, Y coordinates.
334
- * Example: x=10, y=5 → [10,5]
335
- * @param inputs xy information
336
- * @returns point 3d
458
+ * Builds a 2D point from its x and y values.
459
+ *
460
+ * Example: x=10, y=5 -> [10,5]
461
+ * @param inputs - The two values
462
+ * @returns The point `[x, y]`
337
463
  * @group create
338
464
  * @shortname point xy
339
465
  * @drawable false
466
+ * @example
467
+ * ```typescript
468
+ * const point = bitbybit.point.pointXY({ x: 10, y: 5 });
469
+ * ```
340
470
  */
341
471
  pointXY(inputs) {
342
472
  return [inputs.x, inputs.y];
343
473
  }
344
474
  /**
345
- * Creates logarithmic spiral points using golden angle or custom widening factor.
346
- * Generates natural spiral patterns common in nature (sunflower, nautilus shell).
347
- * Example: numberPoints=100, radius=10, phi=1.618 → 100 points forming outward spiral
348
- * @param inputs Spiral information
349
- * @returns Specified number of points in the array along the spiral
475
+ * Lays out points along a logarithmic spiral in the XY plane, from the origin outward to
476
+ * `radius`.
477
+ *
478
+ * `numberPoints` sets how many points are placed, `phi` and `widening` how quickly the spiral
479
+ * opens, and `factor` where along the curve it starts. Every point has z = 0.
480
+ * @param inputs - The point count, the radius and the shape of the spiral
481
+ * @returns The points along the spiral, from the center outward
350
482
  * @group create
351
483
  * @shortname spiral
352
484
  * @drawable true
485
+ * @example
486
+ * ```typescript
487
+ * const points = bitbybit.point.spiral({ phi: 0.9, numberPoints: 100, widening: 3, radius: 10, factor: 1 });
488
+ * ```
353
489
  */
354
490
  spiral(inputs) {
355
491
  const phi = inputs.phi;
@@ -365,14 +501,20 @@ export class Point {
365
501
  return spiral;
366
502
  }
367
503
  /**
368
- * Creates hexagonal grid center points on XY plane (honeycomb pattern).
369
- * Grid size controlled by number of hexagons, not width/height.
370
- * Example: radiusHexagon=1, nrHexagonsX=3, nrHexagonsY=3 → 9 hex centers in grid pattern
371
- * @param inputs Information about hexagon and the grid
372
- * @returns Points in the array on the grid
504
+ * Lays out the centers of a honeycomb of hexagons in the XY plane.
505
+ *
506
+ * `radiusHexagon` is the distance from a hexagon's center to a corner; columns run along X and
507
+ * rows along Y, every second row shifted by half a column. `orientOnCenter` centers the grid on
508
+ * the origin, `pointsOnGround` lays it on the XZ plane.
509
+ * @param inputs - The hexagon size, how many columns and rows, and where to place the grid
510
+ * @returns The center points, row by row
373
511
  * @group create
374
512
  * @shortname hex grid
375
513
  * @drawable true
514
+ * @example
515
+ * ```typescript
516
+ * const centers = bitbybit.point.hexGrid({ radiusHexagon: 1, nrHexagonsX: 5, nrHexagonsY: 4, orientOnCenter: true, pointsOnGround: false });
517
+ * ```
376
518
  */
377
519
  hexGrid(inputs) {
378
520
  const xLength = Math.sqrt(Math.pow(inputs.radiusHexagon, 2) - Math.pow(inputs.radiusHexagon / 2, 2));
@@ -400,14 +542,28 @@ export class Point {
400
542
  return points;
401
543
  }
402
544
  /**
403
- * Creates hexagonal grid scaled to fit within specified width/height bounds (auto-calculates hex size).
404
- * Returns center points and hex vertices. Supports pointy-top or flat-top orientation.
405
- * Example: width=10, height=10, nrHexagonsInHeight=3 → hex grid filling 10×10 area with 3 rows
406
- * @param inputs Information about the desired grid dimensions and hexagon counts.
407
- * @returns An object containing the array of center points and an array of hexagon vertex arrays.
545
+ * Lays out a honeycomb of hexagons that fills a given width and height, sizing the hexagons
546
+ * from the counts.
547
+ *
548
+ * The result carries the center points and the six corners of every hexagon. A corner points up
549
+ * unless `flatTop` is set; the extend flags stretch the outer rows past the edges to cover the
550
+ * rectangle without a jagged border.
551
+ * @param inputs - The area to fill, the hexagon counts, the orientation and the placement options
552
+ * @returns The centers and the corner points of every hexagon
408
553
  * @group create
409
554
  * @shortname scaled hex grid to fit
410
555
  * @drawable false
556
+ * @example
557
+ * ```typescript
558
+ * const grid = bitbybit.point.hexGridScaledToFit({
559
+ * width: 10,
560
+ * height: 10,
561
+ * nrHexagonsInWidth: 5,
562
+ * nrHexagonsInHeight: 5,
563
+ * flatTop: false,
564
+ * centerGrid: true,
565
+ * });
566
+ * ```
411
567
  */
412
568
  hexGridScaledToFit(inputs) {
413
569
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
@@ -673,14 +829,21 @@ export class Point {
673
829
  };
674
830
  }
675
831
  /**
676
- * Calculates the maximum possible fillet radius at a corner formed by two line segments
677
- * sharing an endpoint (C), such that the fillet arc is tangent to both segments
678
- * and lies entirely within them.
679
- * @param inputs three points and the tolerance
680
- * @returns the maximum fillet radius
832
+ * Finds the largest fillet that fits a corner: the arc touches both segments and stays inside
833
+ * them.
834
+ *
835
+ * The corner is `end`; `start` and `center` are the far ends of the two segments that meet
836
+ * there. The radius is limited by the shorter segment. A straight or folded-back corner, or a
837
+ * segment shorter than `tolerance`, gives 0.
838
+ * @param inputs - The far end of each segment, the corner they share, and the tolerance
839
+ * @returns The largest fillet radius, in model units
681
840
  * @group fillet
682
841
  * @shortname max fillet radius
683
842
  * @drawable false
843
+ * @example
844
+ * ```typescript
845
+ * const radius = bitbybit.point.maxFilletRadius({ start: [10, 0, 0], center: [0, 10, 0], end: [0, 0, 0], tolerance: 1e-7 });
846
+ * ```
684
847
  */
685
848
  maxFilletRadius(inputs) {
686
849
  const { start: p1, center: p2, end: c, tolerance = 1e-7 } = inputs;
@@ -712,14 +875,20 @@ export class Point {
712
875
  return maxRadius;
713
876
  }
714
877
  /**
715
- * Calculates the maximum possible fillet radius at a corner C, such that the fillet arc
716
- * is tangent to both segments (P1-C, P2-C) and the tangent points lie within
717
- * the first half of each segment (measured from C).
718
- * @param inputs three points and the tolerance
719
- * @returns the maximum fillet radius
878
+ * Finds the largest fillet at a corner whose arc touches each segment within its nearer half,
879
+ * so neighboring corners of a polyline can each be filleted without the arcs overlapping.
880
+ *
881
+ * The corner is `end`; `start` and `center` are the far ends of the two segments. A straight or
882
+ * folded-back corner, or a segment shorter than `tolerance`, gives 0.
883
+ * @param inputs - The far end of each segment, the corner they share, and the tolerance
884
+ * @returns The largest fillet radius under the half-segment rule, in model units
720
885
  * @group fillet
721
886
  * @shortname max fillet radius half line
722
887
  * @drawable false
888
+ * @example
889
+ * ```typescript
890
+ * const radius = bitbybit.point.maxFilletRadiusHalfLine({ start: [10, 0, 0], center: [0, 10, 0], end: [0, 0, 0], tolerance: 1e-7 });
891
+ * ```
723
892
  */
724
893
  maxFilletRadiusHalfLine(inputs) {
725
894
  const { start: p1, center: p2, end: c, tolerance = 1e-7 } = inputs;
@@ -748,14 +917,24 @@ export class Point {
748
917
  return maxRadius;
749
918
  }
750
919
  /**
751
- * Calculates the maximum possible fillet radius at each corner of a polyline formed by
752
- * formed by a series of points. The fillet radius is calculated for each internal
753
- * corner and optionally for the closing corners if the polyline is closed.
754
- * @param inputs Points, checkLastWithFirst flag, and tolerance
755
- * @returns Array of maximum fillet radii for each corner
920
+ * Finds the largest fillet for every corner of a polyline, each limited to the nearer half of
921
+ * its segments so the fillets never overlap.
922
+ *
923
+ * With `checkLastWithFirst` on, the polyline is treated as closed and the two corners at the
924
+ * ends are included. Fewer than three points give an empty list.
925
+ * @param inputs - The polyline points, whether it is closed, and the tolerance
926
+ * @returns One radius per corner, in the order of the corners
756
927
  * @group fillet
757
928
  * @shortname max fillets half line
758
929
  * @drawable false
930
+ * @example
931
+ * ```typescript
932
+ * const radii = bitbybit.point.maxFilletsHalfLine({
933
+ * points: [[0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]],
934
+ * checkLastWithFirst: true,
935
+ * tolerance: 1e-7,
936
+ * });
937
+ * ```
759
938
  */
760
939
  maxFilletsHalfLine(inputs) {
761
940
  const { points, checkLastWithFirst = false, tolerance = 1e-7 } = inputs;
@@ -801,17 +980,24 @@ export class Point {
801
980
  return results;
802
981
  }
803
982
  /**
804
- * Calculates the single safest maximum fillet radius that can be applied
805
- * uniformly to all corners of collection of points, based on the 'half-line' constraint.
806
- * This is determined by finding the minimum of the maximum possible fillet
807
- * radii calculated for each individual corner.
808
- * @param inputs Defines the points, whether it's closed, and an optional tolerance.
809
- * @returns The smallest value from the results of pointsMaxFilletsHalfLine.
810
- * Returns 0 if the polyline has fewer than 3 points or if any
811
- * calculated maximum radius is 0.
983
+ * Finds one fillet radius that fits every corner of a polyline: the smallest of the per-corner
984
+ * maximums under the half-segment rule.
985
+ *
986
+ * With `checkLastWithFirst` on, the polyline is treated as closed. Fewer than three points, or
987
+ * any corner that allows no fillet, give 0.
988
+ * @param inputs - The polyline points, whether it is closed, and the tolerance
989
+ * @returns The radius that fits every corner, in model units
812
990
  * @group fillet
813
991
  * @shortname safest fillet radii points
814
992
  * @drawable false
993
+ * @example
994
+ * ```typescript
995
+ * const radius = bitbybit.point.safestPointsMaxFilletHalfLine({
996
+ * points: [[0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]],
997
+ * checkLastWithFirst: true,
998
+ * tolerance: 1e-7,
999
+ * });
1000
+ * ```
815
1001
  */
816
1002
  safestPointsMaxFilletHalfLine(inputs) {
817
1003
  const allMaxRadii = this.maxFilletsHalfLine(inputs);
@@ -822,25 +1008,49 @@ export class Point {
822
1008
  return Math.max(0, safestRadius);
823
1009
  }
824
1010
  /**
825
- * Removes consecutive duplicate points from array within tolerance.
826
- * Example: [[0,0,0], [0,0,0], [1,0,0], [1,0,0], [2,0,0]] → [[0,0,0], [1,0,0], [2,0,0]]
827
- * @param inputs points, tolerance and check first and last
828
- * @returns Points in the array without consecutive duplicates
1011
+ * Removes a point when it repeats the one right before it; the same point further away is kept.
1012
+ *
1013
+ * With `checkFirstAndLast` on, a last point that repeats the first is dropped too. Points
1014
+ * within `tolerance` of each other count as the same.
1015
+ * Example: [[0,0,0], [0,0,0], [1,0,0], [1,0,0], [2,0,0]] -> [[0,0,0], [1,0,0], [2,0,0]]
1016
+ * @param inputs - The points, the tolerance and whether to compare the first and last
1017
+ * @returns The points without consecutive repeats
829
1018
  * @group clean
830
1019
  * @shortname remove duplicates
831
1020
  * @drawable true
1021
+ * @example
1022
+ * ```typescript
1023
+ * const cleaned = bitbybit.point.removeConsecutiveDuplicates({
1024
+ * points: [[0, 0, 0], [0, 0, 0], [1, 0, 0]],
1025
+ * tolerance: 1e-7,
1026
+ * checkFirstAndLast: false,
1027
+ * });
1028
+ * ```
832
1029
  */
833
1030
  removeConsecutiveDuplicates(inputs) {
834
1031
  return this.geometryHelper.removeConsecutivePointDuplicates(inputs.points, inputs.checkFirstAndLast, inputs.tolerance);
835
1032
  }
836
1033
  /**
837
- * Calculates normal vector from three points using cross product (perpendicular to plane).
838
- * Example: p1=[0,0,0], p2=[1,0,0], p3=[0,1,0] → [0,0,1] (pointing up from XY plane)
839
- * @param inputs Three points and the reverse normal flag
840
- * @returns Normal vector
1034
+ * Finds the direction at right angles to the plane through three points, with length 1.
1035
+ *
1036
+ * The direction follows the right-hand rule going from the first point to the second to the
1037
+ * third; `reverseNormal` flips it. Points on one line have no plane, so the result is
1038
+ * undefined.
1039
+ * Example: [0,0,0], [1,0,0], [0,1,0] -> [0,0,1]
1040
+ * @param inputs - The three points and whether to flip the result
1041
+ * @returns The unit normal, or undefined when the points are on one line
841
1042
  * @group create
842
1043
  * @shortname normal from 3 points
843
1044
  * @drawable true
1045
+ * @example
1046
+ * ```typescript
1047
+ * const normal = bitbybit.point.normalFromThreePoints({
1048
+ * point1: [0, 0, 0],
1049
+ * point2: [1, 0, 0],
1050
+ * point3: [0, 1, 0],
1051
+ * reverseNormal: false,
1052
+ * });
1053
+ * ```
844
1054
  */
845
1055
  normalFromThreePoints(inputs) {
846
1056
  const p1 = inputs.point1;
@@ -885,13 +1095,18 @@ export class Point {
885
1095
  return { index: closestPointIndex + 1, distance, point };
886
1096
  }
887
1097
  /**
888
- * Checks if two points are approximately equal within tolerance (distance-based comparison).
889
- * Example: point1=[1.0000001, 2.0, 3.0], point2=[1.0, 2.0, 3.0], tolerance=1e-6 → true
890
- * @param inputs Two points and the tolerance
891
- * @returns true if the points are almost equal
1098
+ * Tells whether two points are closer together than a tolerance.
1099
+ *
1100
+ * Example: [1.0000001, 2, 3] and [1, 2, 3] with tolerance 1e-6 -> true
1101
+ * @param inputs - The two points and the tolerance
1102
+ * @returns True when the distance between them is below the tolerance
892
1103
  * @group measure
893
1104
  * @shortname two points almost equal
894
1105
  * @drawable false
1106
+ * @example
1107
+ * ```typescript
1108
+ * const same = bitbybit.point.twoPointsAlmostEqual({ point1: [1, 2, 3], point2: [1, 2, 3.0000001], tolerance: 1e-6 });
1109
+ * ```
895
1110
  */
896
1111
  twoPointsAlmostEqual(inputs) {
897
1112
  var _a;
@@ -901,13 +1116,18 @@ export class Point {
901
1116
  return dist < ((_a = inputs.tolerance) !== null && _a !== void 0 ? _a : 1e-7);
902
1117
  }
903
1118
  /**
904
- * Sorts points lexicographically (by X, then Y, then Z coordinates).
905
- * Example: [[5,0,0], [1,0,0], [3,0,0]] → [[1,0,0], [3,0,0], [5,0,0]]
906
- * @param inputs points
907
- * @returns sorted points
1119
+ * Sorts points by X, then by Y for equal X, then by Z.
1120
+ *
1121
+ * Example: [[5,0,0], [1,0,0], [3,0,0]] -> [[1,0,0], [3,0,0], [5,0,0]]
1122
+ * @param inputs - The points to sort
1123
+ * @returns A sorted copy of the points
908
1124
  * @group sort
909
1125
  * @shortname sort points
910
1126
  * @drawable true
1127
+ * @example
1128
+ * ```typescript
1129
+ * const sorted = bitbybit.point.sortPoints({ points: [[5, 0, 0], [1, 0, 0], [3, 0, 0]] });
1130
+ * ```
911
1131
  */
912
1132
  sortPoints(inputs) {
913
1133
  return [...inputs.points].sort((a, b) => {