@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.
- package/lib/api/GlobalCDNProvider.js +1 -1
- package/lib/api/inputs/base-inputs.d.ts +13 -12
- package/lib/api/inputs/color-inputs.d.ts +97 -48
- package/lib/api/inputs/color-inputs.js +95 -46
- package/lib/api/inputs/dates-inputs.d.ts +67 -26
- package/lib/api/inputs/dates-inputs.js +57 -16
- package/lib/api/inputs/io-inputs.d.ts +13 -15
- package/lib/api/inputs/io-inputs.js +7 -8
- package/lib/api/inputs/line-inputs.d.ts +88 -33
- package/lib/api/inputs/line-inputs.js +61 -11
- package/lib/api/inputs/lists-inputs.d.ts +207 -96
- package/lib/api/inputs/lists-inputs.js +153 -45
- package/lib/api/inputs/logic-inputs.d.ts +52 -22
- package/lib/api/inputs/logic-inputs.js +41 -12
- package/lib/api/inputs/math-inputs.d.ts +113 -52
- package/lib/api/inputs/math-inputs.js +112 -51
- package/lib/api/inputs/mesh-inputs.d.ts +30 -11
- package/lib/api/inputs/mesh-inputs.js +21 -3
- package/lib/api/inputs/point-inputs.d.ts +240 -107
- package/lib/api/inputs/point-inputs.js +199 -73
- package/lib/api/inputs/polyline-inputs.d.ts +68 -28
- package/lib/api/inputs/polyline-inputs.js +48 -13
- package/lib/api/inputs/text-inputs.d.ts +117 -46
- package/lib/api/inputs/text-inputs.js +111 -41
- package/lib/api/inputs/transforms-inputs.d.ts +65 -23
- package/lib/api/inputs/transforms-inputs.js +64 -22
- package/lib/api/inputs/vector-inputs.d.ts +154 -76
- package/lib/api/inputs/vector-inputs.js +132 -57
- package/lib/api/models/point/hex-grid-data.d.ts +1 -1
- package/lib/api/models/point/hex-grid-data.js +1 -1
- package/lib/api/services/color.d.ts +149 -70
- package/lib/api/services/color.js +149 -70
- package/lib/api/services/dates.d.ts +313 -150
- package/lib/api/services/dates.js +313 -150
- package/lib/api/services/line.d.ts +138 -68
- package/lib/api/services/line.js +138 -68
- package/lib/api/services/lists.d.ts +357 -177
- package/lib/api/services/lists.js +357 -177
- package/lib/api/services/logic.d.ts +98 -45
- package/lib/api/services/logic.js +98 -45
- package/lib/api/services/math.d.ts +363 -211
- package/lib/api/services/math.js +363 -211
- package/lib/api/services/mesh.d.ts +73 -31
- package/lib/api/services/mesh.js +73 -31
- package/lib/api/services/point.d.ts +367 -147
- package/lib/api/services/point.js +367 -147
- package/lib/api/services/polyline.d.ts +146 -71
- package/lib/api/services/polyline.js +146 -71
- package/lib/api/services/text.d.ts +320 -165
- package/lib/api/services/text.js +320 -165
- package/lib/api/services/transforms.d.ts +145 -58
- package/lib/api/services/transforms.js +145 -58
- package/lib/api/services/vector.d.ts +381 -156
- package/lib/api/services/vector.js +381 -156
- 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
|
-
*
|
|
6
|
-
*
|
|
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
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
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
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
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
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
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
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
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
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* @
|
|
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
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
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;
|
package/lib/api/services/mesh.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
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
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
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
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
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
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
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
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
* @
|
|
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
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
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);
|