@bitbybit-dev/base 0.19.0-alpha.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/LICENSE +21 -0
- package/README.md +71 -0
- package/babel.config.cjs +14 -0
- package/babel.config.d.cts +5 -0
- package/index.d.ts +1 -0
- package/index.js +4 -0
- package/lib/api/index.d.ts +1 -0
- package/lib/api/index.js +1 -0
- package/lib/api/inputs/base-inputs.d.ts +35 -0
- package/lib/api/inputs/base-inputs.js +1 -0
- package/lib/api/inputs/color-inputs.d.ts +122 -0
- package/lib/api/inputs/color-inputs.js +164 -0
- package/lib/api/inputs/index.d.ts +8 -0
- package/lib/api/inputs/index.js +8 -0
- package/lib/api/inputs/inputs.d.ts +10 -0
- package/lib/api/inputs/inputs.js +10 -0
- package/lib/api/inputs/lists-inputs.d.ts +478 -0
- package/lib/api/inputs/lists-inputs.js +576 -0
- package/lib/api/inputs/logic-inputs.d.ts +163 -0
- package/lib/api/inputs/logic-inputs.js +111 -0
- package/lib/api/inputs/math-inputs.d.ts +311 -0
- package/lib/api/inputs/math-inputs.js +391 -0
- package/lib/api/inputs/point-inputs.d.ts +446 -0
- package/lib/api/inputs/point-inputs.js +521 -0
- package/lib/api/inputs/text-inputs.d.ts +83 -0
- package/lib/api/inputs/text-inputs.js +120 -0
- package/lib/api/inputs/transforms-inputs.d.ts +136 -0
- package/lib/api/inputs/transforms-inputs.js +200 -0
- package/lib/api/inputs/vector-inputs.d.ts +300 -0
- package/lib/api/inputs/vector-inputs.js +304 -0
- package/lib/api/services/color.d.ts +114 -0
- package/lib/api/services/color.js +170 -0
- package/lib/api/services/geometry-helper.d.ts +15 -0
- package/lib/api/services/geometry-helper.js +151 -0
- package/lib/api/services/index.d.ts +9 -0
- package/lib/api/services/index.js +9 -0
- package/lib/api/services/lists.d.ts +287 -0
- package/lib/api/services/lists.js +682 -0
- package/lib/api/services/logic.d.ts +99 -0
- package/lib/api/services/logic.js +203 -0
- package/lib/api/services/math.d.ts +349 -0
- package/lib/api/services/math.js +621 -0
- package/lib/api/services/point.d.ts +223 -0
- package/lib/api/services/point.js +351 -0
- package/lib/api/services/text.d.ts +69 -0
- package/lib/api/services/text.js +84 -0
- package/lib/api/services/transforms.d.ts +122 -0
- package/lib/api/services/transforms.js +256 -0
- package/lib/api/services/vector.d.ts +320 -0
- package/lib/api/services/vector.js +468 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/package.json +93 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { GeometryHelper } from "./geometry-helper";
|
|
2
|
+
import * as Inputs from "../inputs/inputs";
|
|
3
|
+
import { Base } from "../inputs/inputs";
|
|
4
|
+
import { Transforms } from "./transforms";
|
|
5
|
+
/**
|
|
6
|
+
* Contains various methods for points. Point in bitbybit is simply an array containing 3 numbers for [x, y, z].
|
|
7
|
+
* Because of this form Point can be interchanged with Vector, which also is an array in [x, y, z] form.
|
|
8
|
+
* When creating 2D points, z coordinate is simply set to 0 - [x, y, 0].
|
|
9
|
+
*/
|
|
10
|
+
export declare class Point {
|
|
11
|
+
private readonly geometryHelper;
|
|
12
|
+
private readonly transforms;
|
|
13
|
+
constructor(geometryHelper: GeometryHelper, transforms: Transforms);
|
|
14
|
+
/**
|
|
15
|
+
* Transforms the single point
|
|
16
|
+
* @param inputs Contains a point and the transformations to apply
|
|
17
|
+
* @returns Transformed point
|
|
18
|
+
* @group transforms
|
|
19
|
+
* @shortname transform point
|
|
20
|
+
* @drawable true
|
|
21
|
+
*/
|
|
22
|
+
transformPoint(inputs: Inputs.Point.TransformPointDto): Inputs.Base.Point3;
|
|
23
|
+
/**
|
|
24
|
+
* Transforms multiple points
|
|
25
|
+
* @param inputs Contains points and the transformations to apply
|
|
26
|
+
* @returns Transformed points
|
|
27
|
+
* @group transforms
|
|
28
|
+
* @shortname transform points
|
|
29
|
+
* @drawable true
|
|
30
|
+
*/
|
|
31
|
+
transformPoints(inputs: Inputs.Point.TransformPointsDto): Inputs.Base.Point3[];
|
|
32
|
+
/**
|
|
33
|
+
* Transforms multiple points by multiple transformations
|
|
34
|
+
* @param inputs Contains points and the transformations to apply
|
|
35
|
+
* @returns Transformed points
|
|
36
|
+
* @group transforms
|
|
37
|
+
* @shortname transforms for points
|
|
38
|
+
* @drawable true
|
|
39
|
+
*/
|
|
40
|
+
transformsForPoints(inputs: Inputs.Point.TransformsForPointsDto): Inputs.Base.Point3[];
|
|
41
|
+
/**
|
|
42
|
+
* Translate multiple points
|
|
43
|
+
* @param inputs Contains points and the translation vector
|
|
44
|
+
* @returns Translated points
|
|
45
|
+
* @group transforms
|
|
46
|
+
* @shortname translate points
|
|
47
|
+
* @drawable true
|
|
48
|
+
*/
|
|
49
|
+
translatePoints(inputs: Inputs.Point.TranslatePointsDto): Inputs.Base.Point3[];
|
|
50
|
+
/**
|
|
51
|
+
* Translate multiple points
|
|
52
|
+
* @param inputs Contains points and the translation vector
|
|
53
|
+
* @returns Translated points
|
|
54
|
+
* @group transforms
|
|
55
|
+
* @shortname translate points with vectors
|
|
56
|
+
* @drawable true
|
|
57
|
+
*/
|
|
58
|
+
translatePointsWithVectors(inputs: Inputs.Point.TranslatePointsWithVectorsDto): Inputs.Base.Point3[];
|
|
59
|
+
/**
|
|
60
|
+
* Translate multiple points by x, y, z values provided
|
|
61
|
+
* @param inputs Contains points and the translation in x y and z
|
|
62
|
+
* @returns Translated points
|
|
63
|
+
* @group transforms
|
|
64
|
+
* @shortname translate xyz points
|
|
65
|
+
* @drawable true
|
|
66
|
+
*/
|
|
67
|
+
translateXYZPoints(inputs: Inputs.Point.TranslateXYZPointsDto): Inputs.Base.Point3[];
|
|
68
|
+
/**
|
|
69
|
+
* Scale multiple points by providing center point and x, y, z scale factors
|
|
70
|
+
* @param inputs Contains points, center point and scale factors
|
|
71
|
+
* @returns Scaled points
|
|
72
|
+
* @group transforms
|
|
73
|
+
* @shortname scale points on center
|
|
74
|
+
* @drawable true
|
|
75
|
+
*/
|
|
76
|
+
scalePointsCenterXYZ(inputs: Inputs.Point.ScalePointsCenterXYZDto): Inputs.Base.Point3[];
|
|
77
|
+
/**
|
|
78
|
+
* Rotate multiple points by providing center point, axis and degrees of rotation
|
|
79
|
+
* @param inputs Contains points, axis, center point and angle of rotation
|
|
80
|
+
* @returns Rotated points
|
|
81
|
+
* @group transforms
|
|
82
|
+
* @shortname rotate points center axis
|
|
83
|
+
* @drawable true
|
|
84
|
+
*/
|
|
85
|
+
rotatePointsCenterAxis(inputs: Inputs.Point.RotatePointsCenterAxisDto): Inputs.Base.Point3[];
|
|
86
|
+
/**
|
|
87
|
+
* Measures the closest distance between a point and a collection of points
|
|
88
|
+
* @param inputs Point from which to measure and points to measure the distance against
|
|
89
|
+
* @returns Distance to closest point
|
|
90
|
+
* @group extract
|
|
91
|
+
* @shortname distance to closest pt
|
|
92
|
+
* @drawable false
|
|
93
|
+
*/
|
|
94
|
+
closestPointFromPointsDistance(inputs: Inputs.Point.ClosestPointFromPointsDto): number;
|
|
95
|
+
/**
|
|
96
|
+
* Finds the closest point index between a point and a collection of points. Caution, index is not 0 based, it starts with 1.
|
|
97
|
+
* @param inputs Point from which to find the index in a collection of points
|
|
98
|
+
* @returns Closest point index
|
|
99
|
+
* @group extract
|
|
100
|
+
* @shortname index of closest pt
|
|
101
|
+
* @drawable false
|
|
102
|
+
*/
|
|
103
|
+
closestPointFromPointsIndex(inputs: Inputs.Point.ClosestPointFromPointsDto): number;
|
|
104
|
+
/**
|
|
105
|
+
* Finds the closest point in a collection
|
|
106
|
+
* @param inputs Point and points collection to find the closest point in
|
|
107
|
+
* @returns Closest point
|
|
108
|
+
* @group extract
|
|
109
|
+
* @shortname closest pt
|
|
110
|
+
* @drawable true
|
|
111
|
+
*/
|
|
112
|
+
closestPointFromPoints(inputs: Inputs.Point.ClosestPointFromPointsDto): Inputs.Base.Point3;
|
|
113
|
+
/**
|
|
114
|
+
* Finds the distance between two points
|
|
115
|
+
* @param inputs Coordinates of start and end points
|
|
116
|
+
* @returns Distance
|
|
117
|
+
* @group measure
|
|
118
|
+
* @shortname distance
|
|
119
|
+
* @drawable false
|
|
120
|
+
*/
|
|
121
|
+
distance(inputs: Inputs.Point.StartEndPointsDto): number;
|
|
122
|
+
/**
|
|
123
|
+
* Finds the distances between the start point and multiple end points
|
|
124
|
+
* @param inputs Coordinates of start and end points
|
|
125
|
+
* @returns Distances
|
|
126
|
+
* @group measure
|
|
127
|
+
* @shortname distances to points
|
|
128
|
+
* @drawable false
|
|
129
|
+
*/
|
|
130
|
+
distancesToPoints(inputs: Inputs.Point.StartEndPointsListDto): number[];
|
|
131
|
+
/**
|
|
132
|
+
* Multiply point by a specified amount
|
|
133
|
+
* @param inputs The point to be multiplied and the amount of points to create
|
|
134
|
+
* @returns Distance
|
|
135
|
+
* @group transforms
|
|
136
|
+
* @shortname multiply point
|
|
137
|
+
* @drawable true
|
|
138
|
+
*/
|
|
139
|
+
multiplyPoint(inputs: Inputs.Point.MultiplyPointDto): Inputs.Base.Point3[];
|
|
140
|
+
/**
|
|
141
|
+
* Get x coordinate of the point
|
|
142
|
+
* @param inputs The point
|
|
143
|
+
* @returns X coordinate
|
|
144
|
+
* @group get
|
|
145
|
+
* @shortname x coord
|
|
146
|
+
* @drawable false
|
|
147
|
+
*/
|
|
148
|
+
getX(inputs: Inputs.Point.PointDto): number;
|
|
149
|
+
/**
|
|
150
|
+
* Get y coordinate of the point
|
|
151
|
+
* @param inputs The point
|
|
152
|
+
* @returns Y coordinate
|
|
153
|
+
* @group get
|
|
154
|
+
* @shortname y coord
|
|
155
|
+
* @drawable false
|
|
156
|
+
*/
|
|
157
|
+
getY(inputs: Inputs.Point.PointDto): number;
|
|
158
|
+
/**
|
|
159
|
+
* Get z coordinate of the point
|
|
160
|
+
* @param inputs The point
|
|
161
|
+
* @returns Z coordinate
|
|
162
|
+
* @group get
|
|
163
|
+
* @shortname z coord
|
|
164
|
+
* @drawable false
|
|
165
|
+
*/
|
|
166
|
+
getZ(inputs: Inputs.Point.PointDto): number;
|
|
167
|
+
/**
|
|
168
|
+
* Get average point of points
|
|
169
|
+
* @param inputs The points
|
|
170
|
+
* @returns point
|
|
171
|
+
* @group extract
|
|
172
|
+
* @shortname average point
|
|
173
|
+
* @drawable true
|
|
174
|
+
*/
|
|
175
|
+
averagePoint(inputs: Inputs.Point.PointsDto): Base.Point3;
|
|
176
|
+
/**
|
|
177
|
+
* Creates the xyz point
|
|
178
|
+
* @param inputs xyz information
|
|
179
|
+
* @returns point 3d
|
|
180
|
+
* @group create
|
|
181
|
+
* @shortname point xyz
|
|
182
|
+
* @drawable true
|
|
183
|
+
*/
|
|
184
|
+
pointXYZ(inputs: Inputs.Point.PointXYZDto): Inputs.Base.Point3;
|
|
185
|
+
/**
|
|
186
|
+
* Creates the xy point
|
|
187
|
+
* @param inputs xy information
|
|
188
|
+
* @returns point 3d
|
|
189
|
+
* @group create
|
|
190
|
+
* @shortname point xy
|
|
191
|
+
* @drawable false
|
|
192
|
+
*/
|
|
193
|
+
pointXY(inputs: Inputs.Point.PointXYDto): Inputs.Base.Point2;
|
|
194
|
+
/**
|
|
195
|
+
* Creates the spiral out of multiple points
|
|
196
|
+
* @param inputs Spiral information
|
|
197
|
+
* @returns Specified number of points in the array along the spiral
|
|
198
|
+
* @group create
|
|
199
|
+
* @shortname spiral
|
|
200
|
+
* @drawable true
|
|
201
|
+
*/
|
|
202
|
+
spiral(inputs: Inputs.Point.SpiralDto): Inputs.Base.Point3[];
|
|
203
|
+
/**
|
|
204
|
+
* Creates a flat point grid on XY plane. This grid contains center points for hexagons of the given radius.
|
|
205
|
+
* Be aware that we control only the nr of hexagons to be made and not the length and width of the grid.
|
|
206
|
+
* @param inputs Information about hexagon and the grid
|
|
207
|
+
* @returns Points in the array on the grid
|
|
208
|
+
* @group create
|
|
209
|
+
* @shortname hex grid
|
|
210
|
+
* @drawable true
|
|
211
|
+
*/
|
|
212
|
+
hexGrid(inputs: Inputs.Point.HexGridCentersDto): Inputs.Base.Point3[];
|
|
213
|
+
/**
|
|
214
|
+
* Removes consecutive duplicates from the point array with tolerance
|
|
215
|
+
* @param inputs points, tolerance and check first and last
|
|
216
|
+
* @returns Points in the array without consecutive duplicates
|
|
217
|
+
* @group clean
|
|
218
|
+
* @shortname remove duplicates
|
|
219
|
+
* @drawable true
|
|
220
|
+
*/
|
|
221
|
+
removeConsecutiveDuplicates(inputs: Inputs.Point.RemoveConsecutiveDuplicatesDto): Inputs.Base.Point3[];
|
|
222
|
+
private closestPointFromPointData;
|
|
223
|
+
}
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contains various methods for points. Point in bitbybit is simply an array containing 3 numbers for [x, y, z].
|
|
3
|
+
* Because of this form Point can be interchanged with Vector, which also is an array in [x, y, z] form.
|
|
4
|
+
* When creating 2D points, z coordinate is simply set to 0 - [x, y, 0].
|
|
5
|
+
*/
|
|
6
|
+
export class Point {
|
|
7
|
+
constructor(geometryHelper, transforms) {
|
|
8
|
+
this.geometryHelper = geometryHelper;
|
|
9
|
+
this.transforms = transforms;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Transforms the single point
|
|
13
|
+
* @param inputs Contains a point and the transformations to apply
|
|
14
|
+
* @returns Transformed point
|
|
15
|
+
* @group transforms
|
|
16
|
+
* @shortname transform point
|
|
17
|
+
* @drawable true
|
|
18
|
+
*/
|
|
19
|
+
transformPoint(inputs) {
|
|
20
|
+
const transformation = inputs.transformation;
|
|
21
|
+
let transformedControlPoints = [inputs.point];
|
|
22
|
+
transformedControlPoints = this.geometryHelper.transformControlPoints(transformation, transformedControlPoints);
|
|
23
|
+
return transformedControlPoints[0];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Transforms multiple points
|
|
27
|
+
* @param inputs Contains points and the transformations to apply
|
|
28
|
+
* @returns Transformed points
|
|
29
|
+
* @group transforms
|
|
30
|
+
* @shortname transform points
|
|
31
|
+
* @drawable true
|
|
32
|
+
*/
|
|
33
|
+
transformPoints(inputs) {
|
|
34
|
+
return this.geometryHelper.transformControlPoints(inputs.transformation, inputs.points);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Transforms multiple points by multiple transformations
|
|
38
|
+
* @param inputs Contains points and the transformations to apply
|
|
39
|
+
* @returns Transformed points
|
|
40
|
+
* @group transforms
|
|
41
|
+
* @shortname transforms for points
|
|
42
|
+
* @drawable true
|
|
43
|
+
*/
|
|
44
|
+
transformsForPoints(inputs) {
|
|
45
|
+
if (inputs.points.length !== inputs.transformation.length) {
|
|
46
|
+
throw new Error("You must provide equal nr of points and transformations");
|
|
47
|
+
}
|
|
48
|
+
return inputs.points.map((pt, index) => {
|
|
49
|
+
return this.geometryHelper.transformControlPoints(inputs.transformation[index], [pt])[0];
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Translate multiple points
|
|
54
|
+
* @param inputs Contains points and the translation vector
|
|
55
|
+
* @returns Translated points
|
|
56
|
+
* @group transforms
|
|
57
|
+
* @shortname translate points
|
|
58
|
+
* @drawable true
|
|
59
|
+
*/
|
|
60
|
+
translatePoints(inputs) {
|
|
61
|
+
const translationTransform = this.transforms.translationXYZ({ translation: inputs.translation });
|
|
62
|
+
return this.geometryHelper.transformControlPoints(translationTransform, inputs.points);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Translate multiple points
|
|
66
|
+
* @param inputs Contains points and the translation vector
|
|
67
|
+
* @returns Translated points
|
|
68
|
+
* @group transforms
|
|
69
|
+
* @shortname translate points with vectors
|
|
70
|
+
* @drawable true
|
|
71
|
+
*/
|
|
72
|
+
translatePointsWithVectors(inputs) {
|
|
73
|
+
if (inputs.points.length !== inputs.translations.length) {
|
|
74
|
+
throw new Error("You must provide equal nr of points and translations");
|
|
75
|
+
}
|
|
76
|
+
const translationTransforms = this.transforms.translationsXYZ({ translations: inputs.translations });
|
|
77
|
+
return inputs.points.map((pt, index) => {
|
|
78
|
+
return this.geometryHelper.transformControlPoints(translationTransforms[index], [pt])[0];
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Translate multiple points by x, y, z values provided
|
|
83
|
+
* @param inputs Contains points and the translation in x y and z
|
|
84
|
+
* @returns Translated points
|
|
85
|
+
* @group transforms
|
|
86
|
+
* @shortname translate xyz points
|
|
87
|
+
* @drawable true
|
|
88
|
+
*/
|
|
89
|
+
translateXYZPoints(inputs) {
|
|
90
|
+
const translationTransform = this.transforms.translationXYZ({ translation: [inputs.x, inputs.y, inputs.z] });
|
|
91
|
+
return this.geometryHelper.transformControlPoints(translationTransform, inputs.points);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Scale multiple points by providing center point and x, y, z scale factors
|
|
95
|
+
* @param inputs Contains points, center point and scale factors
|
|
96
|
+
* @returns Scaled points
|
|
97
|
+
* @group transforms
|
|
98
|
+
* @shortname scale points on center
|
|
99
|
+
* @drawable true
|
|
100
|
+
*/
|
|
101
|
+
scalePointsCenterXYZ(inputs) {
|
|
102
|
+
const scaleTransforms = this.transforms.scaleCenterXYZ({ center: inputs.center, scaleXyz: inputs.scaleXyz });
|
|
103
|
+
return this.geometryHelper.transformControlPoints(scaleTransforms, inputs.points);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Rotate multiple points by providing center point, axis and degrees of rotation
|
|
107
|
+
* @param inputs Contains points, axis, center point and angle of rotation
|
|
108
|
+
* @returns Rotated points
|
|
109
|
+
* @group transforms
|
|
110
|
+
* @shortname rotate points center axis
|
|
111
|
+
* @drawable true
|
|
112
|
+
*/
|
|
113
|
+
rotatePointsCenterAxis(inputs) {
|
|
114
|
+
const rotationTransforms = this.transforms.rotationCenterAxis({ center: inputs.center, axis: inputs.axis, angle: inputs.angle });
|
|
115
|
+
return this.geometryHelper.transformControlPoints(rotationTransforms, inputs.points);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Measures the closest distance between a point and a collection of points
|
|
119
|
+
* @param inputs Point from which to measure and points to measure the distance against
|
|
120
|
+
* @returns Distance to closest point
|
|
121
|
+
* @group extract
|
|
122
|
+
* @shortname distance to closest pt
|
|
123
|
+
* @drawable false
|
|
124
|
+
*/
|
|
125
|
+
closestPointFromPointsDistance(inputs) {
|
|
126
|
+
return this.closestPointFromPointData(inputs).distance;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Finds the closest point index between a point and a collection of points. Caution, index is not 0 based, it starts with 1.
|
|
130
|
+
* @param inputs Point from which to find the index in a collection of points
|
|
131
|
+
* @returns Closest point index
|
|
132
|
+
* @group extract
|
|
133
|
+
* @shortname index of closest pt
|
|
134
|
+
* @drawable false
|
|
135
|
+
*/
|
|
136
|
+
closestPointFromPointsIndex(inputs) {
|
|
137
|
+
return this.closestPointFromPointData(inputs).index;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Finds the closest point in a collection
|
|
141
|
+
* @param inputs Point and points collection to find the closest point in
|
|
142
|
+
* @returns Closest point
|
|
143
|
+
* @group extract
|
|
144
|
+
* @shortname closest pt
|
|
145
|
+
* @drawable true
|
|
146
|
+
*/
|
|
147
|
+
closestPointFromPoints(inputs) {
|
|
148
|
+
return this.closestPointFromPointData(inputs).point;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Finds the distance between two points
|
|
152
|
+
* @param inputs Coordinates of start and end points
|
|
153
|
+
* @returns Distance
|
|
154
|
+
* @group measure
|
|
155
|
+
* @shortname distance
|
|
156
|
+
* @drawable false
|
|
157
|
+
*/
|
|
158
|
+
distance(inputs) {
|
|
159
|
+
const x = inputs.endPoint[0] - inputs.startPoint[0];
|
|
160
|
+
const y = inputs.endPoint[1] - inputs.startPoint[1];
|
|
161
|
+
const z = inputs.endPoint[2] - inputs.startPoint[2];
|
|
162
|
+
return Math.sqrt(x * x + y * y + z * z);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Finds the distances between the start point and multiple end points
|
|
166
|
+
* @param inputs Coordinates of start and end points
|
|
167
|
+
* @returns Distances
|
|
168
|
+
* @group measure
|
|
169
|
+
* @shortname distances to points
|
|
170
|
+
* @drawable false
|
|
171
|
+
*/
|
|
172
|
+
distancesToPoints(inputs) {
|
|
173
|
+
return inputs.endPoints.map(pt => {
|
|
174
|
+
return this.distance({ startPoint: inputs.startPoint, endPoint: pt });
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Multiply point by a specified amount
|
|
179
|
+
* @param inputs The point to be multiplied and the amount of points to create
|
|
180
|
+
* @returns Distance
|
|
181
|
+
* @group transforms
|
|
182
|
+
* @shortname multiply point
|
|
183
|
+
* @drawable true
|
|
184
|
+
*/
|
|
185
|
+
multiplyPoint(inputs) {
|
|
186
|
+
const points = [];
|
|
187
|
+
for (let i = 0; i < inputs.amountOfPoints; i++) {
|
|
188
|
+
points.push([inputs.point[0], inputs.point[1], inputs.point[2]]);
|
|
189
|
+
}
|
|
190
|
+
return points;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Get x coordinate of the point
|
|
194
|
+
* @param inputs The point
|
|
195
|
+
* @returns X coordinate
|
|
196
|
+
* @group get
|
|
197
|
+
* @shortname x coord
|
|
198
|
+
* @drawable false
|
|
199
|
+
*/
|
|
200
|
+
getX(inputs) {
|
|
201
|
+
return inputs.point[0];
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Get y coordinate of the point
|
|
205
|
+
* @param inputs The point
|
|
206
|
+
* @returns Y coordinate
|
|
207
|
+
* @group get
|
|
208
|
+
* @shortname y coord
|
|
209
|
+
* @drawable false
|
|
210
|
+
*/
|
|
211
|
+
getY(inputs) {
|
|
212
|
+
return inputs.point[1];
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Get z coordinate of the point
|
|
216
|
+
* @param inputs The point
|
|
217
|
+
* @returns Z coordinate
|
|
218
|
+
* @group get
|
|
219
|
+
* @shortname z coord
|
|
220
|
+
* @drawable false
|
|
221
|
+
*/
|
|
222
|
+
getZ(inputs) {
|
|
223
|
+
return inputs.point[2];
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Get average point of points
|
|
227
|
+
* @param inputs The points
|
|
228
|
+
* @returns point
|
|
229
|
+
* @group extract
|
|
230
|
+
* @shortname average point
|
|
231
|
+
* @drawable true
|
|
232
|
+
*/
|
|
233
|
+
averagePoint(inputs) {
|
|
234
|
+
const xVals = [];
|
|
235
|
+
const yVals = [];
|
|
236
|
+
const zVals = [];
|
|
237
|
+
inputs.points.forEach(pt => {
|
|
238
|
+
xVals.push(pt[0]);
|
|
239
|
+
yVals.push(pt[1]);
|
|
240
|
+
zVals.push(pt[2]);
|
|
241
|
+
});
|
|
242
|
+
return [
|
|
243
|
+
xVals.reduce((p, c) => p + c, 0) / inputs.points.length,
|
|
244
|
+
yVals.reduce((p, c) => p + c, 0) / inputs.points.length,
|
|
245
|
+
zVals.reduce((p, c) => p + c, 0) / inputs.points.length,
|
|
246
|
+
];
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Creates the xyz point
|
|
250
|
+
* @param inputs xyz information
|
|
251
|
+
* @returns point 3d
|
|
252
|
+
* @group create
|
|
253
|
+
* @shortname point xyz
|
|
254
|
+
* @drawable true
|
|
255
|
+
*/
|
|
256
|
+
pointXYZ(inputs) {
|
|
257
|
+
return [inputs.x, inputs.y, inputs.z];
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Creates the xy point
|
|
261
|
+
* @param inputs xy information
|
|
262
|
+
* @returns point 3d
|
|
263
|
+
* @group create
|
|
264
|
+
* @shortname point xy
|
|
265
|
+
* @drawable false
|
|
266
|
+
*/
|
|
267
|
+
pointXY(inputs) {
|
|
268
|
+
return [inputs.x, inputs.y];
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Creates the spiral out of multiple points
|
|
272
|
+
* @param inputs Spiral information
|
|
273
|
+
* @returns Specified number of points in the array along the spiral
|
|
274
|
+
* @group create
|
|
275
|
+
* @shortname spiral
|
|
276
|
+
* @drawable true
|
|
277
|
+
*/
|
|
278
|
+
spiral(inputs) {
|
|
279
|
+
const phi = inputs.phi;
|
|
280
|
+
const b = Math.log(phi) / (Math.PI / inputs.widening);
|
|
281
|
+
const spiral = [];
|
|
282
|
+
const step = inputs.radius / inputs.numberPoints;
|
|
283
|
+
for (let i = 0; i < inputs.radius; i += step) {
|
|
284
|
+
const th = Math.log(i / inputs.factor) / b;
|
|
285
|
+
const x = i * Math.cos(th);
|
|
286
|
+
const y = i * Math.sin(th);
|
|
287
|
+
spiral.push([x ? x : 0, y ? y : 0, 0]);
|
|
288
|
+
}
|
|
289
|
+
return spiral;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Creates a flat point grid on XY plane. This grid contains center points for hexagons of the given radius.
|
|
293
|
+
* Be aware that we control only the nr of hexagons to be made and not the length and width of the grid.
|
|
294
|
+
* @param inputs Information about hexagon and the grid
|
|
295
|
+
* @returns Points in the array on the grid
|
|
296
|
+
* @group create
|
|
297
|
+
* @shortname hex grid
|
|
298
|
+
* @drawable true
|
|
299
|
+
*/
|
|
300
|
+
hexGrid(inputs) {
|
|
301
|
+
const xLength = Math.sqrt(Math.pow(inputs.radiusHexagon, 2) - Math.pow(inputs.radiusHexagon / 2, 2));
|
|
302
|
+
const points = [];
|
|
303
|
+
for (let ix = 0; ix < inputs.nrHexagonsX; ix++) {
|
|
304
|
+
const coordX = ix * xLength * 2;
|
|
305
|
+
for (let iy = 0; iy < inputs.nrHexagonsY; iy++) {
|
|
306
|
+
const coordY = (inputs.radiusHexagon + inputs.radiusHexagon / 2) * iy;
|
|
307
|
+
const adjustX = coordX + (iy % 2 === 0 ? 0 : xLength);
|
|
308
|
+
points.push([adjustX, coordY, 0]);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (inputs.orientOnCenter) {
|
|
312
|
+
const compensateX = points[points.length - 1][0] / 2;
|
|
313
|
+
const compensateY = points[points.length - 1][1] / 2;
|
|
314
|
+
points.forEach((p, index) => {
|
|
315
|
+
points[index] = [p[0] - compensateX, p[1] - compensateY, 0];
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
if (inputs.pointsOnGround) {
|
|
319
|
+
points.forEach((p, index) => {
|
|
320
|
+
points[index] = [p[0], 0, p[1]];
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
return points;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Removes consecutive duplicates from the point array with tolerance
|
|
327
|
+
* @param inputs points, tolerance and check first and last
|
|
328
|
+
* @returns Points in the array without consecutive duplicates
|
|
329
|
+
* @group clean
|
|
330
|
+
* @shortname remove duplicates
|
|
331
|
+
* @drawable true
|
|
332
|
+
*/
|
|
333
|
+
removeConsecutiveDuplicates(inputs) {
|
|
334
|
+
return this.geometryHelper.removeConsecutivePointDuplicates(inputs.points, inputs.checkFirstAndLast, inputs.tolerance);
|
|
335
|
+
}
|
|
336
|
+
closestPointFromPointData(inputs) {
|
|
337
|
+
let distance = Number.MAX_SAFE_INTEGER;
|
|
338
|
+
let closestPointIndex;
|
|
339
|
+
let point;
|
|
340
|
+
for (let i = 0; i < inputs.points.length; i++) {
|
|
341
|
+
const pt = inputs.points[i];
|
|
342
|
+
const currentDist = this.distance({ startPoint: inputs.point, endPoint: pt });
|
|
343
|
+
if (currentDist < distance) {
|
|
344
|
+
distance = currentDist;
|
|
345
|
+
closestPointIndex = i;
|
|
346
|
+
point = pt;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return { index: closestPointIndex + 1, distance, point };
|
|
350
|
+
}
|
|
351
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as Inputs from "../inputs/inputs";
|
|
2
|
+
/**
|
|
3
|
+
* Contains various text methods.
|
|
4
|
+
*/
|
|
5
|
+
export declare class TextBitByBit {
|
|
6
|
+
/**
|
|
7
|
+
* Creates a text
|
|
8
|
+
* @param inputs a text
|
|
9
|
+
* @returns text
|
|
10
|
+
* @group create
|
|
11
|
+
* @shortname text
|
|
12
|
+
* @drawable false
|
|
13
|
+
*/
|
|
14
|
+
create(inputs: Inputs.Text.TextDto): string;
|
|
15
|
+
/**
|
|
16
|
+
* Split the text to multiple pieces by a separator
|
|
17
|
+
* @param inputs a text
|
|
18
|
+
* @returns text
|
|
19
|
+
* @group transform
|
|
20
|
+
* @shortname split
|
|
21
|
+
* @drawable false
|
|
22
|
+
*/
|
|
23
|
+
split(inputs: Inputs.Text.TextSplitDto): string[];
|
|
24
|
+
/**
|
|
25
|
+
* Replace all occurrences of a text by another text
|
|
26
|
+
* @param inputs a text
|
|
27
|
+
* @returns text
|
|
28
|
+
* @group transform
|
|
29
|
+
* @shortname replaceAll
|
|
30
|
+
* @drawable false
|
|
31
|
+
*/
|
|
32
|
+
replaceAll(inputs: Inputs.Text.TextReplaceDto): string;
|
|
33
|
+
/**
|
|
34
|
+
* Join multiple items by a separator into text
|
|
35
|
+
* @param inputs a list of items
|
|
36
|
+
* @returns text
|
|
37
|
+
* @group transform
|
|
38
|
+
* @shortname join
|
|
39
|
+
* @drawable false
|
|
40
|
+
*/
|
|
41
|
+
join(inputs: Inputs.Text.TextJoinDto): string;
|
|
42
|
+
/**
|
|
43
|
+
* Transform any item to text
|
|
44
|
+
* @param inputs any item
|
|
45
|
+
* @returns text
|
|
46
|
+
* @group transform
|
|
47
|
+
* @shortname to string
|
|
48
|
+
* @drawable false
|
|
49
|
+
*/
|
|
50
|
+
toString<T>(inputs: Inputs.Text.ToStringDto<T>): string;
|
|
51
|
+
/**
|
|
52
|
+
* Transform each item in list to text
|
|
53
|
+
* @param inputs list of items
|
|
54
|
+
* @returns texts
|
|
55
|
+
* @group transform
|
|
56
|
+
* @shortname to strings
|
|
57
|
+
* @drawable false
|
|
58
|
+
*/
|
|
59
|
+
toStringEach<T>(inputs: Inputs.Text.ToStringEachDto<T>): string[];
|
|
60
|
+
/**
|
|
61
|
+
* Format a text with values
|
|
62
|
+
* @param inputs a text and values
|
|
63
|
+
* @returns formatted text
|
|
64
|
+
* @group transform
|
|
65
|
+
* @shortname format
|
|
66
|
+
* @drawable false
|
|
67
|
+
*/
|
|
68
|
+
format(inputs: Inputs.Text.TextFormatDto): string;
|
|
69
|
+
}
|