@bitbybit-dev/base 1.2.0-rc.2 → 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
|
@@ -3,141 +3,228 @@ import * as Inputs from "../inputs";
|
|
|
3
3
|
import { MathBitByBit } from "./math";
|
|
4
4
|
import { Vector } from "./vector";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Builds transformation matrices for moving, rotating, scaling and stretching geometry. A
|
|
7
|
+
* transformation is a 4x4 matrix as 16 numbers in column-major order; most methods return a short
|
|
8
|
+
* list of them that is applied in order, so a rotation about a point is a move to the origin, the
|
|
9
|
+
* rotation, and the move back. Angles are in degrees. Apply the result with the transform methods
|
|
10
|
+
* of `point`, `polyline`, `line` and the kernels.
|
|
9
11
|
*/
|
|
10
12
|
export declare class Transforms {
|
|
11
13
|
private readonly vector;
|
|
12
14
|
private readonly math;
|
|
13
15
|
constructor(vector: Vector, math: MathBitByBit);
|
|
14
16
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
17
|
+
* Builds a rotation about an axis that passes through a center point.
|
|
18
|
+
*
|
|
19
|
+
* The result is three matrices applied in order: move the center to the origin, rotate, move
|
|
20
|
+
* back. The angle is in degrees; positive turns counter-clockwise when the axis points toward
|
|
21
|
+
* you.
|
|
22
|
+
* Example: center [5,0,0], axis [0,1,0], angle 90 -> a quarter turn about the vertical line
|
|
23
|
+
* through [5,0,0]
|
|
24
|
+
* @param inputs - The axis direction, the center it passes through and the angle in degrees
|
|
25
|
+
* @returns The list of matrices to apply in order
|
|
20
26
|
* @group rotation
|
|
21
27
|
* @shortname center axis
|
|
22
28
|
* @drawable false
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const turn = bitbybit.transforms.rotationCenterAxis({ center: [5, 0, 0], axis: [0, 1, 0], angle: 90 });
|
|
32
|
+
* const points = bitbybit.point.transformPoints({ points: [[10, 0, 0]], transformation: turn });
|
|
33
|
+
* ```
|
|
23
34
|
*/
|
|
24
35
|
rotationCenterAxis(inputs: Inputs.Transforms.RotationCenterAxisDto): Base.TransformMatrixes;
|
|
25
36
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
37
|
+
* Builds a rotation about a line parallel to the X axis through a center point.
|
|
38
|
+
*
|
|
39
|
+
* The result is three matrices applied in order: move the center to the origin, rotate, move
|
|
40
|
+
* back. The angle is in degrees; positive turns counter-clockwise when the axis points toward
|
|
41
|
+
* you.
|
|
42
|
+
* Example: center [0,0,0], angle 90 -> a quarter turn about the X axis
|
|
43
|
+
* @param inputs - The center and the angle in degrees
|
|
44
|
+
* @returns The list of matrices to apply in order
|
|
30
45
|
* @group rotation
|
|
31
46
|
* @shortname center x
|
|
32
47
|
* @drawable false
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const turn = bitbybit.transforms.rotationCenterX({ center: [0, 0, 0], angle: 90 });
|
|
51
|
+
* ```
|
|
33
52
|
*/
|
|
34
53
|
rotationCenterX(inputs: Inputs.Transforms.RotationCenterDto): Base.TransformMatrixes;
|
|
35
54
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
55
|
+
* Builds a rotation about a line parallel to the Y axis through a center point.
|
|
56
|
+
*
|
|
57
|
+
* The result is three matrices applied in order: move the center to the origin, rotate, move
|
|
58
|
+
* back. The angle is in degrees; positive turns counter-clockwise when the axis points toward
|
|
59
|
+
* you.
|
|
60
|
+
* Example: center [0,0,0], angle 90 -> a quarter turn about the Y axis
|
|
61
|
+
* @param inputs - The center and the angle in degrees
|
|
62
|
+
* @returns The list of matrices to apply in order
|
|
40
63
|
* @group rotation
|
|
41
64
|
* @shortname center y
|
|
42
65
|
* @drawable false
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const turn = bitbybit.transforms.rotationCenterY({ center: [0, 0, 0], angle: 90 });
|
|
69
|
+
* ```
|
|
43
70
|
*/
|
|
44
71
|
rotationCenterY(inputs: Inputs.Transforms.RotationCenterDto): Base.TransformMatrixes;
|
|
45
72
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
73
|
+
* Builds a rotation about a line parallel to the Z axis through a center point.
|
|
74
|
+
*
|
|
75
|
+
* The result is three matrices applied in order: move the center to the origin, rotate, move
|
|
76
|
+
* back. The angle is in degrees; positive turns counter-clockwise when the axis points toward
|
|
77
|
+
* you.
|
|
78
|
+
* Example: center [0,0,0], angle 90 -> a quarter turn about the Z axis
|
|
79
|
+
* @param inputs - The center and the angle in degrees
|
|
80
|
+
* @returns The list of matrices to apply in order
|
|
50
81
|
* @group rotation
|
|
51
82
|
* @shortname center z
|
|
52
83
|
* @drawable false
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* const turn = bitbybit.transforms.rotationCenterZ({ center: [0, 0, 0], angle: 90 });
|
|
87
|
+
* ```
|
|
53
88
|
*/
|
|
54
89
|
rotationCenterZ(inputs: Inputs.Transforms.RotationCenterDto): Base.TransformMatrixes;
|
|
55
90
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
91
|
+
* Builds a rotation from three angles about a center point: yaw turns about Y, pitch about X
|
|
92
|
+
* and roll about Z.
|
|
93
|
+
*
|
|
94
|
+
* The result is three matrices applied in order: move the center to the origin, rotate, move
|
|
95
|
+
* back. Angles are in degrees.
|
|
96
|
+
* Example: yaw 90, pitch 0, roll 0 -> a quarter turn about the vertical axis
|
|
97
|
+
* @param inputs - The yaw, pitch and roll in degrees and the center
|
|
98
|
+
* @returns The list of matrices to apply in order
|
|
61
99
|
* @group rotation
|
|
62
100
|
* @shortname yaw pitch roll
|
|
63
101
|
* @drawable false
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const turn = bitbybit.transforms.rotationCenterYawPitchRoll({ yaw: 90, pitch: 0, roll: 0, center: [0, 0, 0] });
|
|
105
|
+
* ```
|
|
64
106
|
*/
|
|
65
107
|
rotationCenterYawPitchRoll(inputs: Inputs.Transforms.RotationCenterYawPitchRollDto): Base.TransformMatrixes;
|
|
66
108
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
109
|
+
* Builds a scale with its own factor per axis, measured from a center point that stays in
|
|
110
|
+
* place.
|
|
111
|
+
*
|
|
112
|
+
* The result is three matrices applied in order: move the center to the origin, scale, move
|
|
113
|
+
* back.
|
|
114
|
+
* Example: center [5,5,5], factors [2,1,0.5] -> doubles X, keeps Y, halves Z about [5,5,5]
|
|
115
|
+
* @param inputs - The center and the factor for each axis
|
|
116
|
+
* @returns The list of matrices to apply in order
|
|
71
117
|
* @group scale
|
|
72
118
|
* @shortname center xyz
|
|
73
119
|
* @drawable false
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* const scale = bitbybit.transforms.scaleCenterXYZ({ center: [5, 5, 5], scaleXyz: [2, 1, 0.5] });
|
|
123
|
+
* ```
|
|
74
124
|
*/
|
|
75
125
|
scaleCenterXYZ(inputs: Inputs.Transforms.ScaleCenterXYZDto): Base.TransformMatrixes;
|
|
76
126
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* @
|
|
127
|
+
* Builds a scale with its own factor per axis, measured from the origin.
|
|
128
|
+
*
|
|
129
|
+
* Example: factors [2,3,1] -> doubles X, triples Y, keeps Z
|
|
130
|
+
* @param inputs - The factor for each axis
|
|
131
|
+
* @returns A list with the one scale matrix
|
|
81
132
|
* @group scale
|
|
82
133
|
* @shortname xyz
|
|
83
134
|
* @drawable false
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* const scale = bitbybit.transforms.scaleXYZ({ scaleXyz: [2, 3, 1] });
|
|
138
|
+
* ```
|
|
84
139
|
*/
|
|
85
140
|
scaleXYZ(inputs: Inputs.Transforms.ScaleXYZDto): Base.TransformMatrixes;
|
|
86
141
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
142
|
+
* Builds a stretch along one direction, measured from a center point; distances across that
|
|
143
|
+
* direction stay as they are.
|
|
144
|
+
*
|
|
145
|
+
* The result is three matrices applied in order: move the center to the origin, stretch, move
|
|
146
|
+
* back.
|
|
147
|
+
* Example: center [0,0,0], direction [1,0,0], scale 2 -> everything twice as far from the
|
|
148
|
+
* center along X
|
|
149
|
+
* @param inputs - The center, the direction and the factor
|
|
150
|
+
* @returns The list of matrices to apply in order
|
|
92
151
|
* @group scale
|
|
93
152
|
* @shortname stretch dir center
|
|
94
153
|
* @drawable false
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* const stretch = bitbybit.transforms.stretchDirFromCenter({ center: [0, 0, 0], direction: [1, 0, 0], scale: 2 });
|
|
157
|
+
* ```
|
|
95
158
|
*/
|
|
96
159
|
stretchDirFromCenter(inputs: Inputs.Transforms.StretchDirCenterDto): Base.TransformMatrixes;
|
|
97
160
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* @
|
|
161
|
+
* Builds a scale by the same factor on every axis, measured from the origin.
|
|
162
|
+
*
|
|
163
|
+
* Example: 2 -> everything twice as big and twice as far from the origin
|
|
164
|
+
* @param inputs - The factor
|
|
165
|
+
* @returns A list with the one scale matrix
|
|
102
166
|
* @group scale
|
|
103
167
|
* @shortname uniform
|
|
104
168
|
* @drawable false
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* const scale = bitbybit.transforms.uniformScale({ scale: 2 });
|
|
172
|
+
* ```
|
|
105
173
|
*/
|
|
106
174
|
uniformScale(inputs: Inputs.Transforms.UniformScaleDto): Base.TransformMatrixes;
|
|
107
175
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
176
|
+
* Builds a scale by the same factor on every axis, measured from a center point that stays in
|
|
177
|
+
* place.
|
|
178
|
+
*
|
|
179
|
+
* The result is three matrices applied in order: move the center to the origin, scale, move
|
|
180
|
+
* back.
|
|
181
|
+
* Example: center [5,5,5], scale 0.5 -> everything half as big, shrinking toward [5,5,5]
|
|
182
|
+
* @param inputs - The factor and the center
|
|
183
|
+
* @returns The list of matrices to apply in order
|
|
112
184
|
* @group scale
|
|
113
185
|
* @shortname uniform from center
|
|
114
186
|
* @drawable false
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* const scale = bitbybit.transforms.uniformScaleFromCenter({ center: [5, 5, 5], scale: 0.5 });
|
|
190
|
+
* ```
|
|
115
191
|
*/
|
|
116
192
|
uniformScaleFromCenter(inputs: Inputs.Transforms.UniformScaleFromCenterDto): Base.TransformMatrixes;
|
|
117
193
|
/**
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* @
|
|
194
|
+
* Builds a move by a vector.
|
|
195
|
+
*
|
|
196
|
+
* Example: [10,5,0] -> 10 along X, 5 along Y, nothing along Z
|
|
197
|
+
* @param inputs - The vector to move by
|
|
198
|
+
* @returns A list with the one translation matrix
|
|
122
199
|
* @group translation
|
|
123
200
|
* @shortname xyz
|
|
124
201
|
* @drawable false
|
|
202
|
+
* @example
|
|
203
|
+
* ```typescript
|
|
204
|
+
* const move = bitbybit.transforms.translationXYZ({ translation: [10, 5, 0] });
|
|
205
|
+
* ```
|
|
125
206
|
*/
|
|
126
207
|
translationXYZ(inputs: Inputs.Transforms.TranslationXYZDto): Base.TransformMatrixes;
|
|
127
208
|
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
209
|
+
* Builds one move per vector, for transforming many points each by its own vector.
|
|
210
|
+
*
|
|
211
|
+
* Example: [[1,0,0], [0,2,0]] -> two transformations: one along X, one along Y
|
|
212
|
+
* @param inputs - The vectors to move by
|
|
213
|
+
* @returns One transformation per vector, in the same order
|
|
132
214
|
* @group translations
|
|
133
215
|
* @shortname xyz
|
|
134
216
|
* @drawable false
|
|
135
|
-
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* const moves = bitbybit.transforms.translationsXYZ({ translations: [[1, 0, 0], [0, 2, 0]] });
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
136
222
|
translationsXYZ(inputs: Inputs.Transforms.TranslationsXYZDto): Base.TransformMatrixes[];
|
|
137
223
|
/**
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
224
|
+
* Gives the matrix that changes nothing, as a starting point or a placeholder.
|
|
225
|
+
*
|
|
226
|
+
* Example: [1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1]
|
|
227
|
+
* @returns The identity matrix
|
|
141
228
|
* @group identity
|
|
142
229
|
* @shortname identity
|
|
143
230
|
* @drawable false
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Builds transformation matrices for moving, rotating, scaling and stretching geometry. A
|
|
3
|
+
* transformation is a 4x4 matrix as 16 numbers in column-major order; most methods return a short
|
|
4
|
+
* list of them that is applied in order, so a rotation about a point is a move to the origin, the
|
|
5
|
+
* rotation, and the move back. Angles are in degrees. Apply the result with the transform methods
|
|
6
|
+
* of `point`, `polyline`, `line` and the kernels.
|
|
5
7
|
*/
|
|
6
8
|
export class Transforms {
|
|
7
9
|
constructor(vector, math) {
|
|
@@ -9,14 +11,23 @@ export class Transforms {
|
|
|
9
11
|
this.math = math;
|
|
10
12
|
}
|
|
11
13
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* Builds a rotation about an axis that passes through a center point.
|
|
15
|
+
*
|
|
16
|
+
* The result is three matrices applied in order: move the center to the origin, rotate, move
|
|
17
|
+
* back. The angle is in degrees; positive turns counter-clockwise when the axis points toward
|
|
18
|
+
* you.
|
|
19
|
+
* Example: center [5,0,0], axis [0,1,0], angle 90 -> a quarter turn about the vertical line
|
|
20
|
+
* through [5,0,0]
|
|
21
|
+
* @param inputs - The axis direction, the center it passes through and the angle in degrees
|
|
22
|
+
* @returns The list of matrices to apply in order
|
|
17
23
|
* @group rotation
|
|
18
24
|
* @shortname center axis
|
|
19
25
|
* @drawable false
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const turn = bitbybit.transforms.rotationCenterAxis({ center: [5, 0, 0], axis: [0, 1, 0], angle: 90 });
|
|
29
|
+
* const points = bitbybit.point.transformPoints({ points: [[10, 0, 0]], transformation: turn });
|
|
30
|
+
* ```
|
|
20
31
|
*/
|
|
21
32
|
rotationCenterAxis(inputs) {
|
|
22
33
|
return [
|
|
@@ -26,13 +37,21 @@ export class Transforms {
|
|
|
26
37
|
];
|
|
27
38
|
}
|
|
28
39
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
40
|
+
* Builds a rotation about a line parallel to the X axis through a center point.
|
|
41
|
+
*
|
|
42
|
+
* The result is three matrices applied in order: move the center to the origin, rotate, move
|
|
43
|
+
* back. The angle is in degrees; positive turns counter-clockwise when the axis points toward
|
|
44
|
+
* you.
|
|
45
|
+
* Example: center [0,0,0], angle 90 -> a quarter turn about the X axis
|
|
46
|
+
* @param inputs - The center and the angle in degrees
|
|
47
|
+
* @returns The list of matrices to apply in order
|
|
33
48
|
* @group rotation
|
|
34
49
|
* @shortname center x
|
|
35
50
|
* @drawable false
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const turn = bitbybit.transforms.rotationCenterX({ center: [0, 0, 0], angle: 90 });
|
|
54
|
+
* ```
|
|
36
55
|
*/
|
|
37
56
|
rotationCenterX(inputs) {
|
|
38
57
|
return [
|
|
@@ -42,13 +61,21 @@ export class Transforms {
|
|
|
42
61
|
];
|
|
43
62
|
}
|
|
44
63
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
64
|
+
* Builds a rotation about a line parallel to the Y axis through a center point.
|
|
65
|
+
*
|
|
66
|
+
* The result is three matrices applied in order: move the center to the origin, rotate, move
|
|
67
|
+
* back. The angle is in degrees; positive turns counter-clockwise when the axis points toward
|
|
68
|
+
* you.
|
|
69
|
+
* Example: center [0,0,0], angle 90 -> a quarter turn about the Y axis
|
|
70
|
+
* @param inputs - The center and the angle in degrees
|
|
71
|
+
* @returns The list of matrices to apply in order
|
|
49
72
|
* @group rotation
|
|
50
73
|
* @shortname center y
|
|
51
74
|
* @drawable false
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const turn = bitbybit.transforms.rotationCenterY({ center: [0, 0, 0], angle: 90 });
|
|
78
|
+
* ```
|
|
52
79
|
*/
|
|
53
80
|
rotationCenterY(inputs) {
|
|
54
81
|
return [
|
|
@@ -58,13 +85,21 @@ export class Transforms {
|
|
|
58
85
|
];
|
|
59
86
|
}
|
|
60
87
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
88
|
+
* Builds a rotation about a line parallel to the Z axis through a center point.
|
|
89
|
+
*
|
|
90
|
+
* The result is three matrices applied in order: move the center to the origin, rotate, move
|
|
91
|
+
* back. The angle is in degrees; positive turns counter-clockwise when the axis points toward
|
|
92
|
+
* you.
|
|
93
|
+
* Example: center [0,0,0], angle 90 -> a quarter turn about the Z axis
|
|
94
|
+
* @param inputs - The center and the angle in degrees
|
|
95
|
+
* @returns The list of matrices to apply in order
|
|
65
96
|
* @group rotation
|
|
66
97
|
* @shortname center z
|
|
67
98
|
* @drawable false
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const turn = bitbybit.transforms.rotationCenterZ({ center: [0, 0, 0], angle: 90 });
|
|
102
|
+
* ```
|
|
68
103
|
*/
|
|
69
104
|
rotationCenterZ(inputs) {
|
|
70
105
|
return [
|
|
@@ -74,14 +109,21 @@ export class Transforms {
|
|
|
74
109
|
];
|
|
75
110
|
}
|
|
76
111
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
112
|
+
* Builds a rotation from three angles about a center point: yaw turns about Y, pitch about X
|
|
113
|
+
* and roll about Z.
|
|
114
|
+
*
|
|
115
|
+
* The result is three matrices applied in order: move the center to the origin, rotate, move
|
|
116
|
+
* back. Angles are in degrees.
|
|
117
|
+
* Example: yaw 90, pitch 0, roll 0 -> a quarter turn about the vertical axis
|
|
118
|
+
* @param inputs - The yaw, pitch and roll in degrees and the center
|
|
119
|
+
* @returns The list of matrices to apply in order
|
|
82
120
|
* @group rotation
|
|
83
121
|
* @shortname yaw pitch roll
|
|
84
122
|
* @drawable false
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const turn = bitbybit.transforms.rotationCenterYawPitchRoll({ yaw: 90, pitch: 0, roll: 0, center: [0, 0, 0] });
|
|
126
|
+
* ```
|
|
85
127
|
*/
|
|
86
128
|
rotationCenterYawPitchRoll(inputs) {
|
|
87
129
|
return [
|
|
@@ -91,13 +133,21 @@ export class Transforms {
|
|
|
91
133
|
];
|
|
92
134
|
}
|
|
93
135
|
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
136
|
+
* Builds a scale with its own factor per axis, measured from a center point that stays in
|
|
137
|
+
* place.
|
|
138
|
+
*
|
|
139
|
+
* The result is three matrices applied in order: move the center to the origin, scale, move
|
|
140
|
+
* back.
|
|
141
|
+
* Example: center [5,5,5], factors [2,1,0.5] -> doubles X, keeps Y, halves Z about [5,5,5]
|
|
142
|
+
* @param inputs - The center and the factor for each axis
|
|
143
|
+
* @returns The list of matrices to apply in order
|
|
98
144
|
* @group scale
|
|
99
145
|
* @shortname center xyz
|
|
100
146
|
* @drawable false
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* const scale = bitbybit.transforms.scaleCenterXYZ({ center: [5, 5, 5], scaleXyz: [2, 1, 0.5] });
|
|
150
|
+
* ```
|
|
101
151
|
*/
|
|
102
152
|
scaleCenterXYZ(inputs) {
|
|
103
153
|
return [
|
|
@@ -107,26 +157,39 @@ export class Transforms {
|
|
|
107
157
|
];
|
|
108
158
|
}
|
|
109
159
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
* @
|
|
160
|
+
* Builds a scale with its own factor per axis, measured from the origin.
|
|
161
|
+
*
|
|
162
|
+
* Example: factors [2,3,1] -> doubles X, triples Y, keeps Z
|
|
163
|
+
* @param inputs - The factor for each axis
|
|
164
|
+
* @returns A list with the one scale matrix
|
|
114
165
|
* @group scale
|
|
115
166
|
* @shortname xyz
|
|
116
167
|
* @drawable false
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const scale = bitbybit.transforms.scaleXYZ({ scaleXyz: [2, 3, 1] });
|
|
171
|
+
* ```
|
|
117
172
|
*/
|
|
118
173
|
scaleXYZ(inputs) {
|
|
119
174
|
return [this.scaling(inputs.scaleXyz[0], inputs.scaleXyz[1], inputs.scaleXyz[2])];
|
|
120
175
|
}
|
|
121
176
|
/**
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
177
|
+
* Builds a stretch along one direction, measured from a center point; distances across that
|
|
178
|
+
* direction stay as they are.
|
|
179
|
+
*
|
|
180
|
+
* The result is three matrices applied in order: move the center to the origin, stretch, move
|
|
181
|
+
* back.
|
|
182
|
+
* Example: center [0,0,0], direction [1,0,0], scale 2 -> everything twice as far from the
|
|
183
|
+
* center along X
|
|
184
|
+
* @param inputs - The center, the direction and the factor
|
|
185
|
+
* @returns The list of matrices to apply in order
|
|
127
186
|
* @group scale
|
|
128
187
|
* @shortname stretch dir center
|
|
129
188
|
* @drawable false
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* const stretch = bitbybit.transforms.stretchDirFromCenter({ center: [0, 0, 0], direction: [1, 0, 0], scale: 2 });
|
|
192
|
+
* ```
|
|
130
193
|
*/
|
|
131
194
|
stretchDirFromCenter(inputs) {
|
|
132
195
|
const { center = [0, 0, 0], direction = [0, 0, 1], scale = 2 } = inputs;
|
|
@@ -137,25 +200,38 @@ export class Transforms {
|
|
|
137
200
|
];
|
|
138
201
|
}
|
|
139
202
|
/**
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
* @
|
|
203
|
+
* Builds a scale by the same factor on every axis, measured from the origin.
|
|
204
|
+
*
|
|
205
|
+
* Example: 2 -> everything twice as big and twice as far from the origin
|
|
206
|
+
* @param inputs - The factor
|
|
207
|
+
* @returns A list with the one scale matrix
|
|
144
208
|
* @group scale
|
|
145
209
|
* @shortname uniform
|
|
146
210
|
* @drawable false
|
|
211
|
+
* @example
|
|
212
|
+
* ```typescript
|
|
213
|
+
* const scale = bitbybit.transforms.uniformScale({ scale: 2 });
|
|
214
|
+
* ```
|
|
147
215
|
*/
|
|
148
216
|
uniformScale(inputs) {
|
|
149
217
|
return [this.scaling(inputs.scale, inputs.scale, inputs.scale)];
|
|
150
218
|
}
|
|
151
219
|
/**
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
220
|
+
* Builds a scale by the same factor on every axis, measured from a center point that stays in
|
|
221
|
+
* place.
|
|
222
|
+
*
|
|
223
|
+
* The result is three matrices applied in order: move the center to the origin, scale, move
|
|
224
|
+
* back.
|
|
225
|
+
* Example: center [5,5,5], scale 0.5 -> everything half as big, shrinking toward [5,5,5]
|
|
226
|
+
* @param inputs - The factor and the center
|
|
227
|
+
* @returns The list of matrices to apply in order
|
|
156
228
|
* @group scale
|
|
157
229
|
* @shortname uniform from center
|
|
158
230
|
* @drawable false
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* const scale = bitbybit.transforms.uniformScaleFromCenter({ center: [5, 5, 5], scale: 0.5 });
|
|
234
|
+
* ```
|
|
159
235
|
*/
|
|
160
236
|
uniformScaleFromCenter(inputs) {
|
|
161
237
|
return [
|
|
@@ -165,33 +241,44 @@ export class Transforms {
|
|
|
165
241
|
];
|
|
166
242
|
}
|
|
167
243
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
* @
|
|
244
|
+
* Builds a move by a vector.
|
|
245
|
+
*
|
|
246
|
+
* Example: [10,5,0] -> 10 along X, 5 along Y, nothing along Z
|
|
247
|
+
* @param inputs - The vector to move by
|
|
248
|
+
* @returns A list with the one translation matrix
|
|
172
249
|
* @group translation
|
|
173
250
|
* @shortname xyz
|
|
174
251
|
* @drawable false
|
|
252
|
+
* @example
|
|
253
|
+
* ```typescript
|
|
254
|
+
* const move = bitbybit.transforms.translationXYZ({ translation: [10, 5, 0] });
|
|
255
|
+
* ```
|
|
175
256
|
*/
|
|
176
257
|
translationXYZ(inputs) {
|
|
177
258
|
return [this.translation(inputs.translation[0], inputs.translation[1], inputs.translation[2])];
|
|
178
259
|
}
|
|
179
260
|
/**
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
261
|
+
* Builds one move per vector, for transforming many points each by its own vector.
|
|
262
|
+
*
|
|
263
|
+
* Example: [[1,0,0], [0,2,0]] -> two transformations: one along X, one along Y
|
|
264
|
+
* @param inputs - The vectors to move by
|
|
265
|
+
* @returns One transformation per vector, in the same order
|
|
184
266
|
* @group translations
|
|
185
267
|
* @shortname xyz
|
|
186
268
|
* @drawable false
|
|
187
|
-
|
|
269
|
+
* @example
|
|
270
|
+
* ```typescript
|
|
271
|
+
* const moves = bitbybit.transforms.translationsXYZ({ translations: [[1, 0, 0], [0, 2, 0]] });
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
188
274
|
translationsXYZ(inputs) {
|
|
189
275
|
return inputs.translations.map(translation => [this.translation(translation[0], translation[1], translation[2])]);
|
|
190
276
|
}
|
|
191
277
|
/**
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
278
|
+
* Gives the matrix that changes nothing, as a starting point or a placeholder.
|
|
279
|
+
*
|
|
280
|
+
* Example: [1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1]
|
|
281
|
+
* @returns The identity matrix
|
|
195
282
|
* @group identity
|
|
196
283
|
* @shortname identity
|
|
197
284
|
* @drawable false
|