@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
@@ -2,76 +2,118 @@ import * as Inputs from "../inputs";
2
2
  import { Polyline } from "./polyline";
3
3
  import { Vector } from "./vector";
4
4
  /**
5
- * Contains various mesh helper methods that are not necessarily present in higher level CAD kernels that
6
- * bitbybit is using.
5
+ * Geometry on plain triangle meshes: a mesh is a list of triangles, each three points. The methods
6
+ * here work out the plane of a triangle, the distance from a point to a plane, and where two meshes
7
+ * cut through each other, as segments, as polylines or as point lists. They need no CAD kernel, so
8
+ * they run on any triangulated data.
7
9
  */
8
10
  export declare class MeshBitByBit {
9
11
  private readonly vector;
10
12
  private readonly polyline;
11
13
  constructor(vector: Vector, polyline: Polyline);
12
14
  /**
13
- * Calculates signed distance from a point to a plane (positive=above plane, negative=below).
14
- * Example: point=[0,5,0], plane={normal:[0,1,0], d:0} → 5 (point is 5 units above XZ plane)
15
- * @param inputs a point and a plane
16
- * @returns signed distance
15
+ * Measures how far a point is from a plane, with a sign: positive on the side the normal points
16
+ * to, negative on the other.
17
+ *
18
+ * Example: point [0,5,0] and the XZ plane with normal [0,1,0] -> 5
19
+ * @param inputs - The point and the plane
20
+ * @returns The signed distance in model units
17
21
  * @group base
18
22
  * @shortname signed dist to plane
19
23
  * @drawable false
24
+ * @example
25
+ * ```typescript
26
+ * const above = bitbybit.mesh.signedDistanceToPlane({ point: [0, 5, 0], plane: { normal: [0, 1, 0], d: 0 } });
27
+ * ```
20
28
  */
21
29
  signedDistanceToPlane(inputs: Inputs.Mesh.SignedDistanceFromPlaneToPointDto): number;
22
30
  /**
23
- * Calculates plane equation from triangle vertices (normal vector and distance from origin).
24
- * Returns undefined if triangle is degenerate (zero area, collinear points).
25
- * Example: triangle=[[0,0,0], [1,0,0], [0,1,0]] → {normal:[0,0,1], d:0} (XY plane)
26
- * @param inputs triangle and tolerance
27
- * @returns triangle plane
31
+ * Finds the plane a triangle lies in: its unit normal and its distance from the origin along
32
+ * that normal.
33
+ *
34
+ * The normal follows the right-hand rule around the triangle's points. A triangle with no area,
35
+ * whose points are on one line, has no plane and gives undefined.
36
+ * Example: [[0,0,0], [1,0,0], [0,1,0]] -> { normal: [0,0,1], d: 0 }
37
+ * @param inputs - The triangle and the tolerance below which its area counts as zero
38
+ * @returns The plane, or undefined for a flat triangle
28
39
  * @group traingle
29
40
  * @shortname triangle plane
30
41
  * @drawable false
42
+ * @example
43
+ * ```typescript
44
+ * const plane = bitbybit.mesh.calculateTrianglePlane({ triangle: [[0, 0, 0], [1, 0, 0], [0, 1, 0]], tolerance: 1e-7 });
45
+ * ```
31
46
  */
32
47
  calculateTrianglePlane(inputs: Inputs.Mesh.TriangleToleranceDto): Inputs.Base.TrianglePlane3 | undefined;
33
48
  /**
34
- * Calculates intersection segment of two triangles (line segment where they cross).
35
- * Returns undefined if triangles don't intersect, are parallel, or are coplanar.
36
- * Example: triangle1=[[0,0,0], [2,0,0], [1,2,0]], triangle2=[[1,-1,1], [1,1,1], [1,1,-1]] → [[1,0,0], [1,1,0]]
37
- * @param inputs first triangle, second triangle, and tolerance
38
- * @returns intersection segment or undefined if no intersection
49
+ * Finds the segment where two triangles cut through each other.
50
+ *
51
+ * Triangles that do not touch, are parallel, or lie in the same plane give undefined.
52
+ * Example: a triangle in the XY plane and one standing across it -> the segment where they
53
+ * cross
54
+ * @param inputs - The two triangles and the tolerance
55
+ * @returns The crossing segment, or undefined when there is none
39
56
  * @group traingle
40
57
  * @shortname triangle-triangle int
41
58
  * @drawable false
59
+ * @example
60
+ * ```typescript
61
+ * const cut = bitbybit.mesh.triangleTriangleIntersection({
62
+ * triangle1: [[0, 0, 0], [2, 0, 0], [1, 2, 0]],
63
+ * triangle2: [[1, -1, 1], [1, 1, 1], [1, 1, -1]],
64
+ * tolerance: 1e-7,
65
+ * });
66
+ * ```
42
67
  */
43
68
  triangleTriangleIntersection(inputs: Inputs.Mesh.TriangleTriangleToleranceDto): Inputs.Base.Segment3 | undefined;
44
69
  /**
45
- * Calculates all intersection segments between two triangle meshes (pairwise triangle tests).
46
- * Returns array of line segments where mesh surfaces intersect.
47
- * Example: cube mesh intersecting with sphere mesh → multiple segments forming intersection curve
48
- * @param inputs first mesh, second mesh, and tolerance
49
- * @returns array of intersection segments
70
+ * Finds every segment where the surfaces of two meshes cut through each other, testing each
71
+ * triangle of one against each triangle of the other.
72
+ *
73
+ * Example: a cube mesh and a sphere mesh -> the segments that together trace their intersection
74
+ * curve
75
+ * @param inputs - The two meshes and the tolerance
76
+ * @returns The crossing segments, in no particular order
50
77
  * @group mesh
51
78
  * @shortname mesh-mesh int segments
52
79
  * @drawable false
80
+ * @example
81
+ * ```typescript
82
+ * const segments = bitbybit.mesh.meshMeshIntersectionSegments({ mesh1: cubeTriangles, mesh2: sphereTriangles, tolerance: 1e-7 });
83
+ * ```
53
84
  */
54
85
  meshMeshIntersectionSegments(inputs: Inputs.Mesh.MeshMeshToleranceDto): Inputs.Base.Segment3[];
55
86
  /**
56
- * Calculates intersection polylines between two meshes by sorting segments into connected paths.
57
- * Segments are joined end-to-end to form continuous or closed curves.
58
- * Example: cube-sphere intersection → closed polyline loops where surfaces meet
59
- * @param inputs first mesh, second mesh, and tolerance
60
- * @returns array of intersection polylines
87
+ * Finds where the surfaces of two meshes cut through each other and joins the pieces into
88
+ * polylines, closed where the curve loops.
89
+ *
90
+ * Example: a cube mesh and a sphere mesh -> closed polylines where the two surfaces meet
91
+ * @param inputs - The two meshes and the tolerance
92
+ * @returns The intersection curves as polylines
61
93
  * @group mesh
62
94
  * @shortname mesh-mesh int polylines
63
95
  * @drawable true
96
+ * @example
97
+ * ```typescript
98
+ * const curves = bitbybit.mesh.meshMeshIntersectionPolylines({ mesh1: cubeTriangles, mesh2: sphereTriangles, tolerance: 1e-7 });
99
+ * ```
64
100
  */
65
101
  meshMeshIntersectionPolylines(inputs: Inputs.Mesh.MeshMeshToleranceDto): Inputs.Base.Polyline3[];
66
102
  /**
67
- * Calculates intersection points between two meshes as point arrays (one array per polyline).
68
- * Closed polylines have first point duplicated at end.
69
- * Example: cube-sphere intersection → arrays of points defining intersection curves
70
- * @param inputs first mesh, second mesh, and tolerance
71
- * @returns array of intersection points
103
+ * Finds where the surfaces of two meshes cut through each other, as one list of points per
104
+ * curve.
105
+ *
106
+ * A closed curve repeats its first point at the end so the loop is explicit.
107
+ * Example: a cube mesh and a sphere mesh -> point lists tracing where the two surfaces meet
108
+ * @param inputs - The two meshes and the tolerance
109
+ * @returns One point list per intersection curve
72
110
  * @group mesh
73
111
  * @shortname mesh-mesh int points
74
112
  * @drawable false
113
+ * @example
114
+ * ```typescript
115
+ * const curves = bitbybit.mesh.meshMeshIntersectionPoints({ mesh1: cubeTriangles, mesh2: sphereTriangles, tolerance: 1e-7 });
116
+ * ```
75
117
  */
76
118
  meshMeshIntersectionPoints(inputs: Inputs.Mesh.MeshMeshToleranceDto): Inputs.Base.Point3[][];
77
119
  private computeIntersectionPoint;
@@ -1,6 +1,8 @@
1
1
  /**
2
- * Contains various mesh helper methods that are not necessarily present in higher level CAD kernels that
3
- * bitbybit is using.
2
+ * Geometry on plain triangle meshes: a mesh is a list of triangles, each three points. The methods
3
+ * here work out the plane of a triangle, the distance from a point to a plane, and where two meshes
4
+ * cut through each other, as segments, as polylines or as point lists. They need no CAD kernel, so
5
+ * they run on any triangulated data.
4
6
  */
5
7
  export class MeshBitByBit {
6
8
  constructor(vector, polyline) {
@@ -8,26 +10,39 @@ export class MeshBitByBit {
8
10
  this.polyline = polyline;
9
11
  }
10
12
  /**
11
- * Calculates signed distance from a point to a plane (positive=above plane, negative=below).
12
- * Example: point=[0,5,0], plane={normal:[0,1,0], d:0} → 5 (point is 5 units above XZ plane)
13
- * @param inputs a point and a plane
14
- * @returns signed distance
13
+ * Measures how far a point is from a plane, with a sign: positive on the side the normal points
14
+ * to, negative on the other.
15
+ *
16
+ * Example: point [0,5,0] and the XZ plane with normal [0,1,0] -> 5
17
+ * @param inputs - The point and the plane
18
+ * @returns The signed distance in model units
15
19
  * @group base
16
20
  * @shortname signed dist to plane
17
21
  * @drawable false
22
+ * @example
23
+ * ```typescript
24
+ * const above = bitbybit.mesh.signedDistanceToPlane({ point: [0, 5, 0], plane: { normal: [0, 1, 0], d: 0 } });
25
+ * ```
18
26
  */
19
27
  signedDistanceToPlane(inputs) {
20
28
  return this.vector.dot({ first: inputs.plane.normal, second: inputs.point }) - inputs.plane.d;
21
29
  }
22
30
  /**
23
- * Calculates plane equation from triangle vertices (normal vector and distance from origin).
24
- * Returns undefined if triangle is degenerate (zero area, collinear points).
25
- * Example: triangle=[[0,0,0], [1,0,0], [0,1,0]] → {normal:[0,0,1], d:0} (XY plane)
26
- * @param inputs triangle and tolerance
27
- * @returns triangle plane
31
+ * Finds the plane a triangle lies in: its unit normal and its distance from the origin along
32
+ * that normal.
33
+ *
34
+ * The normal follows the right-hand rule around the triangle's points. A triangle with no area,
35
+ * whose points are on one line, has no plane and gives undefined.
36
+ * Example: [[0,0,0], [1,0,0], [0,1,0]] -> { normal: [0,0,1], d: 0 }
37
+ * @param inputs - The triangle and the tolerance below which its area counts as zero
38
+ * @returns The plane, or undefined for a flat triangle
28
39
  * @group traingle
29
40
  * @shortname triangle plane
30
41
  * @drawable false
42
+ * @example
43
+ * ```typescript
44
+ * const plane = bitbybit.mesh.calculateTrianglePlane({ triangle: [[0, 0, 0], [1, 0, 0], [0, 1, 0]], tolerance: 1e-7 });
45
+ * ```
31
46
  */
32
47
  calculateTrianglePlane(inputs) {
33
48
  const EPSILON_SQ = Math.pow((inputs.tolerance || 1e-7), 2);
@@ -42,14 +57,24 @@ export class MeshBitByBit {
42
57
  return { normal: normalizedNormal, d: d };
43
58
  }
44
59
  /**
45
- * Calculates intersection segment of two triangles (line segment where they cross).
46
- * Returns undefined if triangles don't intersect, are parallel, or are coplanar.
47
- * Example: triangle1=[[0,0,0], [2,0,0], [1,2,0]], triangle2=[[1,-1,1], [1,1,1], [1,1,-1]] → [[1,0,0], [1,1,0]]
48
- * @param inputs first triangle, second triangle, and tolerance
49
- * @returns intersection segment or undefined if no intersection
60
+ * Finds the segment where two triangles cut through each other.
61
+ *
62
+ * Triangles that do not touch, are parallel, or lie in the same plane give undefined.
63
+ * Example: a triangle in the XY plane and one standing across it -> the segment where they
64
+ * cross
65
+ * @param inputs - The two triangles and the tolerance
66
+ * @returns The crossing segment, or undefined when there is none
50
67
  * @group traingle
51
68
  * @shortname triangle-triangle int
52
69
  * @drawable false
70
+ * @example
71
+ * ```typescript
72
+ * const cut = bitbybit.mesh.triangleTriangleIntersection({
73
+ * triangle1: [[0, 0, 0], [2, 0, 0], [1, 2, 0]],
74
+ * triangle2: [[1, -1, 1], [1, 1, 1], [1, 1, -1]],
75
+ * tolerance: 1e-7,
76
+ * });
77
+ * ```
53
78
  */
54
79
  triangleTriangleIntersection(inputs) {
55
80
  const t1 = inputs.triangle1;
@@ -153,14 +178,20 @@ export class MeshBitByBit {
153
178
  }
154
179
  }
155
180
  /**
156
- * Calculates all intersection segments between two triangle meshes (pairwise triangle tests).
157
- * Returns array of line segments where mesh surfaces intersect.
158
- * Example: cube mesh intersecting with sphere mesh → multiple segments forming intersection curve
159
- * @param inputs first mesh, second mesh, and tolerance
160
- * @returns array of intersection segments
181
+ * Finds every segment where the surfaces of two meshes cut through each other, testing each
182
+ * triangle of one against each triangle of the other.
183
+ *
184
+ * Example: a cube mesh and a sphere mesh -> the segments that together trace their intersection
185
+ * curve
186
+ * @param inputs - The two meshes and the tolerance
187
+ * @returns The crossing segments, in no particular order
161
188
  * @group mesh
162
189
  * @shortname mesh-mesh int segments
163
190
  * @drawable false
191
+ * @example
192
+ * ```typescript
193
+ * const segments = bitbybit.mesh.meshMeshIntersectionSegments({ mesh1: cubeTriangles, mesh2: sphereTriangles, tolerance: 1e-7 });
194
+ * ```
164
195
  */
165
196
  meshMeshIntersectionSegments(inputs) {
166
197
  const mesh1 = inputs.mesh1;
@@ -179,28 +210,39 @@ export class MeshBitByBit {
179
210
  return intersectionSegments;
180
211
  }
181
212
  /**
182
- * Calculates intersection polylines between two meshes by sorting segments into connected paths.
183
- * Segments are joined end-to-end to form continuous or closed curves.
184
- * Example: cube-sphere intersection → closed polyline loops where surfaces meet
185
- * @param inputs first mesh, second mesh, and tolerance
186
- * @returns array of intersection polylines
213
+ * Finds where the surfaces of two meshes cut through each other and joins the pieces into
214
+ * polylines, closed where the curve loops.
215
+ *
216
+ * Example: a cube mesh and a sphere mesh -> closed polylines where the two surfaces meet
217
+ * @param inputs - The two meshes and the tolerance
218
+ * @returns The intersection curves as polylines
187
219
  * @group mesh
188
220
  * @shortname mesh-mesh int polylines
189
221
  * @drawable true
222
+ * @example
223
+ * ```typescript
224
+ * const curves = bitbybit.mesh.meshMeshIntersectionPolylines({ mesh1: cubeTriangles, mesh2: sphereTriangles, tolerance: 1e-7 });
225
+ * ```
190
226
  */
191
227
  meshMeshIntersectionPolylines(inputs) {
192
228
  const segments = this.meshMeshIntersectionSegments(inputs);
193
229
  return this.polyline.sortSegmentsIntoPolylines({ segments, tolerance: inputs.tolerance });
194
230
  }
195
231
  /**
196
- * Calculates intersection points between two meshes as point arrays (one array per polyline).
197
- * Closed polylines have first point duplicated at end.
198
- * Example: cube-sphere intersection → arrays of points defining intersection curves
199
- * @param inputs first mesh, second mesh, and tolerance
200
- * @returns array of intersection points
232
+ * Finds where the surfaces of two meshes cut through each other, as one list of points per
233
+ * curve.
234
+ *
235
+ * A closed curve repeats its first point at the end so the loop is explicit.
236
+ * Example: a cube mesh and a sphere mesh -> point lists tracing where the two surfaces meet
237
+ * @param inputs - The two meshes and the tolerance
238
+ * @returns One point list per intersection curve
201
239
  * @group mesh
202
240
  * @shortname mesh-mesh int points
203
241
  * @drawable false
242
+ * @example
243
+ * ```typescript
244
+ * const curves = bitbybit.mesh.meshMeshIntersectionPoints({ mesh1: cubeTriangles, mesh2: sphereTriangles, tolerance: 1e-7 });
245
+ * ```
204
246
  */
205
247
  meshMeshIntersectionPoints(inputs) {
206
248
  const polylines = this.meshMeshIntersectionPolylines(inputs);