@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
|
@@ -3,8 +3,10 @@ import * as Inputs from "../inputs";
|
|
|
3
3
|
import { Point } from "./point";
|
|
4
4
|
import { Vector } from "./vector";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Straight lines between two points, held as plain objects of the form `{ start, end }`, and the
|
|
7
|
+
* segment form `[start, end]` of the same thing. The methods here build lines, measure and
|
|
8
|
+
* transform them, convert between the two forms, place points along them and find where two lines
|
|
9
|
+
* cross. Lengths are in model units.
|
|
8
10
|
*/
|
|
9
11
|
export declare class Line {
|
|
10
12
|
private readonly vector;
|
|
@@ -12,165 +14,233 @@ export declare class Line {
|
|
|
12
14
|
private readonly geometryHelper;
|
|
13
15
|
constructor(vector: Vector, point: Point, geometryHelper: GeometryHelper);
|
|
14
16
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @
|
|
17
|
+
* Reads the start point of a line.
|
|
18
|
+
*
|
|
19
|
+
* Example: { start: [0,0,0], end: [10,5,0] } -> [0,0,0]
|
|
20
|
+
* @param inputs - The line
|
|
21
|
+
* @returns The start point
|
|
19
22
|
* @group get
|
|
20
23
|
* @shortname line start point
|
|
21
24
|
* @drawable true
|
|
22
25
|
*/
|
|
23
26
|
getStartPoint(inputs: Inputs.Line.LineDto): Inputs.Base.Point3;
|
|
24
27
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @
|
|
28
|
+
* Reads the end point of a line.
|
|
29
|
+
*
|
|
30
|
+
* Example: { start: [0,0,0], end: [10,5,0] } -> [10,5,0]
|
|
31
|
+
* @param inputs - The line
|
|
32
|
+
* @returns The end point
|
|
29
33
|
* @group get
|
|
30
34
|
* @shortname line end point
|
|
31
35
|
* @drawable true
|
|
32
36
|
*/
|
|
33
37
|
getEndPoint(inputs: Inputs.Line.LineDto): Inputs.Base.Point3;
|
|
34
38
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* @
|
|
39
|
+
* Measures the straight distance from the start of a line to its end.
|
|
40
|
+
*
|
|
41
|
+
* Example: { start: [0,0,0], end: [3,4,0] } -> 5
|
|
42
|
+
* @param inputs - The line
|
|
43
|
+
* @returns The length in model units
|
|
39
44
|
* @group get
|
|
40
45
|
* @shortname line length
|
|
41
46
|
* @drawable false
|
|
42
47
|
*/
|
|
43
48
|
length(inputs: Inputs.Line.LineDto): number;
|
|
44
49
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* @
|
|
50
|
+
* Swaps the start and end of a line, so it runs the other way.
|
|
51
|
+
*
|
|
52
|
+
* Example: { start: [0,0,0], end: [10,5,0] } -> { start: [10,5,0], end: [0,0,0] }
|
|
53
|
+
* @param inputs - The line
|
|
54
|
+
* @returns A new line running the other way
|
|
49
55
|
* @group operations
|
|
50
56
|
* @shortname reversed line
|
|
51
57
|
* @drawable true
|
|
52
58
|
*/
|
|
53
59
|
reverse(inputs: Inputs.Line.LineDto): Inputs.Base.Line3;
|
|
54
60
|
/**
|
|
55
|
-
* Applies transformation matrix
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
61
|
+
* Applies a transformation matrix, or a list of them in order, to both ends of a line.
|
|
62
|
+
*
|
|
63
|
+
* Example: { start: [0,0,0], end: [10,0,0] } moved by [5,5,0] -> { start: [5,5,0], end:
|
|
64
|
+
* [15,5,0] }
|
|
65
|
+
* @param inputs - The line and the transformation
|
|
66
|
+
* @returns A new line with the transformed ends
|
|
59
67
|
* @group transforms
|
|
60
68
|
* @shortname transform line
|
|
61
69
|
* @drawable true
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const moved = bitbybit.line.transformLine({
|
|
73
|
+
* line: { start: [0, 0, 0], end: [10, 0, 0] },
|
|
74
|
+
* transformation: bitbybit.transforms.translationXYZ({ translation: [5, 5, 0] }),
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
62
77
|
*/
|
|
63
78
|
transformLine(inputs: Inputs.Line.TransformLineDto): Inputs.Base.Line3;
|
|
64
79
|
/**
|
|
65
|
-
* Applies
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
80
|
+
* Applies a different transformation to each line: the first transformation to the first line,
|
|
81
|
+
* and so on.
|
|
82
|
+
*
|
|
83
|
+
* Example: three lines with three translations -> each line moved by its own translation
|
|
84
|
+
* @param inputs - The lines and one transformation per line
|
|
85
|
+
* @returns The transformed lines, in the same order
|
|
69
86
|
* @group transforms
|
|
70
87
|
* @shortname transform lines
|
|
71
88
|
* @drawable true
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const placed = bitbybit.line.transformsForLines({
|
|
92
|
+
* lines: [{ start: [0, 0, 0], end: [1, 0, 0] }, { start: [0, 0, 0], end: [0, 1, 0] }],
|
|
93
|
+
* transformation: bitbybit.transforms.translationsXYZ({ translations: [[0, 1, 0], [0, 2, 0]] }),
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
72
96
|
*/
|
|
73
97
|
transformsForLines(inputs: Inputs.Line.TransformsLinesDto): Inputs.Base.Line3[];
|
|
74
98
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* @
|
|
99
|
+
* Builds a line object from a start and an end point.
|
|
100
|
+
*
|
|
101
|
+
* Example: start [0,0,0], end [10,5,0] -> { start: [0,0,0], end: [10,5,0] }
|
|
102
|
+
* @param inputs - The start and end points
|
|
103
|
+
* @returns The line object
|
|
79
104
|
* @group create
|
|
80
105
|
* @shortname line
|
|
81
106
|
* @drawable true
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const line = bitbybit.line.create({ start: [0, 0, 0], end: [10, 5, 0] });
|
|
110
|
+
* ```
|
|
82
111
|
*/
|
|
83
112
|
create(inputs: Inputs.Line.LinePointsDto): Inputs.Base.Line3;
|
|
84
113
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* @
|
|
114
|
+
* Builds a segment, the pair-of-points form of a line, from a start and an end point.
|
|
115
|
+
*
|
|
116
|
+
* Example: start [0,0,0], end [10,5,0] -> [[0,0,0], [10,5,0]]
|
|
117
|
+
* @param inputs - The start and end points
|
|
118
|
+
* @returns The segment as `[start, end]`
|
|
89
119
|
* @group create
|
|
90
120
|
* @shortname segment
|
|
91
121
|
* @drawable true
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const segment = bitbybit.line.createSegment({ start: [0, 0, 0], end: [10, 5, 0] });
|
|
125
|
+
* ```
|
|
92
126
|
*/
|
|
93
127
|
createSegment(inputs: Inputs.Line.LinePointsDto): Inputs.Base.Segment3;
|
|
94
128
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
129
|
+
* Finds the point a fraction of the way along a line: 0 gives the start, 1 the end, 0.5 the
|
|
130
|
+
* middle.
|
|
131
|
+
*
|
|
132
|
+
* A fraction outside 0 to 1 continues past the ends.
|
|
133
|
+
* Example: { start: [0,0,0], end: [10,0,0] } at 0.5 -> [5,0,0]
|
|
134
|
+
* @param inputs - The line and the fraction along it
|
|
135
|
+
* @returns The point on the line
|
|
99
136
|
* @group get
|
|
100
137
|
* @shortname point on line
|
|
101
138
|
* @drawable true
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* const middle = bitbybit.line.getPointOnLine({ line: { start: [0, 0, 0], end: [10, 0, 0] }, param: 0.5 });
|
|
142
|
+
* ```
|
|
102
143
|
*/
|
|
103
144
|
getPointOnLine(inputs: Inputs.Line.PointOnLineDto): Inputs.Base.Point3;
|
|
104
145
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* @
|
|
146
|
+
* Joins each point to the next with a line, so a list of points becomes a chain of lines.
|
|
147
|
+
*
|
|
148
|
+
* Example: [[0,0,0], [5,0,0], [5,5,0]] -> two lines, [0,0,0] to [5,0,0] and [5,0,0] to [5,5,0]
|
|
149
|
+
* @param inputs - The points, in order
|
|
150
|
+
* @returns One line per pair of neighboring points
|
|
109
151
|
* @group create
|
|
110
152
|
* @shortname lines between points
|
|
111
153
|
* @drawable true
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* const chain = bitbybit.line.linesBetweenPoints({ points: [[0, 0, 0], [5, 0, 0], [5, 5, 0]] });
|
|
157
|
+
* ```
|
|
112
158
|
*/
|
|
113
159
|
linesBetweenPoints(inputs: Inputs.Line.PointsLinesDto): Inputs.Base.Line3[];
|
|
114
160
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* @
|
|
161
|
+
* Pairs each start point with the end point at the same position and joins them with a line.
|
|
162
|
+
*
|
|
163
|
+
* A pair whose two points coincide makes no line and is left out.
|
|
164
|
+
* Example: starts [[0,0,0], [5,0,0]] and ends [[0,5,0], [5,5,0]] -> two lines
|
|
165
|
+
* @param inputs - The start points and the end points, in matching order
|
|
166
|
+
* @returns One line per pair, skipping pairs of length 0
|
|
120
167
|
* @group create
|
|
121
168
|
* @shortname start and end points to lines
|
|
122
169
|
* @drawable true
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* const rungs = bitbybit.line.linesBetweenStartAndEndPoints({
|
|
173
|
+
* startPoints: [[0, 0, 0], [5, 0, 0]],
|
|
174
|
+
* endPoints: [[0, 5, 0], [5, 5, 0]],
|
|
175
|
+
* });
|
|
176
|
+
* ```
|
|
123
177
|
*/
|
|
124
178
|
linesBetweenStartAndEndPoints(inputs: Inputs.Line.LineStartEndPointsDto): Inputs.Base.Line3[];
|
|
125
179
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* @
|
|
180
|
+
* Turns a line object into its segment form, the pair `[start, end]`.
|
|
181
|
+
*
|
|
182
|
+
* Example: { start: [0,0,0], end: [10,5,0] } -> [[0,0,0], [10,5,0]]
|
|
183
|
+
* @param inputs - The line
|
|
184
|
+
* @returns The segment
|
|
130
185
|
* @group convert
|
|
131
186
|
* @shortname line to segment
|
|
132
187
|
* @drawable false
|
|
133
188
|
*/
|
|
134
189
|
lineToSegment(inputs: Inputs.Line.LineDto): Inputs.Base.Segment3;
|
|
135
190
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* @
|
|
191
|
+
* Turns each line object into its segment form, the pair `[start, end]`.
|
|
192
|
+
*
|
|
193
|
+
* Example: three lines -> three segments, in the same order
|
|
194
|
+
* @param inputs - The lines
|
|
195
|
+
* @returns One segment per line
|
|
140
196
|
* @group convert
|
|
141
197
|
* @shortname lines to segments
|
|
142
198
|
* @drawable false
|
|
143
199
|
*/
|
|
144
200
|
linesToSegments(inputs: Inputs.Line.LinesDto): Inputs.Base.Segment3[];
|
|
145
201
|
/**
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* @
|
|
202
|
+
* Turns a segment, the pair `[start, end]`, into a line object.
|
|
203
|
+
*
|
|
204
|
+
* Example: [[0,0,0], [10,5,0]] -> { start: [0,0,0], end: [10,5,0] }
|
|
205
|
+
* @param inputs - The segment
|
|
206
|
+
* @returns The line
|
|
150
207
|
* @group convert
|
|
151
208
|
* @shortname segment to line
|
|
152
209
|
* @drawable true
|
|
153
210
|
*/
|
|
154
211
|
segmentToLine(inputs: Inputs.Line.SegmentDto): Inputs.Base.Line3;
|
|
155
212
|
/**
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
* @
|
|
213
|
+
* Turns each segment, a pair `[start, end]`, into a line object.
|
|
214
|
+
*
|
|
215
|
+
* Example: three segments -> three lines, in the same order
|
|
216
|
+
* @param inputs - The segments
|
|
217
|
+
* @returns One line per segment
|
|
160
218
|
* @group convert
|
|
161
219
|
* @shortname segments to lines
|
|
162
220
|
* @drawable true
|
|
163
221
|
*/
|
|
164
222
|
segmentsToLines(inputs: Inputs.Line.SegmentsDto): Inputs.Base.Line3[];
|
|
165
223
|
/**
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
224
|
+
* Finds the point where two lines cross.
|
|
225
|
+
*
|
|
226
|
+
* With `checkSegmentsOnly` on, the crossing must lie within both segments; off, the lines
|
|
227
|
+
* extend without end. Parallel lines, lines that pass each other without meeting, and segments
|
|
228
|
+
* that do not reach each other give undefined. The tolerance says how close counts as meeting.
|
|
229
|
+
* Example: [0,0,0] to [10,0,0] and [5,-5,0] to [5,5,0] -> [5,0,0]
|
|
230
|
+
* @param inputs - The two lines, whether to stay within the segments, and the tolerance
|
|
231
|
+
* @returns The crossing point, or undefined when there is none
|
|
171
232
|
* @group intersection
|
|
172
233
|
* @shortname line-line int
|
|
173
234
|
* @drawable true
|
|
235
|
+
* @example
|
|
236
|
+
* ```typescript
|
|
237
|
+
* const crossing = bitbybit.line.lineLineIntersection({
|
|
238
|
+
* line1: { start: [0, 0, 0], end: [10, 0, 0] },
|
|
239
|
+
* line2: { start: [5, -5, 0], end: [5, 5, 0] },
|
|
240
|
+
* checkSegmentsOnly: true,
|
|
241
|
+
* tolerance: 1e-6,
|
|
242
|
+
* });
|
|
243
|
+
* ```
|
|
174
244
|
*/
|
|
175
245
|
lineLineIntersection(inputs: Inputs.Line.LineLineIntersectionDto): Inputs.Base.Point3 | undefined;
|
|
176
246
|
}
|
package/lib/api/services/line.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Straight lines between two points, held as plain objects of the form `{ start, end }`, and the
|
|
3
|
+
* segment form `[start, end]` of the same thing. The methods here build lines, measure and
|
|
4
|
+
* transform them, convert between the two forms, place points along them and find where two lines
|
|
5
|
+
* cross. Lengths are in model units.
|
|
4
6
|
*/
|
|
5
7
|
export class Line {
|
|
6
8
|
constructor(vector, point, geometryHelper) {
|
|
@@ -9,10 +11,11 @@ export class Line {
|
|
|
9
11
|
this.geometryHelper = geometryHelper;
|
|
10
12
|
}
|
|
11
13
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* @
|
|
14
|
+
* Reads the start point of a line.
|
|
15
|
+
*
|
|
16
|
+
* Example: { start: [0,0,0], end: [10,5,0] } -> [0,0,0]
|
|
17
|
+
* @param inputs - The line
|
|
18
|
+
* @returns The start point
|
|
16
19
|
* @group get
|
|
17
20
|
* @shortname line start point
|
|
18
21
|
* @drawable true
|
|
@@ -21,10 +24,11 @@ export class Line {
|
|
|
21
24
|
return inputs.line.start;
|
|
22
25
|
}
|
|
23
26
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* @
|
|
27
|
+
* Reads the end point of a line.
|
|
28
|
+
*
|
|
29
|
+
* Example: { start: [0,0,0], end: [10,5,0] } -> [10,5,0]
|
|
30
|
+
* @param inputs - The line
|
|
31
|
+
* @returns The end point
|
|
28
32
|
* @group get
|
|
29
33
|
* @shortname line end point
|
|
30
34
|
* @drawable true
|
|
@@ -33,10 +37,11 @@ export class Line {
|
|
|
33
37
|
return inputs.line.end;
|
|
34
38
|
}
|
|
35
39
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* @
|
|
40
|
+
* Measures the straight distance from the start of a line to its end.
|
|
41
|
+
*
|
|
42
|
+
* Example: { start: [0,0,0], end: [3,4,0] } -> 5
|
|
43
|
+
* @param inputs - The line
|
|
44
|
+
* @returns The length in model units
|
|
40
45
|
* @group get
|
|
41
46
|
* @shortname line length
|
|
42
47
|
* @drawable false
|
|
@@ -45,10 +50,11 @@ export class Line {
|
|
|
45
50
|
return this.point.distance({ startPoint: inputs.line.start, endPoint: inputs.line.end });
|
|
46
51
|
}
|
|
47
52
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* @
|
|
53
|
+
* Swaps the start and end of a line, so it runs the other way.
|
|
54
|
+
*
|
|
55
|
+
* Example: { start: [0,0,0], end: [10,5,0] } -> { start: [10,5,0], end: [0,0,0] }
|
|
56
|
+
* @param inputs - The line
|
|
57
|
+
* @returns A new line running the other way
|
|
52
58
|
* @group operations
|
|
53
59
|
* @shortname reversed line
|
|
54
60
|
* @drawable true
|
|
@@ -57,13 +63,22 @@ export class Line {
|
|
|
57
63
|
return { start: inputs.line.end, end: inputs.line.start };
|
|
58
64
|
}
|
|
59
65
|
/**
|
|
60
|
-
* Applies transformation matrix
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
66
|
+
* Applies a transformation matrix, or a list of them in order, to both ends of a line.
|
|
67
|
+
*
|
|
68
|
+
* Example: { start: [0,0,0], end: [10,0,0] } moved by [5,5,0] -> { start: [5,5,0], end:
|
|
69
|
+
* [15,5,0] }
|
|
70
|
+
* @param inputs - The line and the transformation
|
|
71
|
+
* @returns A new line with the transformed ends
|
|
64
72
|
* @group transforms
|
|
65
73
|
* @shortname transform line
|
|
66
74
|
* @drawable true
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const moved = bitbybit.line.transformLine({
|
|
78
|
+
* line: { start: [0, 0, 0], end: [10, 0, 0] },
|
|
79
|
+
* transformation: bitbybit.transforms.translationXYZ({ translation: [5, 5, 0] }),
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
67
82
|
*/
|
|
68
83
|
transformLine(inputs) {
|
|
69
84
|
const transformation = inputs.transformation;
|
|
@@ -75,13 +90,22 @@ export class Line {
|
|
|
75
90
|
};
|
|
76
91
|
}
|
|
77
92
|
/**
|
|
78
|
-
* Applies
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
93
|
+
* Applies a different transformation to each line: the first transformation to the first line,
|
|
94
|
+
* and so on.
|
|
95
|
+
*
|
|
96
|
+
* Example: three lines with three translations -> each line moved by its own translation
|
|
97
|
+
* @param inputs - The lines and one transformation per line
|
|
98
|
+
* @returns The transformed lines, in the same order
|
|
82
99
|
* @group transforms
|
|
83
100
|
* @shortname transform lines
|
|
84
101
|
* @drawable true
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const placed = bitbybit.line.transformsForLines({
|
|
105
|
+
* lines: [{ start: [0, 0, 0], end: [1, 0, 0] }, { start: [0, 0, 0], end: [0, 1, 0] }],
|
|
106
|
+
* transformation: bitbybit.transforms.translationsXYZ({ translations: [[0, 1, 0], [0, 2, 0]] }),
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
85
109
|
*/
|
|
86
110
|
transformsForLines(inputs) {
|
|
87
111
|
return inputs.lines.map((line, index) => {
|
|
@@ -95,13 +119,18 @@ export class Line {
|
|
|
95
119
|
});
|
|
96
120
|
}
|
|
97
121
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* @
|
|
122
|
+
* Builds a line object from a start and an end point.
|
|
123
|
+
*
|
|
124
|
+
* Example: start [0,0,0], end [10,5,0] -> { start: [0,0,0], end: [10,5,0] }
|
|
125
|
+
* @param inputs - The start and end points
|
|
126
|
+
* @returns The line object
|
|
102
127
|
* @group create
|
|
103
128
|
* @shortname line
|
|
104
129
|
* @drawable true
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const line = bitbybit.line.create({ start: [0, 0, 0], end: [10, 5, 0] });
|
|
133
|
+
* ```
|
|
105
134
|
*/
|
|
106
135
|
create(inputs) {
|
|
107
136
|
return {
|
|
@@ -110,13 +139,18 @@ export class Line {
|
|
|
110
139
|
};
|
|
111
140
|
}
|
|
112
141
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* @
|
|
142
|
+
* Builds a segment, the pair-of-points form of a line, from a start and an end point.
|
|
143
|
+
*
|
|
144
|
+
* Example: start [0,0,0], end [10,5,0] -> [[0,0,0], [10,5,0]]
|
|
145
|
+
* @param inputs - The start and end points
|
|
146
|
+
* @returns The segment as `[start, end]`
|
|
117
147
|
* @group create
|
|
118
148
|
* @shortname segment
|
|
119
149
|
* @drawable true
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* const segment = bitbybit.line.createSegment({ start: [0, 0, 0], end: [10, 5, 0] });
|
|
153
|
+
* ```
|
|
120
154
|
*/
|
|
121
155
|
createSegment(inputs) {
|
|
122
156
|
return [
|
|
@@ -125,13 +159,20 @@ export class Line {
|
|
|
125
159
|
];
|
|
126
160
|
}
|
|
127
161
|
/**
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
162
|
+
* Finds the point a fraction of the way along a line: 0 gives the start, 1 the end, 0.5 the
|
|
163
|
+
* middle.
|
|
164
|
+
*
|
|
165
|
+
* A fraction outside 0 to 1 continues past the ends.
|
|
166
|
+
* Example: { start: [0,0,0], end: [10,0,0] } at 0.5 -> [5,0,0]
|
|
167
|
+
* @param inputs - The line and the fraction along it
|
|
168
|
+
* @returns The point on the line
|
|
132
169
|
* @group get
|
|
133
170
|
* @shortname point on line
|
|
134
171
|
* @drawable true
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* const middle = bitbybit.line.getPointOnLine({ line: { start: [0, 0, 0], end: [10, 0, 0] }, param: 0.5 });
|
|
175
|
+
* ```
|
|
135
176
|
*/
|
|
136
177
|
getPointOnLine(inputs) {
|
|
137
178
|
var _a;
|
|
@@ -143,13 +184,18 @@ export class Line {
|
|
|
143
184
|
return point;
|
|
144
185
|
}
|
|
145
186
|
/**
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* @
|
|
187
|
+
* Joins each point to the next with a line, so a list of points becomes a chain of lines.
|
|
188
|
+
*
|
|
189
|
+
* Example: [[0,0,0], [5,0,0], [5,5,0]] -> two lines, [0,0,0] to [5,0,0] and [5,0,0] to [5,5,0]
|
|
190
|
+
* @param inputs - The points, in order
|
|
191
|
+
* @returns One line per pair of neighboring points
|
|
150
192
|
* @group create
|
|
151
193
|
* @shortname lines between points
|
|
152
194
|
* @drawable true
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* const chain = bitbybit.line.linesBetweenPoints({ points: [[0, 0, 0], [5, 0, 0], [5, 5, 0]] });
|
|
198
|
+
* ```
|
|
153
199
|
*/
|
|
154
200
|
linesBetweenPoints(inputs) {
|
|
155
201
|
const lines = [];
|
|
@@ -161,14 +207,22 @@ export class Line {
|
|
|
161
207
|
return lines;
|
|
162
208
|
}
|
|
163
209
|
/**
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* @
|
|
210
|
+
* Pairs each start point with the end point at the same position and joins them with a line.
|
|
211
|
+
*
|
|
212
|
+
* A pair whose two points coincide makes no line and is left out.
|
|
213
|
+
* Example: starts [[0,0,0], [5,0,0]] and ends [[0,5,0], [5,5,0]] -> two lines
|
|
214
|
+
* @param inputs - The start points and the end points, in matching order
|
|
215
|
+
* @returns One line per pair, skipping pairs of length 0
|
|
169
216
|
* @group create
|
|
170
217
|
* @shortname start and end points to lines
|
|
171
218
|
* @drawable true
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* const rungs = bitbybit.line.linesBetweenStartAndEndPoints({
|
|
222
|
+
* startPoints: [[0, 0, 0], [5, 0, 0]],
|
|
223
|
+
* endPoints: [[0, 5, 0], [5, 5, 0]],
|
|
224
|
+
* });
|
|
225
|
+
* ```
|
|
172
226
|
*/
|
|
173
227
|
linesBetweenStartAndEndPoints(inputs) {
|
|
174
228
|
return inputs.startPoints
|
|
@@ -176,10 +230,11 @@ export class Line {
|
|
|
176
230
|
.filter(line => this.point.distance({ startPoint: line.start, endPoint: line.end }) !== 0);
|
|
177
231
|
}
|
|
178
232
|
/**
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
* @
|
|
233
|
+
* Turns a line object into its segment form, the pair `[start, end]`.
|
|
234
|
+
*
|
|
235
|
+
* Example: { start: [0,0,0], end: [10,5,0] } -> [[0,0,0], [10,5,0]]
|
|
236
|
+
* @param inputs - The line
|
|
237
|
+
* @returns The segment
|
|
183
238
|
* @group convert
|
|
184
239
|
* @shortname line to segment
|
|
185
240
|
* @drawable false
|
|
@@ -188,10 +243,11 @@ export class Line {
|
|
|
188
243
|
return [inputs.line.start, inputs.line.end];
|
|
189
244
|
}
|
|
190
245
|
/**
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
* @
|
|
246
|
+
* Turns each line object into its segment form, the pair `[start, end]`.
|
|
247
|
+
*
|
|
248
|
+
* Example: three lines -> three segments, in the same order
|
|
249
|
+
* @param inputs - The lines
|
|
250
|
+
* @returns One segment per line
|
|
195
251
|
* @group convert
|
|
196
252
|
* @shortname lines to segments
|
|
197
253
|
* @drawable false
|
|
@@ -200,10 +256,11 @@ export class Line {
|
|
|
200
256
|
return inputs.lines.map(line => [line.start, line.end]);
|
|
201
257
|
}
|
|
202
258
|
/**
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
* @
|
|
259
|
+
* Turns a segment, the pair `[start, end]`, into a line object.
|
|
260
|
+
*
|
|
261
|
+
* Example: [[0,0,0], [10,5,0]] -> { start: [0,0,0], end: [10,5,0] }
|
|
262
|
+
* @param inputs - The segment
|
|
263
|
+
* @returns The line
|
|
207
264
|
* @group convert
|
|
208
265
|
* @shortname segment to line
|
|
209
266
|
* @drawable true
|
|
@@ -212,10 +269,11 @@ export class Line {
|
|
|
212
269
|
return { start: inputs.segment[0], end: inputs.segment[1] };
|
|
213
270
|
}
|
|
214
271
|
/**
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
* @
|
|
272
|
+
* Turns each segment, a pair `[start, end]`, into a line object.
|
|
273
|
+
*
|
|
274
|
+
* Example: three segments -> three lines, in the same order
|
|
275
|
+
* @param inputs - The segments
|
|
276
|
+
* @returns One line per segment
|
|
219
277
|
* @group convert
|
|
220
278
|
* @shortname segments to lines
|
|
221
279
|
* @drawable true
|
|
@@ -224,14 +282,26 @@ export class Line {
|
|
|
224
282
|
return inputs.segments.map(segment => ({ start: segment[0], end: segment[1] }));
|
|
225
283
|
}
|
|
226
284
|
/**
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
285
|
+
* Finds the point where two lines cross.
|
|
286
|
+
*
|
|
287
|
+
* With `checkSegmentsOnly` on, the crossing must lie within both segments; off, the lines
|
|
288
|
+
* extend without end. Parallel lines, lines that pass each other without meeting, and segments
|
|
289
|
+
* that do not reach each other give undefined. The tolerance says how close counts as meeting.
|
|
290
|
+
* Example: [0,0,0] to [10,0,0] and [5,-5,0] to [5,5,0] -> [5,0,0]
|
|
291
|
+
* @param inputs - The two lines, whether to stay within the segments, and the tolerance
|
|
292
|
+
* @returns The crossing point, or undefined when there is none
|
|
232
293
|
* @group intersection
|
|
233
294
|
* @shortname line-line int
|
|
234
295
|
* @drawable true
|
|
296
|
+
* @example
|
|
297
|
+
* ```typescript
|
|
298
|
+
* const crossing = bitbybit.line.lineLineIntersection({
|
|
299
|
+
* line1: { start: [0, 0, 0], end: [10, 0, 0] },
|
|
300
|
+
* line2: { start: [5, -5, 0], end: [5, 5, 0] },
|
|
301
|
+
* checkSegmentsOnly: true,
|
|
302
|
+
* tolerance: 1e-6,
|
|
303
|
+
* });
|
|
304
|
+
* ```
|
|
235
305
|
*/
|
|
236
306
|
lineLineIntersection(inputs) {
|
|
237
307
|
const epsilon = inputs.tolerance || 1e-6;
|