@immugio/three-math-extensions 0.0.11 → 0.0.13

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/types/Line2D.d.ts CHANGED
@@ -1,222 +1,222 @@
1
- import { Point2 } from "./Point2";
2
- import { Vector2 } from "three";
3
- import { Vec2 } from "./Vec2";
4
- export declare class Line2D {
5
- start: Vec2;
6
- end: Vec2;
7
- index: number;
8
- constructor(start: Vec2, end: Vec2, index?: number);
9
- static fromCoordinates(x1: number, y1: number, x2: number, y2: number, index?: number): Line2D;
10
- static fromPoints(p1: Point2, p2: Point2, index?: number): Line2D;
11
- /**
12
- * Creates a polygon formed by an array of lines from points provided.
13
- * The polygon will only be closed if either
14
- * 1) the first and last points are the same or 2) `forceClosedPolygon` is true.
15
- */
16
- static fromPolygon(polygon: Point2[], forceClosedPolygon?: boolean): Line2D[];
17
- static fromLength(length: number): Line2D;
18
- get center(): Vec2;
19
- /**
20
- * Set the center of the line to the provided point. Length and direction remain unchanged.
21
- * Modifies this line.
22
- * @param value
23
- */
24
- set center(value: Point2);
25
- /**
26
- * Set the center of the line to the provided point. Length and direction remain unchanged.
27
- * Modifies this line.
28
- * @param value
29
- */
30
- setCenter(value: Point2): Line2D;
31
- resize(amount: number): Line2D;
32
- moveStartPoint(amount: number): Line2D;
33
- /**
34
- * Moves end point on the line by the given amount. Plus values move the point further away from the center.
35
- * Modifies this line.
36
- */
37
- moveEndPoint(amount: number): Line2D;
38
- private movePointOnThisLine;
39
- /**
40
- * Set the length of this line. Center and direction remain unchanged.
41
- * Modifies this line.
42
- * @param l
43
- */
44
- set length(l: number);
45
- get length(): number;
46
- /**
47
- * Set the length of this line. Center and direction remain unchanged.
48
- * @param length
49
- */
50
- setLength(length: number): this;
51
- /**
52
- * Returns the start and end points of the line as an array.
53
- * Endpoints are not cloned.
54
- */
55
- get endpoints(): Vec2[];
56
- /**
57
- * Returns the direction of this line.
58
- */
59
- get direction(): Vec2;
60
- /**
61
- * Inverts the direction of the line.
62
- * Modifies this line.
63
- */
64
- flip(): Line2D;
65
- /**
66
- * Rotates the line around the center by the given angle in radians.
67
- * Modifies this line.
68
- * @param radians Positive values rotate counter-clockwise.
69
- * @param center
70
- */
71
- rotate(radians: number, center?: Vec2): Line2D;
72
- /**
73
- * Move the line by the given vector.
74
- * Modifies this line.
75
- */
76
- translate(value: Point2): Line2D;
77
- /**
78
- * Move the line to its left by the given amount.
79
- * Modifies this line.
80
- */
81
- translateLeft(amount: number): Line2D;
82
- /**
83
- * Move the line to its right by the given amount.
84
- * Modifies this line.
85
- */
86
- translateRight(amount: number): Line2D;
87
- /**
88
- * Returns true when the point is actually inside the (finite) line segment.
89
- * https://jsfiddle.net/c06zdxtL/2/
90
- * https://stackoverflow.com/questions/6865832/detecting-if-a-point-is-of-a-line-segment/6877674
91
- * @param point: Point2
92
- */
93
- isPointOnLineSection(point: Point2): boolean;
94
- /**
95
- * Returns true when the point is beside the line **segment** and within the maxDistance.
96
- * @param point
97
- * @param maxDistance
98
- */
99
- isPointCloseToAndBesideLineSection(point: Point2, maxDistance: number): boolean;
100
- /**
101
- * Returns true when the point is beside the line **segment**
102
- * @param point
103
- */
104
- isPointBesideLineSection(point: Point2): boolean;
105
- /**
106
- * Returns true when the point is on the **infinite** line.
107
- * @param point
108
- */
109
- isPointOnInfiniteLine(point: Point2): boolean;
110
- /**
111
- * Returns true if other line is collinear and overlaps or at least touching this line.
112
- * @param other
113
- */
114
- isCollinearWithTouchOrOverlap(other: Line2D): boolean;
115
- /**
116
- * Returns true if there is any overlap between this line and the @other line section.
117
- */
118
- overlaps(other: Line2D): boolean;
119
- /**
120
- * Logical AND of this and the other line section.
121
- * @param other
122
- */
123
- getOverlap(other: Line2D): Line2D;
124
- /**
125
- * Joins a copy of @line with the @other line.
126
- * Other must be parallel to this line.
127
- * Returns null if there is no overlap
128
- * Clones the line, does not modify.
129
- * @param line
130
- * @param other
131
- */
132
- static joinLine(line: Line2D, other: Line2D): Line2D;
133
- /**
134
- * Joins provided lines into several joined lines.
135
- * Lines must be parallel for joining.
136
- * Clone the lines, does not modify.
137
- * @param lines
138
- */
139
- static joinLines(lines: Line2D[]): Line2D[];
140
- /**
141
- * Divides the Line3D into a number of segments of the given length.
142
- * Clone the line, does not modify.
143
- * @param maxSegmentLength number
144
- */
145
- chunk(maxSegmentLength: number): Line2D[];
146
- /**
147
- * Returns the closest point parameter on the **infinite** line to the given point.
148
- * @param point
149
- */
150
- closestPointToPointParameterOnInfiniteLine(point: Vector2): number;
151
- /**
152
- * Returns the closest point on the **infinite** line to the given point.
153
- * @param point
154
- */
155
- closestPointOnInfiniteLine(point: Vector2): Vec2;
156
- /**
157
- * Returns the closest point on the line **section** to the given point.
158
- * @param point
159
- */
160
- closestPointOnLine(point: Vector2): Vec2;
161
- /**
162
- * Returns the distance between the **infinite** line and the point.
163
- * @param point
164
- */
165
- distanceToPointOnInfiniteLine(point: Point2): number;
166
- /**
167
- * Returns lines that are the result of clipping @source line by the @clips.
168
- * Clips must be parallel to this line.
169
- * Clones the line, does not modify this.
170
- * @param source
171
- * @param clips
172
- */
173
- static clipLines(source: Line2D, clips: Line2D[]): Line2D[];
174
- /**
175
- * Returns the original line section split into two parts, if the line **sections** overlap, otherwise null
176
- */
177
- splitAtIntersection(other: Line2D, tolerance?: number): Line2D[];
178
- /**
179
- * If lines **sections** overlap, returns the original line section split into two parts, sorted by length
180
- * Else, if the **infinite** lines intersect, returns a new line extended to the intersection point
181
- * Otherwise, null if the lines are parallel and do not intersect
182
- */
183
- splitAtOrExtendToIntersection(other: Line2D): Line2D[];
184
- private static order;
185
- private static subtractSingle;
186
- /**
187
- * If other line is not contained within this line, the excess is trimmed.
188
- * Does not create a copy. Provided line is modified.
189
- * @param lineToTrim
190
- */
191
- trimExcess(lineToTrim: Line2D): void;
192
- /**
193
- * If other line is shorter than this, endpoints are moved to extend other
194
- * Does not create a copy. Provided line is modified.
195
- * @param lineToExtend
196
- * @param tolerance
197
- */
198
- extendToEnds(lineToExtend: Line2D, tolerance: number): void;
199
- /**
200
- * If there is an intersection between this and other, this line is extended to the intersection point. Lines are assumed to be infinite.
201
- * Modifies this line.
202
- * @param other
203
- * @param maxDistanceToIntersection
204
- */
205
- extendToOrTrimAtIntersection(other: Line2D, maxDistanceToIntersection?: number): Line2D;
206
- /**
207
- * Returns the intersection point of two lines. The lines are assumed to be infinite.
208
- */
209
- intersect(other: Line2D): Vec2;
210
- /**
211
- * Check that the infinite lines intersect and that they are in the specified angle to each other
212
- * @param other Line
213
- * @param expectedAngleInRads number
214
- */
215
- hasIntersectionWithAngle(other: Line2D, expectedAngleInRads: number): Vec2;
216
- /**
217
- * Deep clone of this line
218
- */
219
- clone(): Line2D;
220
- toString(): string;
221
- equals(other: Line2D): boolean;
222
- }
1
+ import { Point2 } from "./Point2";
2
+ import { Vector2 } from "three";
3
+ import { Vec2 } from "./Vec2";
4
+ export declare class Line2D {
5
+ start: Vec2;
6
+ end: Vec2;
7
+ index: number;
8
+ constructor(start: Vec2, end: Vec2, index?: number);
9
+ static fromCoordinates(x1: number, y1: number, x2: number, y2: number, index?: number): Line2D;
10
+ static fromPoints(p1: Point2, p2: Point2, index?: number): Line2D;
11
+ /**
12
+ * Creates a polygon formed by an array of lines from points provided.
13
+ * The polygon will only be closed if either
14
+ * 1) the first and last points are the same or 2) `forceClosedPolygon` is true.
15
+ */
16
+ static fromPolygon(polygon: Point2[], forceClosedPolygon?: boolean): Line2D[];
17
+ static fromLength(length: number): Line2D;
18
+ get center(): Vec2;
19
+ /**
20
+ * Set the center of the line to the provided point. Length and direction remain unchanged.
21
+ * Modifies this line.
22
+ * @param value
23
+ */
24
+ set center(value: Point2);
25
+ /**
26
+ * Set the center of the line to the provided point. Length and direction remain unchanged.
27
+ * Modifies this line.
28
+ * @param value
29
+ */
30
+ setCenter(value: Point2): Line2D;
31
+ resize(amount: number): Line2D;
32
+ moveStartPoint(amount: number): Line2D;
33
+ /**
34
+ * Moves end point on the line by the given amount. Plus values move the point further away from the center.
35
+ * Modifies this line.
36
+ */
37
+ moveEndPoint(amount: number): Line2D;
38
+ private movePointOnThisLine;
39
+ /**
40
+ * Set the length of this line. Center and direction remain unchanged.
41
+ * Modifies this line.
42
+ * @param l
43
+ */
44
+ set length(l: number);
45
+ get length(): number;
46
+ /**
47
+ * Set the length of this line. Center and direction remain unchanged.
48
+ * @param length
49
+ */
50
+ setLength(length: number): this;
51
+ /**
52
+ * Returns the start and end points of the line as an array.
53
+ * Endpoints are not cloned.
54
+ */
55
+ get endpoints(): Vec2[];
56
+ /**
57
+ * Returns the direction of this line.
58
+ */
59
+ get direction(): Vec2;
60
+ /**
61
+ * Inverts the direction of the line.
62
+ * Modifies this line.
63
+ */
64
+ flip(): Line2D;
65
+ /**
66
+ * Rotates the line around the center by the given angle in radians.
67
+ * Modifies this line.
68
+ * @param radians Positive values rotate counter-clockwise.
69
+ * @param center
70
+ */
71
+ rotate(radians: number, center?: Vec2): Line2D;
72
+ /**
73
+ * Move the line by the given vector.
74
+ * Modifies this line.
75
+ */
76
+ translate(value: Point2): Line2D;
77
+ /**
78
+ * Move the line to its left by the given amount.
79
+ * Modifies this line.
80
+ */
81
+ translateLeft(amount: number): Line2D;
82
+ /**
83
+ * Move the line to its right by the given amount.
84
+ * Modifies this line.
85
+ */
86
+ translateRight(amount: number): Line2D;
87
+ /**
88
+ * Returns true when the point is actually inside the (finite) line segment.
89
+ * https://jsfiddle.net/c06zdxtL/2/
90
+ * https://stackoverflow.com/questions/6865832/detecting-if-a-point-is-of-a-line-segment/6877674
91
+ * @param point: Point2
92
+ */
93
+ isPointOnLineSection(point: Point2): boolean;
94
+ /**
95
+ * Returns true when the point is beside the line **segment** and within the maxDistance.
96
+ * @param point
97
+ * @param maxDistance
98
+ */
99
+ isPointCloseToAndBesideLineSection(point: Point2, maxDistance: number): boolean;
100
+ /**
101
+ * Returns true when the point is beside the line **segment**
102
+ * @param point
103
+ */
104
+ isPointBesideLineSection(point: Point2): boolean;
105
+ /**
106
+ * Returns true when the point is on the **infinite** line.
107
+ * @param point
108
+ */
109
+ isPointOnInfiniteLine(point: Point2): boolean;
110
+ /**
111
+ * Returns true if other line is collinear and overlaps or at least touching this line.
112
+ * @param other
113
+ */
114
+ isCollinearWithTouchOrOverlap(other: Line2D): boolean;
115
+ /**
116
+ * Returns true if there is any overlap between this line and the @other line section.
117
+ */
118
+ overlaps(other: Line2D): boolean;
119
+ /**
120
+ * Logical AND of this and the other line section.
121
+ * @param other
122
+ */
123
+ getOverlap(other: Line2D): Line2D;
124
+ /**
125
+ * Joins a copy of @line with the @other line.
126
+ * Other must be parallel to this line.
127
+ * Returns null if there is no overlap
128
+ * Clones the line, does not modify.
129
+ * @param line
130
+ * @param other
131
+ */
132
+ static joinLine(line: Line2D, other: Line2D): Line2D;
133
+ /**
134
+ * Joins provided lines into several joined lines.
135
+ * Lines must be parallel for joining.
136
+ * Clone the lines, does not modify.
137
+ * @param lines
138
+ */
139
+ static joinLines(lines: Line2D[]): Line2D[];
140
+ /**
141
+ * Divides the Line3D into a number of segments of the given length.
142
+ * Clone the line, does not modify.
143
+ * @param maxSegmentLength number
144
+ */
145
+ chunk(maxSegmentLength: number): Line2D[];
146
+ /**
147
+ * Returns the closest point parameter on the **infinite** line to the given point.
148
+ * @param point
149
+ */
150
+ closestPointToPointParameterOnInfiniteLine(point: Vector2): number;
151
+ /**
152
+ * Returns the closest point on the **infinite** line to the given point.
153
+ * @param point
154
+ */
155
+ closestPointOnInfiniteLine(point: Vector2): Vec2;
156
+ /**
157
+ * Returns the closest point on the line **section** to the given point.
158
+ * @param point
159
+ */
160
+ closestPointOnLine(point: Vector2): Vec2;
161
+ /**
162
+ * Returns the distance between the **infinite** line and the point.
163
+ * @param point
164
+ */
165
+ distanceToPointOnInfiniteLine(point: Point2): number;
166
+ /**
167
+ * Returns lines that are the result of clipping @source line by the @clips.
168
+ * Clips must be parallel to this line.
169
+ * Clones the line, does not modify this.
170
+ * @param source
171
+ * @param clips
172
+ */
173
+ static clipLines(source: Line2D, clips: Line2D[]): Line2D[];
174
+ /**
175
+ * Returns the original line section split into two parts, if the line **sections** overlap, otherwise null
176
+ */
177
+ splitAtIntersection(other: Line2D, tolerance?: number): Line2D[];
178
+ /**
179
+ * If lines **sections** overlap, returns the original line section split into two parts, sorted by length
180
+ * Else, if the **infinite** lines intersect, returns a new line extended to the intersection point
181
+ * Otherwise, null if the lines are parallel and do not intersect
182
+ */
183
+ splitAtOrExtendToIntersection(other: Line2D): Line2D[];
184
+ private static order;
185
+ private static subtractSingle;
186
+ /**
187
+ * If other line is not contained within this line, the excess is trimmed.
188
+ * Does not create a copy. Provided line is modified.
189
+ * @param lineToTrim
190
+ */
191
+ trimExcess(lineToTrim: Line2D): void;
192
+ /**
193
+ * If other line is shorter than this, endpoints are moved to extend other
194
+ * Does not create a copy. Provided line is modified.
195
+ * @param lineToExtend
196
+ * @param tolerance
197
+ */
198
+ extendToEnds(lineToExtend: Line2D, tolerance: number): void;
199
+ /**
200
+ * If there is an intersection between this and other, this line is extended to the intersection point. Lines are assumed to be infinite.
201
+ * Modifies this line.
202
+ * @param other
203
+ * @param maxDistanceToIntersection
204
+ */
205
+ extendToOrTrimAtIntersection(other: Line2D, maxDistanceToIntersection?: number): Line2D;
206
+ /**
207
+ * Returns the intersection point of two lines. The lines are assumed to be infinite.
208
+ */
209
+ intersect(other: Line2D): Vec2;
210
+ /**
211
+ * Check that the infinite lines intersect and that they are in the specified angle to each other
212
+ * @param other Line
213
+ * @param expectedAngleInRads number
214
+ */
215
+ hasIntersectionWithAngle(other: Line2D, expectedAngleInRads: number): Vec2;
216
+ /**
217
+ * Deep clone of this line
218
+ */
219
+ clone(): Line2D;
220
+ toString(): string;
221
+ equals(other: Line2D): boolean;
222
+ }