@bitbybit-dev/base 0.20.13 → 0.20.14
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/lists-inputs.d.ts +39 -0
- package/lib/api/inputs/lists-inputs.js +43 -0
- package/lib/api/inputs/math-inputs.d.ts +154 -0
- package/lib/api/inputs/math-inputs.js +217 -0
- package/lib/api/inputs/text-inputs.d.ts +139 -0
- package/lib/api/inputs/text-inputs.js +215 -0
- package/lib/api/inputs/vector-inputs.d.ts +8 -0
- package/lib/api/inputs/vector-inputs.js +8 -0
- package/lib/api/services/color.d.ts +27 -12
- package/lib/api/services/color.js +27 -12
- package/lib/api/services/dates.d.ts +62 -30
- package/lib/api/services/dates.js +62 -30
- package/lib/api/services/geometry-helper.d.ts +50 -0
- package/lib/api/services/geometry-helper.js +50 -2
- package/lib/api/services/helpers/dxf/dxf.d.ts +19 -9
- package/lib/api/services/helpers/dxf/dxf.js +19 -9
- package/lib/api/services/line.d.ts +34 -16
- package/lib/api/services/line.js +34 -16
- package/lib/api/services/lists.d.ts +175 -32
- package/lib/api/services/lists.js +275 -32
- package/lib/api/services/logic.d.ts +24 -13
- package/lib/api/services/logic.js +24 -13
- package/lib/api/services/math.d.ts +180 -35
- package/lib/api/services/math.js +215 -35
- package/lib/api/services/mesh.d.ts +17 -6
- package/lib/api/services/mesh.js +17 -6
- package/lib/api/services/point.d.ts +63 -32
- package/lib/api/services/point.js +63 -32
- package/lib/api/services/polyline.d.ts +27 -11
- package/lib/api/services/polyline.js +27 -11
- package/lib/api/services/text.d.ts +286 -7
- package/lib/api/services/text.js +350 -7
- package/lib/api/services/transforms.d.ts +30 -16
- package/lib/api/services/transforms.js +30 -16
- package/lib/api/services/vector.d.ts +85 -38
- package/lib/api/services/vector.js +87 -38
- package/package.json +1 -1
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
export class GeometryHelper {
|
|
2
2
|
constructor() {
|
|
3
|
+
/**
|
|
4
|
+
* Calculates the nesting depth of an array recursively.
|
|
5
|
+
* Example: [1,2,3] → 1, [[1,2],[3,4]] → 2, [[[1]]] → 3
|
|
6
|
+
*/
|
|
3
7
|
this.getArrayDepth = (value) => {
|
|
4
8
|
return Array.isArray(value) ?
|
|
5
9
|
1 + Math.max(...value.map(this.getArrayDepth)) :
|
|
6
10
|
0;
|
|
7
11
|
};
|
|
8
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Applies one or more 4×4 transformation matrices to a list of points sequentially.
|
|
15
|
+
* Each transformation is applied in order (composition of transformations).
|
|
16
|
+
* Example: points=[[0,0,0], [1,0,0]] with translation [5,0,0] → [[5,0,0], [6,0,0]]
|
|
17
|
+
*/
|
|
9
18
|
transformControlPoints(transformation, transformedControlPoints) {
|
|
10
19
|
const transformationArrays = this.getFlatTransformations(transformation);
|
|
11
20
|
transformationArrays.forEach(transform => {
|
|
@@ -13,6 +22,11 @@ export class GeometryHelper {
|
|
|
13
22
|
});
|
|
14
23
|
return transformedControlPoints;
|
|
15
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Flattens nested transformation arrays into a single-level array of transformation matrices.
|
|
27
|
+
* Handles both 2D arrays (single transform list) and 3D arrays (nested transform lists).
|
|
28
|
+
* Example: [[[matrix1, matrix2]], [[matrix3]]] → [matrix1, matrix2, matrix3]
|
|
29
|
+
*/
|
|
16
30
|
getFlatTransformations(transformation) {
|
|
17
31
|
let transformationArrays = [];
|
|
18
32
|
if (this.getArrayDepth(transformation) === 3) {
|
|
@@ -25,9 +39,17 @@ export class GeometryHelper {
|
|
|
25
39
|
}
|
|
26
40
|
return transformationArrays;
|
|
27
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Applies a single 4×4 transformation matrix (as flat 16-element array) to multiple points.
|
|
44
|
+
* Example: points=[[0,0,0], [1,0,0]] with translation matrix → transformed points
|
|
45
|
+
*/
|
|
28
46
|
transformPointsByMatrixArray(points, transform) {
|
|
29
47
|
return this.transformPointsCoordinates(points, transform);
|
|
30
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Transforms multiple points using a transformation matrix (maps each point through the matrix).
|
|
51
|
+
* Example: points=[[1,0,0], [0,1,0]] with 90° rotation → [[0,1,0], [-1,0,0]]
|
|
52
|
+
*/
|
|
31
53
|
transformPointsCoordinates(points, transform) {
|
|
32
54
|
const transformedPoints = [];
|
|
33
55
|
for (const pt of points) {
|
|
@@ -36,7 +58,11 @@ export class GeometryHelper {
|
|
|
36
58
|
}
|
|
37
59
|
return transformedPoints;
|
|
38
60
|
}
|
|
39
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Removes all duplicate vectors from a list (works with arbitrary-length numeric vectors).
|
|
63
|
+
* Compares vectors using tolerance for floating-point equality.
|
|
64
|
+
* Example: [[1,2], [3,4], [1,2], [5,6]] with tolerance=1e-7 → [[1,2], [3,4], [5,6]]
|
|
65
|
+
*/
|
|
40
66
|
removeAllDuplicateVectors(vectors, tolerance = 1e-7) {
|
|
41
67
|
const cleanVectors = [];
|
|
42
68
|
vectors.forEach(vector => {
|
|
@@ -47,7 +73,11 @@ export class GeometryHelper {
|
|
|
47
73
|
});
|
|
48
74
|
return cleanVectors;
|
|
49
75
|
}
|
|
50
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Removes consecutive duplicate vectors from a list (keeps only first occurrence in each sequence).
|
|
78
|
+
* Optionally checks and removes duplicate if first and last vectors match.
|
|
79
|
+
* Example: [[1,2], [1,2], [3,4], [3,4], [5,6]] → [[1,2], [3,4], [5,6]]
|
|
80
|
+
*/
|
|
51
81
|
removeConsecutiveVectorDuplicates(vectors, checkFirstAndLast = true, tolerance = 1e-7) {
|
|
52
82
|
const vectorsRemaining = [];
|
|
53
83
|
if (vectors.length > 1) {
|
|
@@ -74,6 +104,11 @@ export class GeometryHelper {
|
|
|
74
104
|
}
|
|
75
105
|
return vectorsRemaining;
|
|
76
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Compares two vectors for approximate equality using tolerance (element-wise comparison).
|
|
109
|
+
* Returns false if vectors have different lengths.
|
|
110
|
+
* Example: [1.0000001, 2.0], [1.0, 2.0] with tolerance=1e-6 → true
|
|
111
|
+
*/
|
|
77
112
|
vectorsTheSame(vec1, vec2, tolerance) {
|
|
78
113
|
let result = false;
|
|
79
114
|
if (vec1.length !== vec2.length) {
|
|
@@ -90,10 +125,19 @@ export class GeometryHelper {
|
|
|
90
125
|
}
|
|
91
126
|
return result;
|
|
92
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Checks if two numbers are approximately equal within a tolerance.
|
|
130
|
+
* Example: 1.0000001, 1.0 with tolerance=1e-6 → true, 1.001, 1.0 with tolerance=1e-6 → false
|
|
131
|
+
*/
|
|
93
132
|
approxEq(num1, num2, tolerance) {
|
|
94
133
|
const res = Math.abs(num1 - num2) < tolerance;
|
|
95
134
|
return res;
|
|
96
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Removes consecutive duplicate points from a list (specialized for 3D/2D points).
|
|
138
|
+
* Optionally checks and removes duplicate if first and last points match (for closed loops).
|
|
139
|
+
* Example: [[0,0,0], [0,0,0], [1,0,0], [1,0,0]] → [[0,0,0], [1,0,0]]
|
|
140
|
+
*/
|
|
97
141
|
removeConsecutivePointDuplicates(points, checkFirstAndLast = true, tolerance = 1e-7) {
|
|
98
142
|
const pointsRemaining = [];
|
|
99
143
|
if (points.length > 1) {
|
|
@@ -120,6 +164,10 @@ export class GeometryHelper {
|
|
|
120
164
|
}
|
|
121
165
|
return pointsRemaining;
|
|
122
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Checks if two points are approximately equal using tolerance (supports 2D and 3D points).
|
|
169
|
+
* Example: [1.0000001, 2.0, 3.0], [1.0, 2.0, 3.0] with tolerance=1e-6 → true
|
|
170
|
+
*/
|
|
123
171
|
arePointsTheSame(pointA, pointB, tolerance) {
|
|
124
172
|
let result = false;
|
|
125
173
|
if (pointA.length === 2 && pointB.length === 2) {
|
|
@@ -2,7 +2,8 @@ import * as Inputs from "../../../inputs";
|
|
|
2
2
|
export declare class Dxf {
|
|
3
3
|
private dxfGenerator;
|
|
4
4
|
/**
|
|
5
|
-
* Creates a line segment for DXF
|
|
5
|
+
* Creates a line segment definition for DXF export (pass-through for validation).
|
|
6
|
+
* Example: start=[0,0], end=[10,5] → DXF line segment from origin to [10,5]
|
|
6
7
|
* @param inputs Line segment definition
|
|
7
8
|
* @returns Line segment DTO
|
|
8
9
|
* @group dxf
|
|
@@ -11,7 +12,8 @@ export declare class Dxf {
|
|
|
11
12
|
*/
|
|
12
13
|
lineSegment(inputs: Inputs.IO.DxfLineSegmentDto): Inputs.IO.DxfLineSegmentDto;
|
|
13
14
|
/**
|
|
14
|
-
* Creates an arc segment for DXF
|
|
15
|
+
* Creates an arc segment definition for DXF export (curved path between two points).
|
|
16
|
+
* Example: center=[5,5], radius=5, startAngle=0°, endAngle=90° → quarter circle arc
|
|
15
17
|
* @param inputs Arc segment definition
|
|
16
18
|
* @returns Arc segment DTO
|
|
17
19
|
* @group dxf
|
|
@@ -20,7 +22,8 @@ export declare class Dxf {
|
|
|
20
22
|
*/
|
|
21
23
|
arcSegment(inputs: Inputs.IO.DxfArcSegmentDto): Inputs.IO.DxfArcSegmentDto;
|
|
22
24
|
/**
|
|
23
|
-
* Creates a circle segment for DXF
|
|
25
|
+
* Creates a circle segment definition for DXF export (closed circular path).
|
|
26
|
+
* Example: center=[10,10], radius=5 → full circle with diameter 10 centered at [10,10]
|
|
24
27
|
* @param inputs Circle segment definition
|
|
25
28
|
* @returns Circle segment DTO
|
|
26
29
|
* @group dxf
|
|
@@ -29,7 +32,8 @@ export declare class Dxf {
|
|
|
29
32
|
*/
|
|
30
33
|
circleSegment(inputs: Inputs.IO.DxfCircleSegmentDto): Inputs.IO.DxfCircleSegmentDto;
|
|
31
34
|
/**
|
|
32
|
-
* Creates a polyline segment for DXF
|
|
35
|
+
* Creates a polyline segment definition for DXF export (connected line segments through points).
|
|
36
|
+
* Example: points=[[0,0], [5,0], [5,5], [0,5]] → rectangular polyline path
|
|
33
37
|
* @param inputs Polyline segment definition
|
|
34
38
|
* @returns Polyline segment DTO
|
|
35
39
|
* @group dxf
|
|
@@ -38,7 +42,8 @@ export declare class Dxf {
|
|
|
38
42
|
*/
|
|
39
43
|
polylineSegment(inputs: Inputs.IO.DxfPolylineSegmentDto): Inputs.IO.DxfPolylineSegmentDto;
|
|
40
44
|
/**
|
|
41
|
-
* Creates a spline segment for DXF
|
|
45
|
+
* Creates a spline segment definition for DXF export (smooth curve through control points).
|
|
46
|
+
* Example: controlPoints=[[0,0], [5,10], [10,0]] → smooth curved path through points
|
|
42
47
|
* @param inputs Spline segment definition
|
|
43
48
|
* @returns Spline segment DTO
|
|
44
49
|
* @group dxf
|
|
@@ -47,7 +52,9 @@ export declare class Dxf {
|
|
|
47
52
|
*/
|
|
48
53
|
splineSegment(inputs: Inputs.IO.DxfSplineSegmentDto): Inputs.IO.DxfSplineSegmentDto;
|
|
49
54
|
/**
|
|
50
|
-
* Creates a path from segments
|
|
55
|
+
* Creates a path from multiple segments (combines lines, arcs, circles, polylines, splines).
|
|
56
|
+
* Similar to OCCT wires - segments are connected to form a continuous or multi-part path.
|
|
57
|
+
* Example: segments=[lineSegment, arcSegment, polylineSegment] → combined path entity
|
|
51
58
|
* @param inputs Path definition with segments
|
|
52
59
|
* @returns Path DTO
|
|
53
60
|
* @group dxf
|
|
@@ -56,7 +63,9 @@ export declare class Dxf {
|
|
|
56
63
|
*/
|
|
57
64
|
path(inputs: Inputs.IO.DxfPathDto): Inputs.IO.DxfPathDto;
|
|
58
65
|
/**
|
|
59
|
-
* Creates a paths part with layer and color
|
|
66
|
+
* Creates a paths part with layer and color assignment for DXF organization.
|
|
67
|
+
* Groups multiple paths into a single layer with consistent styling.
|
|
68
|
+
* Example: paths=[path1, path2], layer="Outlines", color=red → grouped geometry
|
|
60
69
|
* @param inputs Paths part definition
|
|
61
70
|
* @returns Paths part DTO
|
|
62
71
|
* @group dxf
|
|
@@ -65,8 +74,9 @@ export declare class Dxf {
|
|
|
65
74
|
*/
|
|
66
75
|
pathsPart(inputs: Inputs.IO.DxfPathsPartDto): Inputs.IO.DxfPathsPartDto;
|
|
67
76
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
77
|
+
* Generates a complete DXF file from paths parts (exports 2D CAD drawing format).
|
|
78
|
+
* Supports lines, arcs, circles, polylines, and splines organized in layered paths.
|
|
79
|
+
* Example: model with 3 parts on different layers → valid DXF file string for CAD software
|
|
70
80
|
* @param inputs DXF model definition
|
|
71
81
|
* @returns DXF file content as string
|
|
72
82
|
* @group dxf
|
|
@@ -4,7 +4,8 @@ export class Dxf {
|
|
|
4
4
|
this.dxfGenerator = new DxfGenerator();
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
|
-
* Creates a line segment for DXF
|
|
7
|
+
* Creates a line segment definition for DXF export (pass-through for validation).
|
|
8
|
+
* Example: start=[0,0], end=[10,5] → DXF line segment from origin to [10,5]
|
|
8
9
|
* @param inputs Line segment definition
|
|
9
10
|
* @returns Line segment DTO
|
|
10
11
|
* @group dxf
|
|
@@ -15,7 +16,8 @@ export class Dxf {
|
|
|
15
16
|
return inputs;
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
|
-
* Creates an arc segment for DXF
|
|
19
|
+
* Creates an arc segment definition for DXF export (curved path between two points).
|
|
20
|
+
* Example: center=[5,5], radius=5, startAngle=0°, endAngle=90° → quarter circle arc
|
|
19
21
|
* @param inputs Arc segment definition
|
|
20
22
|
* @returns Arc segment DTO
|
|
21
23
|
* @group dxf
|
|
@@ -26,7 +28,8 @@ export class Dxf {
|
|
|
26
28
|
return inputs;
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
29
|
-
* Creates a circle segment for DXF
|
|
31
|
+
* Creates a circle segment definition for DXF export (closed circular path).
|
|
32
|
+
* Example: center=[10,10], radius=5 → full circle with diameter 10 centered at [10,10]
|
|
30
33
|
* @param inputs Circle segment definition
|
|
31
34
|
* @returns Circle segment DTO
|
|
32
35
|
* @group dxf
|
|
@@ -37,7 +40,8 @@ export class Dxf {
|
|
|
37
40
|
return inputs;
|
|
38
41
|
}
|
|
39
42
|
/**
|
|
40
|
-
* Creates a polyline segment for DXF
|
|
43
|
+
* Creates a polyline segment definition for DXF export (connected line segments through points).
|
|
44
|
+
* Example: points=[[0,0], [5,0], [5,5], [0,5]] → rectangular polyline path
|
|
41
45
|
* @param inputs Polyline segment definition
|
|
42
46
|
* @returns Polyline segment DTO
|
|
43
47
|
* @group dxf
|
|
@@ -48,7 +52,8 @@ export class Dxf {
|
|
|
48
52
|
return inputs;
|
|
49
53
|
}
|
|
50
54
|
/**
|
|
51
|
-
* Creates a spline segment for DXF
|
|
55
|
+
* Creates a spline segment definition for DXF export (smooth curve through control points).
|
|
56
|
+
* Example: controlPoints=[[0,0], [5,10], [10,0]] → smooth curved path through points
|
|
52
57
|
* @param inputs Spline segment definition
|
|
53
58
|
* @returns Spline segment DTO
|
|
54
59
|
* @group dxf
|
|
@@ -59,7 +64,9 @@ export class Dxf {
|
|
|
59
64
|
return inputs;
|
|
60
65
|
}
|
|
61
66
|
/**
|
|
62
|
-
* Creates a path from segments
|
|
67
|
+
* Creates a path from multiple segments (combines lines, arcs, circles, polylines, splines).
|
|
68
|
+
* Similar to OCCT wires - segments are connected to form a continuous or multi-part path.
|
|
69
|
+
* Example: segments=[lineSegment, arcSegment, polylineSegment] → combined path entity
|
|
63
70
|
* @param inputs Path definition with segments
|
|
64
71
|
* @returns Path DTO
|
|
65
72
|
* @group dxf
|
|
@@ -70,7 +77,9 @@ export class Dxf {
|
|
|
70
77
|
return inputs;
|
|
71
78
|
}
|
|
72
79
|
/**
|
|
73
|
-
* Creates a paths part with layer and color
|
|
80
|
+
* Creates a paths part with layer and color assignment for DXF organization.
|
|
81
|
+
* Groups multiple paths into a single layer with consistent styling.
|
|
82
|
+
* Example: paths=[path1, path2], layer="Outlines", color=red → grouped geometry
|
|
74
83
|
* @param inputs Paths part definition
|
|
75
84
|
* @returns Paths part DTO
|
|
76
85
|
* @group dxf
|
|
@@ -81,8 +90,9 @@ export class Dxf {
|
|
|
81
90
|
return inputs;
|
|
82
91
|
}
|
|
83
92
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
93
|
+
* Generates a complete DXF file from paths parts (exports 2D CAD drawing format).
|
|
94
|
+
* Supports lines, arcs, circles, polylines, and splines organized in layered paths.
|
|
95
|
+
* Example: model with 3 parts on different layers → valid DXF file string for CAD software
|
|
86
96
|
* @param inputs DXF model definition
|
|
87
97
|
* @returns DXF file content as string
|
|
88
98
|
* @group dxf
|
|
@@ -12,7 +12,8 @@ export declare class Line {
|
|
|
12
12
|
private readonly geometryHelper;
|
|
13
13
|
constructor(vector: Vector, point: Point, geometryHelper: GeometryHelper);
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Extracts start point from a line.
|
|
16
|
+
* Example: line={start:[0,0,0], end:[10,5,0]} → [0,0,0]
|
|
16
17
|
* @param inputs a line
|
|
17
18
|
* @returns start point
|
|
18
19
|
* @group get
|
|
@@ -21,7 +22,8 @@ export declare class Line {
|
|
|
21
22
|
*/
|
|
22
23
|
getStartPoint(inputs: Inputs.Line.LineDto): Inputs.Base.Point3;
|
|
23
24
|
/**
|
|
24
|
-
*
|
|
25
|
+
* Extracts end point from a line.
|
|
26
|
+
* Example: line={start:[0,0,0], end:[10,5,0]} → [10,5,0]
|
|
25
27
|
* @param inputs a line
|
|
26
28
|
* @returns end point
|
|
27
29
|
* @group get
|
|
@@ -30,7 +32,8 @@ export declare class Line {
|
|
|
30
32
|
*/
|
|
31
33
|
getEndPoint(inputs: Inputs.Line.LineDto): Inputs.Base.Point3;
|
|
32
34
|
/**
|
|
33
|
-
*
|
|
35
|
+
* Calculates length (distance) of a line segment.
|
|
36
|
+
* Example: line={start:[0,0,0], end:[3,4,0]} → 5 (using Pythagorean theorem)
|
|
34
37
|
* @param inputs a line
|
|
35
38
|
* @returns line length
|
|
36
39
|
* @group get
|
|
@@ -39,7 +42,8 @@ export declare class Line {
|
|
|
39
42
|
*/
|
|
40
43
|
length(inputs: Inputs.Line.LineDto): number;
|
|
41
44
|
/**
|
|
42
|
-
*
|
|
45
|
+
* Reverses line direction by swapping start and end points.
|
|
46
|
+
* Example: line={start:[0,0,0], end:[10,5,0]} → {start:[10,5,0], end:[0,0,0]}
|
|
43
47
|
* @param inputs a line
|
|
44
48
|
* @returns reversed line
|
|
45
49
|
* @group operations
|
|
@@ -48,7 +52,8 @@ export declare class Line {
|
|
|
48
52
|
*/
|
|
49
53
|
reverse(inputs: Inputs.Line.LineDto): Inputs.Base.Line3;
|
|
50
54
|
/**
|
|
51
|
-
*
|
|
55
|
+
* Applies transformation matrix to line (rotates, scales, or translates both endpoints).
|
|
56
|
+
* Example: line={start:[0,0,0], end:[10,0,0]} with translation [5,5,0] → {start:[5,5,0], end:[15,5,0]}
|
|
52
57
|
* @param inputs a line
|
|
53
58
|
* @returns transformed line
|
|
54
59
|
* @group transforms
|
|
@@ -57,7 +62,8 @@ export declare class Line {
|
|
|
57
62
|
*/
|
|
58
63
|
transformLine(inputs: Inputs.Line.TransformLineDto): Inputs.Base.Line3;
|
|
59
64
|
/**
|
|
60
|
-
*
|
|
65
|
+
* Applies multiple transformations to multiple lines (one transform per line).
|
|
66
|
+
* Example: 3 lines with 3 different translation matrices → each line moved independently
|
|
61
67
|
* @param inputs lines
|
|
62
68
|
* @returns transformed lines
|
|
63
69
|
* @group transforms
|
|
@@ -66,7 +72,8 @@ export declare class Line {
|
|
|
66
72
|
*/
|
|
67
73
|
transformsForLines(inputs: Inputs.Line.TransformsLinesDto): Inputs.Base.Line3[];
|
|
68
74
|
/**
|
|
69
|
-
*
|
|
75
|
+
* Creates a line from two points (line object with start and end properties).
|
|
76
|
+
* Example: start=[0,0,0], end=[10,5,0] → {start:[0,0,0], end:[10,5,0]}
|
|
70
77
|
* @param inputs start and end points of the line
|
|
71
78
|
* @returns line
|
|
72
79
|
* @group create
|
|
@@ -75,7 +82,8 @@ export declare class Line {
|
|
|
75
82
|
*/
|
|
76
83
|
create(inputs: Inputs.Line.LinePointsDto): Inputs.Base.Line3;
|
|
77
84
|
/**
|
|
78
|
-
*
|
|
85
|
+
* Creates a segment from two points (array format: [start, end]).
|
|
86
|
+
* Example: start=[0,0,0], end=[10,5,0] → [[0,0,0], [10,5,0]]
|
|
79
87
|
* @param inputs start and end points of the segment
|
|
80
88
|
* @returns segment
|
|
81
89
|
* @group create
|
|
@@ -84,7 +92,8 @@ export declare class Line {
|
|
|
84
92
|
*/
|
|
85
93
|
createSegment(inputs: Inputs.Line.LinePointsDto): Inputs.Base.Segment3;
|
|
86
94
|
/**
|
|
87
|
-
*
|
|
95
|
+
* Calculates point at parameter t along line segment (0=start, 1=end, linear interpolation).
|
|
96
|
+
* Example: line={start:[0,0,0], end:[10,0,0]}, param=0.5 → [5,0,0] (midpoint)
|
|
88
97
|
* @param inputs line
|
|
89
98
|
* @returns point on line
|
|
90
99
|
* @group get
|
|
@@ -93,7 +102,8 @@ export declare class Line {
|
|
|
93
102
|
*/
|
|
94
103
|
getPointOnLine(inputs: Inputs.Line.PointOnLineDto): Inputs.Base.Point3;
|
|
95
104
|
/**
|
|
96
|
-
*
|
|
105
|
+
* Creates line segments connecting consecutive points in a list (forms a polyline path).
|
|
106
|
+
* Example: points=[[0,0,0], [5,0,0], [5,5,0]] → 2 lines: [0→5] and [5→5,5]
|
|
97
107
|
* @param inputs points
|
|
98
108
|
* @returns lines
|
|
99
109
|
* @group create
|
|
@@ -102,7 +112,9 @@ export declare class Line {
|
|
|
102
112
|
*/
|
|
103
113
|
linesBetweenPoints(inputs: Inputs.Line.PointsLinesDto): Inputs.Base.Line3[];
|
|
104
114
|
/**
|
|
105
|
-
*
|
|
115
|
+
* Creates lines by pairing corresponding start and end points from two arrays.
|
|
116
|
+
* Filters out zero-length lines.
|
|
117
|
+
* Example: starts=[[0,0,0], [5,0,0]], ends=[[0,5,0], [5,5,0]] → 2 lines connecting paired points
|
|
106
118
|
* @param inputs start points and end points
|
|
107
119
|
* @returns lines
|
|
108
120
|
* @group create
|
|
@@ -111,7 +123,8 @@ export declare class Line {
|
|
|
111
123
|
*/
|
|
112
124
|
linesBetweenStartAndEndPoints(inputs: Inputs.Line.LineStartEndPointsDto): Inputs.Base.Line3[];
|
|
113
125
|
/**
|
|
114
|
-
*
|
|
126
|
+
* Converts line object to segment array format.
|
|
127
|
+
* Example: {start:[0,0,0], end:[10,5,0]} → [[0,0,0], [10,5,0]]
|
|
115
128
|
* @param inputs line
|
|
116
129
|
* @returns segment
|
|
117
130
|
* @group convert
|
|
@@ -120,7 +133,8 @@ export declare class Line {
|
|
|
120
133
|
*/
|
|
121
134
|
lineToSegment(inputs: Inputs.Line.LineDto): Inputs.Base.Segment3;
|
|
122
135
|
/**
|
|
123
|
-
* Converts
|
|
136
|
+
* Converts multiple line objects to segment array format (batch conversion).
|
|
137
|
+
* Example: 3 line objects → 3 segment arrays [[start1, end1], [start2, end2], ...]
|
|
124
138
|
* @param inputs lines
|
|
125
139
|
* @returns segments
|
|
126
140
|
* @group convert
|
|
@@ -129,7 +143,8 @@ export declare class Line {
|
|
|
129
143
|
*/
|
|
130
144
|
linesToSegments(inputs: Inputs.Line.LinesDto): Inputs.Base.Segment3[];
|
|
131
145
|
/**
|
|
132
|
-
* Converts
|
|
146
|
+
* Converts segment array to line object format.
|
|
147
|
+
* Example: [[0,0,0], [10,5,0]] → {start:[0,0,0], end:[10,5,0]}
|
|
133
148
|
* @param inputs segment
|
|
134
149
|
* @returns line
|
|
135
150
|
* @group convert
|
|
@@ -138,7 +153,8 @@ export declare class Line {
|
|
|
138
153
|
*/
|
|
139
154
|
segmentToLine(inputs: Inputs.Line.SegmentDto): Inputs.Base.Line3;
|
|
140
155
|
/**
|
|
141
|
-
* Converts
|
|
156
|
+
* Converts multiple segment arrays to line object format (batch conversion).
|
|
157
|
+
* Example: 3 segment arrays → 3 line objects with start/end properties
|
|
142
158
|
* @param inputs segments
|
|
143
159
|
* @returns lines
|
|
144
160
|
* @group convert
|
|
@@ -147,7 +163,9 @@ export declare class Line {
|
|
|
147
163
|
*/
|
|
148
164
|
segmentsToLines(inputs: Inputs.Line.SegmentsDto): Inputs.Base.Line3[];
|
|
149
165
|
/**
|
|
150
|
-
*
|
|
166
|
+
* Calculates intersection point of two lines (or segments if checkSegmentsOnly=true).
|
|
167
|
+
* Returns undefined if lines are parallel, skew, or segments don't overlap.
|
|
168
|
+
* Example: line1={start:[0,0,0], end:[10,0,0]}, line2={start:[5,-5,0], end:[5,5,0]} → [5,0,0]
|
|
151
169
|
* @param inputs line1 and line2
|
|
152
170
|
* @returns intersection point or undefined if no intersection
|
|
153
171
|
* @group intersection
|
package/lib/api/services/line.js
CHANGED
|
@@ -9,7 +9,8 @@ export class Line {
|
|
|
9
9
|
this.geometryHelper = geometryHelper;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Extracts start point from a line.
|
|
13
|
+
* Example: line={start:[0,0,0], end:[10,5,0]} → [0,0,0]
|
|
13
14
|
* @param inputs a line
|
|
14
15
|
* @returns start point
|
|
15
16
|
* @group get
|
|
@@ -20,7 +21,8 @@ export class Line {
|
|
|
20
21
|
return inputs.line.start;
|
|
21
22
|
}
|
|
22
23
|
/**
|
|
23
|
-
*
|
|
24
|
+
* Extracts end point from a line.
|
|
25
|
+
* Example: line={start:[0,0,0], end:[10,5,0]} → [10,5,0]
|
|
24
26
|
* @param inputs a line
|
|
25
27
|
* @returns end point
|
|
26
28
|
* @group get
|
|
@@ -31,7 +33,8 @@ export class Line {
|
|
|
31
33
|
return inputs.line.end;
|
|
32
34
|
}
|
|
33
35
|
/**
|
|
34
|
-
*
|
|
36
|
+
* Calculates length (distance) of a line segment.
|
|
37
|
+
* Example: line={start:[0,0,0], end:[3,4,0]} → 5 (using Pythagorean theorem)
|
|
35
38
|
* @param inputs a line
|
|
36
39
|
* @returns line length
|
|
37
40
|
* @group get
|
|
@@ -42,7 +45,8 @@ export class Line {
|
|
|
42
45
|
return this.point.distance({ startPoint: inputs.line.start, endPoint: inputs.line.end });
|
|
43
46
|
}
|
|
44
47
|
/**
|
|
45
|
-
*
|
|
48
|
+
* Reverses line direction by swapping start and end points.
|
|
49
|
+
* Example: line={start:[0,0,0], end:[10,5,0]} → {start:[10,5,0], end:[0,0,0]}
|
|
46
50
|
* @param inputs a line
|
|
47
51
|
* @returns reversed line
|
|
48
52
|
* @group operations
|
|
@@ -53,7 +57,8 @@ export class Line {
|
|
|
53
57
|
return { start: inputs.line.end, end: inputs.line.start };
|
|
54
58
|
}
|
|
55
59
|
/**
|
|
56
|
-
*
|
|
60
|
+
* Applies transformation matrix to line (rotates, scales, or translates both endpoints).
|
|
61
|
+
* Example: line={start:[0,0,0], end:[10,0,0]} with translation [5,5,0] → {start:[5,5,0], end:[15,5,0]}
|
|
57
62
|
* @param inputs a line
|
|
58
63
|
* @returns transformed line
|
|
59
64
|
* @group transforms
|
|
@@ -70,7 +75,8 @@ export class Line {
|
|
|
70
75
|
};
|
|
71
76
|
}
|
|
72
77
|
/**
|
|
73
|
-
*
|
|
78
|
+
* Applies multiple transformations to multiple lines (one transform per line).
|
|
79
|
+
* Example: 3 lines with 3 different translation matrices → each line moved independently
|
|
74
80
|
* @param inputs lines
|
|
75
81
|
* @returns transformed lines
|
|
76
82
|
* @group transforms
|
|
@@ -89,7 +95,8 @@ export class Line {
|
|
|
89
95
|
});
|
|
90
96
|
}
|
|
91
97
|
/**
|
|
92
|
-
*
|
|
98
|
+
* Creates a line from two points (line object with start and end properties).
|
|
99
|
+
* Example: start=[0,0,0], end=[10,5,0] → {start:[0,0,0], end:[10,5,0]}
|
|
93
100
|
* @param inputs start and end points of the line
|
|
94
101
|
* @returns line
|
|
95
102
|
* @group create
|
|
@@ -103,7 +110,8 @@ export class Line {
|
|
|
103
110
|
};
|
|
104
111
|
}
|
|
105
112
|
/**
|
|
106
|
-
*
|
|
113
|
+
* Creates a segment from two points (array format: [start, end]).
|
|
114
|
+
* Example: start=[0,0,0], end=[10,5,0] → [[0,0,0], [10,5,0]]
|
|
107
115
|
* @param inputs start and end points of the segment
|
|
108
116
|
* @returns segment
|
|
109
117
|
* @group create
|
|
@@ -117,7 +125,8 @@ export class Line {
|
|
|
117
125
|
];
|
|
118
126
|
}
|
|
119
127
|
/**
|
|
120
|
-
*
|
|
128
|
+
* Calculates point at parameter t along line segment (0=start, 1=end, linear interpolation).
|
|
129
|
+
* Example: line={start:[0,0,0], end:[10,0,0]}, param=0.5 → [5,0,0] (midpoint)
|
|
121
130
|
* @param inputs line
|
|
122
131
|
* @returns point on line
|
|
123
132
|
* @group get
|
|
@@ -135,7 +144,8 @@ export class Line {
|
|
|
135
144
|
return point;
|
|
136
145
|
}
|
|
137
146
|
/**
|
|
138
|
-
*
|
|
147
|
+
* Creates line segments connecting consecutive points in a list (forms a polyline path).
|
|
148
|
+
* Example: points=[[0,0,0], [5,0,0], [5,5,0]] → 2 lines: [0→5] and [5→5,5]
|
|
139
149
|
* @param inputs points
|
|
140
150
|
* @returns lines
|
|
141
151
|
* @group create
|
|
@@ -152,7 +162,9 @@ export class Line {
|
|
|
152
162
|
return lines;
|
|
153
163
|
}
|
|
154
164
|
/**
|
|
155
|
-
*
|
|
165
|
+
* Creates lines by pairing corresponding start and end points from two arrays.
|
|
166
|
+
* Filters out zero-length lines.
|
|
167
|
+
* Example: starts=[[0,0,0], [5,0,0]], ends=[[0,5,0], [5,5,0]] → 2 lines connecting paired points
|
|
156
168
|
* @param inputs start points and end points
|
|
157
169
|
* @returns lines
|
|
158
170
|
* @group create
|
|
@@ -165,7 +177,8 @@ export class Line {
|
|
|
165
177
|
.filter(line => this.point.distance({ startPoint: line.start, endPoint: line.end }) !== 0);
|
|
166
178
|
}
|
|
167
179
|
/**
|
|
168
|
-
*
|
|
180
|
+
* Converts line object to segment array format.
|
|
181
|
+
* Example: {start:[0,0,0], end:[10,5,0]} → [[0,0,0], [10,5,0]]
|
|
169
182
|
* @param inputs line
|
|
170
183
|
* @returns segment
|
|
171
184
|
* @group convert
|
|
@@ -176,7 +189,8 @@ export class Line {
|
|
|
176
189
|
return [inputs.line.start, inputs.line.end];
|
|
177
190
|
}
|
|
178
191
|
/**
|
|
179
|
-
* Converts
|
|
192
|
+
* Converts multiple line objects to segment array format (batch conversion).
|
|
193
|
+
* Example: 3 line objects → 3 segment arrays [[start1, end1], [start2, end2], ...]
|
|
180
194
|
* @param inputs lines
|
|
181
195
|
* @returns segments
|
|
182
196
|
* @group convert
|
|
@@ -187,7 +201,8 @@ export class Line {
|
|
|
187
201
|
return inputs.lines.map(line => [line.start, line.end]);
|
|
188
202
|
}
|
|
189
203
|
/**
|
|
190
|
-
* Converts
|
|
204
|
+
* Converts segment array to line object format.
|
|
205
|
+
* Example: [[0,0,0], [10,5,0]] → {start:[0,0,0], end:[10,5,0]}
|
|
191
206
|
* @param inputs segment
|
|
192
207
|
* @returns line
|
|
193
208
|
* @group convert
|
|
@@ -198,7 +213,8 @@ export class Line {
|
|
|
198
213
|
return { start: inputs.segment[0], end: inputs.segment[1] };
|
|
199
214
|
}
|
|
200
215
|
/**
|
|
201
|
-
* Converts
|
|
216
|
+
* Converts multiple segment arrays to line object format (batch conversion).
|
|
217
|
+
* Example: 3 segment arrays → 3 line objects with start/end properties
|
|
202
218
|
* @param inputs segments
|
|
203
219
|
* @returns lines
|
|
204
220
|
* @group convert
|
|
@@ -209,7 +225,9 @@ export class Line {
|
|
|
209
225
|
return inputs.segments.map(segment => ({ start: segment[0], end: segment[1] }));
|
|
210
226
|
}
|
|
211
227
|
/**
|
|
212
|
-
*
|
|
228
|
+
* Calculates intersection point of two lines (or segments if checkSegmentsOnly=true).
|
|
229
|
+
* Returns undefined if lines are parallel, skew, or segments don't overlap.
|
|
230
|
+
* Example: line1={start:[0,0,0], end:[10,0,0]}, line2={start:[5,-5,0], end:[5,5,0]} → [5,0,0]
|
|
213
231
|
* @param inputs line1 and line2
|
|
214
232
|
* @returns intersection point or undefined if no intersection
|
|
215
233
|
* @group intersection
|