@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
@@ -4,8 +4,10 @@ import { Point } from "./point";
4
4
  import { Vector } from "./vector";
5
5
  import { Line } from "./line";
6
6
  /**
7
- * Contains various methods for polyline. Polyline in bitbybit is a simple object that has points property
8
- * containing an array of points. { points: number[][] }
7
+ * Polylines: chains of straight segments through a list of points, held as plain objects of the
8
+ * form `{ points, isClosed }`. A closed polyline joins its last point back to its first. The
9
+ * methods here measure a polyline, convert it to segments or lines, find where polylines cross,
10
+ * sort loose segments into chains and size fillets for its corners. Lengths are in model units.
9
11
  */
10
12
  export declare class Polyline {
11
13
  private readonly vector;
@@ -14,152 +16,225 @@ export declare class Polyline {
14
16
  private readonly geometryHelper;
15
17
  constructor(vector: Vector, point: Point, line: Line, geometryHelper: GeometryHelper);
16
18
  /**
17
- * Calculates total length of polyline by summing distances between consecutive points.
18
- * Example: points=[[0,0,0], [3,0,0], [3,4,0]] → 3 + 4 = 7
19
- * @param inputs a polyline
20
- * @returns length
19
+ * Measures the polyline by adding up the straight distances between neighboring points.
20
+ *
21
+ * The closing segment of a closed polyline is not counted.
22
+ * Example: [[0,0,0], [3,0,0], [3,4,0]] -> 7
23
+ * @param inputs - The polyline
24
+ * @returns The length in model units
21
25
  * @group get
22
26
  * @shortname polyline length
23
27
  * @drawable false
28
+ * @example
29
+ * ```typescript
30
+ * const len = bitbybit.polyline.length({ polyline: { points: [[0, 0, 0], [3, 0, 0], [3, 4, 0]] } });
31
+ * ```
24
32
  */
25
33
  length(inputs: Inputs.Polyline.PolylineDto): number;
26
34
  /**
27
- * Counts number of points in polyline.
28
- * Example: polyline with points=[[0,0,0], [1,0,0], [1,1,0]] → 3
29
- * @param inputs a polyline
30
- * @returns nr of points
35
+ * Counts the points of the polyline.
36
+ *
37
+ * Example: three points -> 3
38
+ * @param inputs - The polyline
39
+ * @returns The number of points
31
40
  * @group get
32
41
  * @shortname nr polyline points
33
42
  * @drawable false
34
43
  */
35
44
  countPoints(inputs: Inputs.Polyline.PolylineDto): number;
36
45
  /**
37
- * Extracts points array from polyline object.
38
- * Example: polyline={points:[[0,0,0], [1,0,0]]} → [[0,0,0], [1,0,0]]
39
- * @param inputs a polyline
40
- * @returns points
46
+ * Reads the list of points out of the polyline.
47
+ *
48
+ * Example: { points: [[0,0,0], [1,0,0]] } -> [[0,0,0], [1,0,0]]
49
+ * @param inputs - The polyline
50
+ * @returns Its points, in order
41
51
  * @group get
42
52
  * @shortname points
43
53
  * @drawable true
44
54
  */
45
55
  getPoints(inputs: Inputs.Polyline.PolylineDto): Inputs.Base.Point3[];
46
56
  /**
47
- * Reverses point order of polyline (flips direction).
48
- * Example: points=[[0,0,0], [1,0,0], [2,0,0]] → [[2,0,0], [1,0,0], [0,0,0]]
49
- * @param inputs a polyline
50
- * @returns reversed polyline
57
+ * Reverses the order of the points, so the polyline runs the other way.
58
+ *
59
+ * The given polyline's own point list is reversed in place and handed back inside a new
60
+ * polyline object.
61
+ * Example: [[0,0,0], [1,0,0], [2,0,0]] -> [[2,0,0], [1,0,0], [0,0,0]]
62
+ * @param inputs - The polyline
63
+ * @returns A polyline with the points in reverse order
51
64
  * @group convert
52
65
  * @shortname reverse polyline
53
66
  * @drawable true
67
+ * @example
68
+ * ```typescript
69
+ * const back = bitbybit.polyline.reverse({ polyline: { points: [[0, 0, 0], [1, 0, 0], [2, 0, 0]] } });
70
+ * ```
54
71
  */
55
72
  reverse(inputs: Inputs.Polyline.PolylineDto): Inputs.Polyline.PolylinePropertiesDto;
56
73
  /**
57
- * Applies transformation matrix to all points in polyline (rotates, scales, or translates).
58
- * Example: polyline with 4 points, translation [5,0,0] → all points moved +5 in X direction
59
- * @param inputs a polyline
60
- * @returns transformed polyline
74
+ * Applies a transformation matrix, or a list of them in order, to every point of the polyline.
75
+ *
76
+ * Example: a translation by [5,0,0] -> every point moved 5 along X
77
+ * @param inputs - The polyline and the transformation
78
+ * @returns A new polyline with the transformed points
61
79
  * @group transforms
62
80
  * @shortname transform polyline
63
81
  * @drawable true
82
+ * @example
83
+ * ```typescript
84
+ * const moved = bitbybit.polyline.transformPolyline({
85
+ * polyline: { points: [[0, 0, 0], [1, 0, 0]] },
86
+ * transformation: bitbybit.transforms.translationXYZ({ translation: [5, 0, 0] }),
87
+ * });
88
+ * ```
64
89
  */
65
90
  transformPolyline(inputs: Inputs.Polyline.TransformPolylineDto): Inputs.Polyline.PolylinePropertiesDto;
66
91
  /**
67
- * Creates a polyline from points array with optional isClosed flag.
68
- * Example: points=[[0,0,0], [1,0,0], [1,1,0]], isClosed=true → {points:..., isClosed:true}
69
- * @param inputs points and info if its closed
70
- * @returns polyline
92
+ * Builds a polyline object from points, open or closed.
93
+ *
94
+ * Example: three points with isClosed true -> a triangle
95
+ * @param inputs - The points and whether the last joins back to the first
96
+ * @returns The polyline object
71
97
  * @group create
72
98
  * @shortname polyline
73
99
  * @drawable true
100
+ * @example
101
+ * ```typescript
102
+ * const triangle = bitbybit.polyline.create({ points: [[0, 0, 0], [1, 0, 0], [1, 1, 0]], isClosed: true });
103
+ * ```
74
104
  */
75
105
  create(inputs: Inputs.Polyline.PolylineCreateDto): Inputs.Polyline.PolylinePropertiesDto;
76
106
  /**
77
- * Converts polyline to line segments (each segment as line object with start/end).
78
- * Closed polylines include closing segment.
79
- * Example: 3 points → 2 or 3 lines (depending on isClosed)
80
- * @param inputs polyline
81
- * @returns lines
107
+ * Splits the polyline into line objects, one per segment, each with a start and an end point.
108
+ *
109
+ * A closed polyline also gets the segment from its last point back to its first, unless the two
110
+ * coincide.
111
+ * Example: three points -> two lines, or three when closed
112
+ * @param inputs - The polyline
113
+ * @returns One line per segment, in order
82
114
  * @group convert
83
115
  * @shortname polyline to lines
84
116
  * @drawable true
117
+ * @example
118
+ * ```typescript
119
+ * const lines = bitbybit.polyline.polylineToLines({ polyline: { points: [[0, 0, 0], [1, 0, 0], [1, 1, 0]], isClosed: true } });
120
+ * ```
85
121
  */
86
122
  polylineToLines(inputs: Inputs.Polyline.PolylineDto): Inputs.Base.Line3[];
87
123
  /**
88
- * Converts polyline to segment arrays (each segment as [point1, point2]).
89
- * Closed polylines include closing segment if endpoints differ.
90
- * Example: 4 points, closed → 4 segments connecting all points in a loop
91
- * @param inputs polyline
92
- * @returns segments
124
+ * Splits the polyline into segments, each a pair of points.
125
+ *
126
+ * A closed polyline also gets the segment from its last point back to its first, unless the two
127
+ * coincide. Fewer than two points give no segments.
128
+ * Example: four points, closed -> four segments around the loop
129
+ * @param inputs - The polyline
130
+ * @returns One point pair per segment, in order
93
131
  * @group convert
94
132
  * @shortname polyline to segments
95
133
  * @drawable false
134
+ * @example
135
+ * ```typescript
136
+ * const segments = bitbybit.polyline.polylineToSegments({ polyline: { points: [[0, 0, 0], [1, 0, 0], [1, 1, 0]], isClosed: false } });
137
+ * ```
96
138
  */
97
139
  polylineToSegments(inputs: Inputs.Polyline.PolylineDto): Inputs.Base.Segment3[];
98
140
  /**
99
- * Finds points where polyline crosses itself (self-intersection points).
100
- * Skips adjacent segments and deduplicates close points.
101
- * Example: figure-8 shaped polyline → returns center crossing point
102
- * @param inputs points of self intersection
103
- * @returns polyline
141
+ * Finds the points where the polyline crosses itself.
142
+ *
143
+ * Neighboring segments are not tested against each other, and crossings closer together than
144
+ * the tolerance are reported once.
145
+ * Example: a figure-eight -> its one crossing point
146
+ * @param inputs - The polyline and the tolerance
147
+ * @returns The crossing points; empty when there are none
104
148
  * @group intersections
105
149
  * @shortname polyline self intersections
106
150
  * @drawable true
151
+ * @example
152
+ * ```typescript
153
+ * const crossings = bitbybit.polyline.polylineSelfIntersection({
154
+ * polyline: { points: [[0, 0, 0], [2, 2, 0], [2, 0, 0], [0, 2, 0]] },
155
+ * tolerance: 1e-6,
156
+ * });
157
+ * ```
107
158
  */
108
159
  polylineSelfIntersection(inputs: Inputs.Polyline.PolylineToleranceDto): Inputs.Base.Point3[];
109
160
  /**
110
- * Finds intersection points between two polylines (all segment-segment crossings).
111
- * Tests all segment pairs and deduplicates close points.
112
- * Example: crossing polylines forming an X → returns center intersection point
113
- * @param inputs two polylines and tolerance
114
- * @returns points
161
+ * Finds the points where two polylines cross each other, testing every segment of one against
162
+ * every segment of the other.
163
+ *
164
+ * Crossings closer together than the tolerance are reported once.
165
+ * Example: two polylines forming an X -> the point in the middle
166
+ * @param inputs - The two polylines and the tolerance
167
+ * @returns The crossing points; empty when there are none
115
168
  * @group intersection
116
169
  * @shortname two polyline intersection
117
170
  * @drawable true
171
+ * @example
172
+ * ```typescript
173
+ * const crossings = bitbybit.polyline.twoPolylineIntersection({
174
+ * polyline1: { points: [[0, 0, 0], [2, 2, 0]] },
175
+ * polyline2: { points: [[0, 2, 0], [2, 0, 0]] },
176
+ * tolerance: 1e-6,
177
+ * });
178
+ * ```
118
179
  */
119
180
  twoPolylineIntersection(inputs: Inputs.Polyline.TwoPolylinesToleranceDto): Inputs.Base.Point3[];
120
181
  /**
121
- * Sorts scrambled segments into connected polylines by matching endpoints.
122
- * Uses spatial hashing for efficient connection finding.
123
- * Example: 10 random segments that form 2 connected paths → 2 polylines
124
- * @param inputs segments
125
- * @returns polylines
182
+ * Joins loose segments into polylines by matching up ends that meet within the tolerance.
183
+ *
184
+ * Segments that connect end to end become one polyline each chain; segments that touch nothing
185
+ * become single-segment polylines.
186
+ * Example: ten scattered segments forming two chains -> two polylines
187
+ * @param inputs - The segments and the tolerance for two ends to count as touching
188
+ * @returns The polylines the segments form
126
189
  * @group sort
127
190
  * @shortname segments to polylines
128
191
  * @drawable true
192
+ * @example
193
+ * ```typescript
194
+ * const chains = bitbybit.polyline.sortSegmentsIntoPolylines({
195
+ * segments: [[[0, 0, 0], [1, 0, 0]], [[1, 0, 0], [1, 1, 0]], [[5, 5, 0], [6, 5, 0]]],
196
+ * tolerance: 1e-5,
197
+ * });
198
+ * ```
129
199
  */
130
200
  sortSegmentsIntoPolylines(inputs: Inputs.Polyline.SegmentsToleranceDto): Inputs.Base.Polyline3[];
131
201
  /**
132
- * Calculates the maximum possible half-line fillet radius for each corner
133
- * of a given polyline. For a closed polyline, it includes the corners
134
- * connecting the last segment back to the first.
135
- *
136
- * The calculation uses the 'half-line' constraint, meaning the fillet's
137
- * tangent points must lie within the first half of each segment connected
138
- * to the corner.
202
+ * Finds the largest fillet for every corner of the polyline, each limited to the nearer half of
203
+ * its segments so the fillets never overlap.
139
204
  *
140
- * @param inputs Defines the polyline points, whether it's closed, and an optional tolerance.
141
- * @returns An array containing the maximum fillet radius calculated for each corner.
142
- * The order corresponds to corners P[1]...P[n-2] for open polylines,
143
- * and P[1]...P[n-2], P[0], P[n-1] for closed polylines.
144
- * Returns an empty array if the polyline has fewer than 3 points.
205
+ * A closed polyline includes the two corners at its ends. Fewer than three points give an empty
206
+ * list.
207
+ * @param inputs - The polyline and the tolerance
208
+ * @returns One radius per corner, in the order of the corners
145
209
  * @group fillet
146
210
  * @shortname polyline max fillet radii
147
211
  * @drawable false
212
+ * @example
213
+ * ```typescript
214
+ * const radii = bitbybit.polyline.maxFilletsHalfLine({
215
+ * polyline: { points: [[0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]], isClosed: true },
216
+ * tolerance: 1e-7,
217
+ * });
218
+ * ```
148
219
  */
149
220
  maxFilletsHalfLine(inputs: Inputs.Polyline.PolylineToleranceDto): number[];
150
221
  /**
151
- * Calculates the single safest maximum fillet radius that can be applied
152
- * uniformly to all corners of a polyline, based on the 'half-line' constraint.
153
- * This is determined by finding the minimum of the maximum possible fillet
154
- * radii calculated for each individual corner.
222
+ * Finds one fillet radius that fits every corner of the polyline: the smallest of the
223
+ * per-corner maximums under the half-segment rule.
155
224
  *
156
- * @param inputs Defines the polyline points, whether it's closed, and an optional tolerance.
157
- * @returns The smallest value from the results of calculatePolylineMaxFillets.
158
- * Returns 0 if the polyline has fewer than 3 points or if any
159
- * calculated maximum radius is 0.
225
+ * Fewer than three points, or any corner that allows no fillet, give 0.
226
+ * @param inputs - The polyline and the tolerance
227
+ * @returns The radius that fits every corner, in model units
160
228
  * @group fillet
161
229
  * @shortname polyline safest fillet radius
162
230
  * @drawable false
231
+ * @example
232
+ * ```typescript
233
+ * const radius = bitbybit.polyline.safestFilletRadius({
234
+ * polyline: { points: [[0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]], isClosed: true },
235
+ * tolerance: 1e-7,
236
+ * });
237
+ * ```
163
238
  */
164
239
  safestFilletRadius(inputs: Inputs.Polyline.PolylineToleranceDto): number;
165
240
  }
@@ -1,6 +1,8 @@
1
1
  /**
2
- * Contains various methods for polyline. Polyline in bitbybit is a simple object that has points property
3
- * containing an array of points. { points: number[][] }
2
+ * Polylines: chains of straight segments through a list of points, held as plain objects of the
3
+ * form `{ points, isClosed }`. A closed polyline joins its last point back to its first. The
4
+ * methods here measure a polyline, convert it to segments or lines, find where polylines cross,
5
+ * sort loose segments into chains and size fillets for its corners. Lengths are in model units.
4
6
  */
5
7
  export class Polyline {
6
8
  constructor(vector, point, line, geometryHelper) {
@@ -10,13 +12,19 @@ export class Polyline {
10
12
  this.geometryHelper = geometryHelper;
11
13
  }
12
14
  /**
13
- * Calculates total length of polyline by summing distances between consecutive points.
14
- * Example: points=[[0,0,0], [3,0,0], [3,4,0]] → 3 + 4 = 7
15
- * @param inputs a polyline
16
- * @returns length
15
+ * Measures the polyline by adding up the straight distances between neighboring points.
16
+ *
17
+ * The closing segment of a closed polyline is not counted.
18
+ * Example: [[0,0,0], [3,0,0], [3,4,0]] -> 7
19
+ * @param inputs - The polyline
20
+ * @returns The length in model units
17
21
  * @group get
18
22
  * @shortname polyline length
19
23
  * @drawable false
24
+ * @example
25
+ * ```typescript
26
+ * const len = bitbybit.polyline.length({ polyline: { points: [[0, 0, 0], [3, 0, 0], [3, 4, 0]] } });
27
+ * ```
20
28
  */
21
29
  length(inputs) {
22
30
  let distanceOfPolyline = 0;
@@ -28,10 +36,11 @@ export class Polyline {
28
36
  return distanceOfPolyline;
29
37
  }
30
38
  /**
31
- * Counts number of points in polyline.
32
- * Example: polyline with points=[[0,0,0], [1,0,0], [1,1,0]] → 3
33
- * @param inputs a polyline
34
- * @returns nr of points
39
+ * Counts the points of the polyline.
40
+ *
41
+ * Example: three points -> 3
42
+ * @param inputs - The polyline
43
+ * @returns The number of points
35
44
  * @group get
36
45
  * @shortname nr polyline points
37
46
  * @drawable false
@@ -40,10 +49,11 @@ export class Polyline {
40
49
  return inputs.polyline.points.length;
41
50
  }
42
51
  /**
43
- * Extracts points array from polyline object.
44
- * Example: polyline={points:[[0,0,0], [1,0,0]]} → [[0,0,0], [1,0,0]]
45
- * @param inputs a polyline
46
- * @returns points
52
+ * Reads the list of points out of the polyline.
53
+ *
54
+ * Example: { points: [[0,0,0], [1,0,0]] } -> [[0,0,0], [1,0,0]]
55
+ * @param inputs - The polyline
56
+ * @returns Its points, in order
47
57
  * @group get
48
58
  * @shortname points
49
59
  * @drawable true
@@ -52,25 +62,40 @@ export class Polyline {
52
62
  return inputs.polyline.points;
53
63
  }
54
64
  /**
55
- * Reverses point order of polyline (flips direction).
56
- * Example: points=[[0,0,0], [1,0,0], [2,0,0]] → [[2,0,0], [1,0,0], [0,0,0]]
57
- * @param inputs a polyline
58
- * @returns reversed polyline
65
+ * Reverses the order of the points, so the polyline runs the other way.
66
+ *
67
+ * The given polyline's own point list is reversed in place and handed back inside a new
68
+ * polyline object.
69
+ * Example: [[0,0,0], [1,0,0], [2,0,0]] -> [[2,0,0], [1,0,0], [0,0,0]]
70
+ * @param inputs - The polyline
71
+ * @returns A polyline with the points in reverse order
59
72
  * @group convert
60
73
  * @shortname reverse polyline
61
74
  * @drawable true
75
+ * @example
76
+ * ```typescript
77
+ * const back = bitbybit.polyline.reverse({ polyline: { points: [[0, 0, 0], [1, 0, 0], [2, 0, 0]] } });
78
+ * ```
62
79
  */
63
80
  reverse(inputs) {
64
81
  return { points: inputs.polyline.points.reverse() };
65
82
  }
66
83
  /**
67
- * Applies transformation matrix to all points in polyline (rotates, scales, or translates).
68
- * Example: polyline with 4 points, translation [5,0,0] → all points moved +5 in X direction
69
- * @param inputs a polyline
70
- * @returns transformed polyline
84
+ * Applies a transformation matrix, or a list of them in order, to every point of the polyline.
85
+ *
86
+ * Example: a translation by [5,0,0] -> every point moved 5 along X
87
+ * @param inputs - The polyline and the transformation
88
+ * @returns A new polyline with the transformed points
71
89
  * @group transforms
72
90
  * @shortname transform polyline
73
91
  * @drawable true
92
+ * @example
93
+ * ```typescript
94
+ * const moved = bitbybit.polyline.transformPolyline({
95
+ * polyline: { points: [[0, 0, 0], [1, 0, 0]] },
96
+ * transformation: bitbybit.transforms.translationXYZ({ translation: [5, 0, 0] }),
97
+ * });
98
+ * ```
74
99
  */
75
100
  transformPolyline(inputs) {
76
101
  const transformation = inputs.transformation;
@@ -79,13 +104,18 @@ export class Polyline {
79
104
  return { points: transformedControlPoints };
80
105
  }
81
106
  /**
82
- * Creates a polyline from points array with optional isClosed flag.
83
- * Example: points=[[0,0,0], [1,0,0], [1,1,0]], isClosed=true → {points:..., isClosed:true}
84
- * @param inputs points and info if its closed
85
- * @returns polyline
107
+ * Builds a polyline object from points, open or closed.
108
+ *
109
+ * Example: three points with isClosed true -> a triangle
110
+ * @param inputs - The points and whether the last joins back to the first
111
+ * @returns The polyline object
86
112
  * @group create
87
113
  * @shortname polyline
88
114
  * @drawable true
115
+ * @example
116
+ * ```typescript
117
+ * const triangle = bitbybit.polyline.create({ points: [[0, 0, 0], [1, 0, 0], [1, 1, 0]], isClosed: true });
118
+ * ```
89
119
  */
90
120
  create(inputs) {
91
121
  var _a;
@@ -95,14 +125,20 @@ export class Polyline {
95
125
  };
96
126
  }
97
127
  /**
98
- * Converts polyline to line segments (each segment as line object with start/end).
99
- * Closed polylines include closing segment.
100
- * Example: 3 points → 2 or 3 lines (depending on isClosed)
101
- * @param inputs polyline
102
- * @returns lines
128
+ * Splits the polyline into line objects, one per segment, each with a start and an end point.
129
+ *
130
+ * A closed polyline also gets the segment from its last point back to its first, unless the two
131
+ * coincide.
132
+ * Example: three points -> two lines, or three when closed
133
+ * @param inputs - The polyline
134
+ * @returns One line per segment, in order
103
135
  * @group convert
104
136
  * @shortname polyline to lines
105
137
  * @drawable true
138
+ * @example
139
+ * ```typescript
140
+ * const lines = bitbybit.polyline.polylineToLines({ polyline: { points: [[0, 0, 0], [1, 0, 0], [1, 1, 0]], isClosed: true } });
141
+ * ```
106
142
  */
107
143
  polylineToLines(inputs) {
108
144
  const segments = this.polylineToSegments(inputs);
@@ -112,14 +148,20 @@ export class Polyline {
112
148
  }));
113
149
  }
114
150
  /**
115
- * Converts polyline to segment arrays (each segment as [point1, point2]).
116
- * Closed polylines include closing segment if endpoints differ.
117
- * Example: 4 points, closed → 4 segments connecting all points in a loop
118
- * @param inputs polyline
119
- * @returns segments
151
+ * Splits the polyline into segments, each a pair of points.
152
+ *
153
+ * A closed polyline also gets the segment from its last point back to its first, unless the two
154
+ * coincide. Fewer than two points give no segments.
155
+ * Example: four points, closed -> four segments around the loop
156
+ * @param inputs - The polyline
157
+ * @returns One point pair per segment, in order
120
158
  * @group convert
121
159
  * @shortname polyline to segments
122
160
  * @drawable false
161
+ * @example
162
+ * ```typescript
163
+ * const segments = bitbybit.polyline.polylineToSegments({ polyline: { points: [[0, 0, 0], [1, 0, 0], [1, 1, 0]], isClosed: false } });
164
+ * ```
123
165
  */
124
166
  polylineToSegments(inputs) {
125
167
  const polyline = inputs.polyline;
@@ -140,14 +182,23 @@ export class Polyline {
140
182
  return segments;
141
183
  }
142
184
  /**
143
- * Finds points where polyline crosses itself (self-intersection points).
144
- * Skips adjacent segments and deduplicates close points.
145
- * Example: figure-8 shaped polyline → returns center crossing point
146
- * @param inputs points of self intersection
147
- * @returns polyline
185
+ * Finds the points where the polyline crosses itself.
186
+ *
187
+ * Neighboring segments are not tested against each other, and crossings closer together than
188
+ * the tolerance are reported once.
189
+ * Example: a figure-eight -> its one crossing point
190
+ * @param inputs - The polyline and the tolerance
191
+ * @returns The crossing points; empty when there are none
148
192
  * @group intersections
149
193
  * @shortname polyline self intersections
150
194
  * @drawable true
195
+ * @example
196
+ * ```typescript
197
+ * const crossings = bitbybit.polyline.polylineSelfIntersection({
198
+ * polyline: { points: [[0, 0, 0], [2, 2, 0], [2, 0, 0], [0, 2, 0]] },
199
+ * tolerance: 1e-6,
200
+ * });
201
+ * ```
151
202
  */
152
203
  polylineSelfIntersection(inputs) {
153
204
  const { polyline, tolerance } = inputs;
@@ -194,14 +245,24 @@ export class Polyline {
194
245
  return selfIntersectionPoints;
195
246
  }
196
247
  /**
197
- * Finds intersection points between two polylines (all segment-segment crossings).
198
- * Tests all segment pairs and deduplicates close points.
199
- * Example: crossing polylines forming an X → returns center intersection point
200
- * @param inputs two polylines and tolerance
201
- * @returns points
248
+ * Finds the points where two polylines cross each other, testing every segment of one against
249
+ * every segment of the other.
250
+ *
251
+ * Crossings closer together than the tolerance are reported once.
252
+ * Example: two polylines forming an X -> the point in the middle
253
+ * @param inputs - The two polylines and the tolerance
254
+ * @returns The crossing points; empty when there are none
202
255
  * @group intersection
203
256
  * @shortname two polyline intersection
204
257
  * @drawable true
258
+ * @example
259
+ * ```typescript
260
+ * const crossings = bitbybit.polyline.twoPolylineIntersection({
261
+ * polyline1: { points: [[0, 0, 0], [2, 2, 0]] },
262
+ * polyline2: { points: [[0, 2, 0], [2, 0, 0]] },
263
+ * tolerance: 1e-6,
264
+ * });
265
+ * ```
205
266
  */
206
267
  twoPolylineIntersection(inputs) {
207
268
  const { polyline1, polyline2, tolerance } = inputs;
@@ -238,14 +299,23 @@ export class Polyline {
238
299
  return intersectionPoints;
239
300
  }
240
301
  /**
241
- * Sorts scrambled segments into connected polylines by matching endpoints.
242
- * Uses spatial hashing for efficient connection finding.
243
- * Example: 10 random segments that form 2 connected paths → 2 polylines
244
- * @param inputs segments
245
- * @returns polylines
302
+ * Joins loose segments into polylines by matching up ends that meet within the tolerance.
303
+ *
304
+ * Segments that connect end to end become one polyline each chain; segments that touch nothing
305
+ * become single-segment polylines.
306
+ * Example: ten scattered segments forming two chains -> two polylines
307
+ * @param inputs - The segments and the tolerance for two ends to count as touching
308
+ * @returns The polylines the segments form
246
309
  * @group sort
247
310
  * @shortname segments to polylines
248
311
  * @drawable true
312
+ * @example
313
+ * ```typescript
314
+ * const chains = bitbybit.polyline.sortSegmentsIntoPolylines({
315
+ * segments: [[[0, 0, 0], [1, 0, 0]], [[1, 0, 0], [1, 1, 0]], [[5, 5, 0], [6, 5, 0]]],
316
+ * tolerance: 1e-5,
317
+ * });
318
+ * ```
249
319
  */
250
320
  sortSegmentsIntoPolylines(inputs) {
251
321
  var _a;
@@ -383,22 +453,23 @@ export class Polyline {
383
453
  return results;
384
454
  }
385
455
  /**
386
- * Calculates the maximum possible half-line fillet radius for each corner
387
- * of a given polyline. For a closed polyline, it includes the corners
388
- * connecting the last segment back to the first.
389
- *
390
- * The calculation uses the 'half-line' constraint, meaning the fillet's
391
- * tangent points must lie within the first half of each segment connected
392
- * to the corner.
456
+ * Finds the largest fillet for every corner of the polyline, each limited to the nearer half of
457
+ * its segments so the fillets never overlap.
393
458
  *
394
- * @param inputs Defines the polyline points, whether it's closed, and an optional tolerance.
395
- * @returns An array containing the maximum fillet radius calculated for each corner.
396
- * The order corresponds to corners P[1]...P[n-2] for open polylines,
397
- * and P[1]...P[n-2], P[0], P[n-1] for closed polylines.
398
- * Returns an empty array if the polyline has fewer than 3 points.
459
+ * A closed polyline includes the two corners at its ends. Fewer than three points give an empty
460
+ * list.
461
+ * @param inputs - The polyline and the tolerance
462
+ * @returns One radius per corner, in the order of the corners
399
463
  * @group fillet
400
464
  * @shortname polyline max fillet radii
401
465
  * @drawable false
466
+ * @example
467
+ * ```typescript
468
+ * const radii = bitbybit.polyline.maxFilletsHalfLine({
469
+ * polyline: { points: [[0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]], isClosed: true },
470
+ * tolerance: 1e-7,
471
+ * });
472
+ * ```
402
473
  */
403
474
  maxFilletsHalfLine(inputs) {
404
475
  return this.point.maxFilletsHalfLine({
@@ -408,18 +479,22 @@ export class Polyline {
408
479
  });
409
480
  }
410
481
  /**
411
- * Calculates the single safest maximum fillet radius that can be applied
412
- * uniformly to all corners of a polyline, based on the 'half-line' constraint.
413
- * This is determined by finding the minimum of the maximum possible fillet
414
- * radii calculated for each individual corner.
482
+ * Finds one fillet radius that fits every corner of the polyline: the smallest of the
483
+ * per-corner maximums under the half-segment rule.
415
484
  *
416
- * @param inputs Defines the polyline points, whether it's closed, and an optional tolerance.
417
- * @returns The smallest value from the results of calculatePolylineMaxFillets.
418
- * Returns 0 if the polyline has fewer than 3 points or if any
419
- * calculated maximum radius is 0.
485
+ * Fewer than three points, or any corner that allows no fillet, give 0.
486
+ * @param inputs - The polyline and the tolerance
487
+ * @returns The radius that fits every corner, in model units
420
488
  * @group fillet
421
489
  * @shortname polyline safest fillet radius
422
490
  * @drawable false
491
+ * @example
492
+ * ```typescript
493
+ * const radius = bitbybit.polyline.safestFilletRadius({
494
+ * polyline: { points: [[0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]], isClosed: true },
495
+ * tolerance: 1e-7,
496
+ * });
497
+ * ```
423
498
  */
424
499
  safestFilletRadius(inputs) {
425
500
  const allMaxRadii = this.maxFilletsHalfLine(inputs);