@bitbybit-dev/base 1.2.0 → 1.3.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
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
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
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @
|
|
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
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* @
|
|
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
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
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
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* @
|
|
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
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* @
|
|
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
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* @
|
|
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
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* @
|
|
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
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
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
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
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
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
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
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* @
|
|
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
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
* @
|
|
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
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
* @
|
|
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
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
* @
|
|
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
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
* @
|
|
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
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
* @
|
|
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
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
* @
|
|
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
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
* @
|
|
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
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
* @
|
|
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
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
* @
|
|
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
|
-
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
* @
|
|
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
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
* @
|
|
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
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
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
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
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
|
-
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
*
|
|
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
|
-
*
|
|
677
|
-
*
|
|
678
|
-
*
|
|
679
|
-
*
|
|
680
|
-
*
|
|
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
|
-
*
|
|
716
|
-
*
|
|
717
|
-
*
|
|
718
|
-
*
|
|
719
|
-
*
|
|
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
|
-
*
|
|
752
|
-
*
|
|
753
|
-
*
|
|
754
|
-
*
|
|
755
|
-
*
|
|
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
|
-
*
|
|
805
|
-
*
|
|
806
|
-
*
|
|
807
|
-
*
|
|
808
|
-
*
|
|
809
|
-
* @
|
|
810
|
-
*
|
|
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
|
|
826
|
-
*
|
|
827
|
-
*
|
|
828
|
-
*
|
|
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
|
-
*
|
|
838
|
-
*
|
|
839
|
-
*
|
|
840
|
-
*
|
|
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
|
-
*
|
|
889
|
-
*
|
|
890
|
-
*
|
|
891
|
-
* @
|
|
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
|
|
905
|
-
*
|
|
906
|
-
*
|
|
907
|
-
* @
|
|
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) => {
|