@immugio/three-math-extensions 0.2.8 → 0.2.10
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/CHANGELOG.md +31 -3
- package/README.md +1 -80
- package/cjs/Line2D.js +11 -2
- package/cjs/index.js +3 -1
- package/cjs/isPointInPolygon.js +16 -0
- package/docs/README.md +86 -1
- package/docs/classes/BoundingBox.md +7 -7
- package/docs/classes/Line2D.md +88 -60
- package/docs/classes/Line3D.md +32 -32
- package/docs/classes/Polygon.md +15 -15
- package/docs/classes/Rectangle.md +17 -17
- package/docs/classes/Size2.md +3 -3
- package/docs/classes/Vec2.md +54 -6
- package/docs/classes/Vec3.md +11 -11
- package/docs/interfaces/Point2.md +2 -2
- package/docs/interfaces/Point3.md +3 -3
- package/docs/modules.md +25 -3
- package/esm/Line2D.js +11 -2
- package/esm/index.js +1 -0
- package/esm/isPointInPolygon.js +12 -0
- package/package.json +1 -1
- package/src/Line2D.ts +12 -2
- package/src/index.ts +2 -1
- package/src/isPointInPolygon.ts +19 -0
- package/types/Line2D.d.ts +4 -2
- package/types/index.d.ts +1 -0
- package/types/isPointInPolygon.d.ts +2 -0
package/docs/classes/Vec3.md
CHANGED
|
@@ -72,7 +72,7 @@ Adds x amount to this Vec3 instance and return this
|
|
|
72
72
|
|
|
73
73
|
#### Defined in
|
|
74
74
|
|
|
75
|
-
[src/Vec3.ts:65](https://github.com/Immugio/three-math-extensions/blob/
|
|
75
|
+
[src/Vec3.ts:65](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/Vec3.ts#L65)
|
|
76
76
|
|
|
77
77
|
___
|
|
78
78
|
|
|
@@ -94,7 +94,7 @@ Adds y amount to this Vec3 instance and return this
|
|
|
94
94
|
|
|
95
95
|
#### Defined in
|
|
96
96
|
|
|
97
|
-
[src/Vec3.ts:56](https://github.com/Immugio/three-math-extensions/blob/
|
|
97
|
+
[src/Vec3.ts:56](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/Vec3.ts#L56)
|
|
98
98
|
|
|
99
99
|
___
|
|
100
100
|
|
|
@@ -112,7 +112,7 @@ Vector3.clone
|
|
|
112
112
|
|
|
113
113
|
#### Defined in
|
|
114
114
|
|
|
115
|
-
[src/Vec3.ts:114](https://github.com/Immugio/three-math-extensions/blob/
|
|
115
|
+
[src/Vec3.ts:114](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/Vec3.ts#L114)
|
|
116
116
|
|
|
117
117
|
___
|
|
118
118
|
|
|
@@ -134,7 +134,7 @@ Returns a clone of the point closest to this from the given points.
|
|
|
134
134
|
|
|
135
135
|
#### Defined in
|
|
136
136
|
|
|
137
|
-
[src/Vec3.ts:74](https://github.com/Immugio/three-math-extensions/blob/
|
|
137
|
+
[src/Vec3.ts:74](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/Vec3.ts#L74)
|
|
138
138
|
|
|
139
139
|
___
|
|
140
140
|
|
|
@@ -156,7 +156,7 @@ Get distance to another vector while ignoring the y-axis.
|
|
|
156
156
|
|
|
157
157
|
#### Defined in
|
|
158
158
|
|
|
159
|
-
[src/Vec3.ts:98](https://github.com/Immugio/three-math-extensions/blob/
|
|
159
|
+
[src/Vec3.ts:98](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/Vec3.ts#L98)
|
|
160
160
|
|
|
161
161
|
___
|
|
162
162
|
|
|
@@ -180,7 +180,7 @@ maxDistance is the maximum distance between the two vectors within which they ar
|
|
|
180
180
|
|
|
181
181
|
#### Defined in
|
|
182
182
|
|
|
183
|
-
[src/Vec3.ts:106](https://github.com/Immugio/three-math-extensions/blob/
|
|
183
|
+
[src/Vec3.ts:106](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/Vec3.ts#L106)
|
|
184
184
|
|
|
185
185
|
___
|
|
186
186
|
|
|
@@ -204,7 +204,7 @@ This Vec3 instance.
|
|
|
204
204
|
|
|
205
205
|
#### Defined in
|
|
206
206
|
|
|
207
|
-
[src/Vec3.ts:43](https://github.com/Immugio/three-math-extensions/blob/
|
|
207
|
+
[src/Vec3.ts:43](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/Vec3.ts#L43)
|
|
208
208
|
|
|
209
209
|
___
|
|
210
210
|
|
|
@@ -229,7 +229,7 @@ This Vec3 instance.
|
|
|
229
229
|
|
|
230
230
|
#### Defined in
|
|
231
231
|
|
|
232
|
-
[src/Vec3.ts:27](https://github.com/Immugio/three-math-extensions/blob/
|
|
232
|
+
[src/Vec3.ts:27](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/Vec3.ts#L27)
|
|
233
233
|
|
|
234
234
|
___
|
|
235
235
|
|
|
@@ -245,7 +245,7 @@ Projects this Vec3 instance onto 2d plan. Vec3.z becomes Vec2.y and Vec3.y is ig
|
|
|
245
245
|
|
|
246
246
|
#### Defined in
|
|
247
247
|
|
|
248
|
-
[src/Vec3.ts:90](https://github.com/Immugio/three-math-extensions/blob/
|
|
248
|
+
[src/Vec3.ts:90](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/Vec3.ts#L90)
|
|
249
249
|
|
|
250
250
|
___
|
|
251
251
|
|
|
@@ -261,7 +261,7 @@ Returns a clone of this Vec3 instance with y and z swapped.
|
|
|
261
261
|
|
|
262
262
|
#### Defined in
|
|
263
263
|
|
|
264
|
-
[src/Vec3.ts:83](https://github.com/Immugio/three-math-extensions/blob/
|
|
264
|
+
[src/Vec3.ts:83](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/Vec3.ts#L83)
|
|
265
265
|
|
|
266
266
|
___
|
|
267
267
|
|
|
@@ -285,4 +285,4 @@ A new Vec3 instance.
|
|
|
285
285
|
|
|
286
286
|
#### Defined in
|
|
287
287
|
|
|
288
|
-
[src/Vec3.ts:17](https://github.com/Immugio/three-math-extensions/blob/
|
|
288
|
+
[src/Vec3.ts:17](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/Vec3.ts#L17)
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
#### Defined in
|
|
19
19
|
|
|
20
|
-
[src/Point2.ts:2](https://github.com/Immugio/three-math-extensions/blob/
|
|
20
|
+
[src/Point2.ts:2](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/Point2.ts#L2)
|
|
21
21
|
|
|
22
22
|
___
|
|
23
23
|
|
|
@@ -27,4 +27,4 @@ ___
|
|
|
27
27
|
|
|
28
28
|
#### Defined in
|
|
29
29
|
|
|
30
|
-
[src/Point2.ts:3](https://github.com/Immugio/three-math-extensions/blob/
|
|
30
|
+
[src/Point2.ts:3](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/Point2.ts#L3)
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
#### Defined in
|
|
20
20
|
|
|
21
|
-
[src/Point3.ts:2](https://github.com/Immugio/three-math-extensions/blob/
|
|
21
|
+
[src/Point3.ts:2](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/Point3.ts#L2)
|
|
22
22
|
|
|
23
23
|
___
|
|
24
24
|
|
|
@@ -28,7 +28,7 @@ ___
|
|
|
28
28
|
|
|
29
29
|
#### Defined in
|
|
30
30
|
|
|
31
|
-
[src/Point3.ts:3](https://github.com/Immugio/three-math-extensions/blob/
|
|
31
|
+
[src/Point3.ts:3](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/Point3.ts#L3)
|
|
32
32
|
|
|
33
33
|
___
|
|
34
34
|
|
|
@@ -38,4 +38,4 @@ ___
|
|
|
38
38
|
|
|
39
39
|
#### Defined in
|
|
40
40
|
|
|
41
|
-
[src/Point3.ts:4](https://github.com/Immugio/three-math-extensions/blob/
|
|
41
|
+
[src/Point3.ts:4](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/Point3.ts#L4)
|
package/docs/modules.md
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
|
|
27
27
|
### Functions
|
|
28
28
|
|
|
29
|
+
- [isPointInPolygon](modules.md#ispointinpolygon)
|
|
29
30
|
- [normalizeAngleDegrees](modules.md#normalizeangledegrees)
|
|
30
31
|
- [normalizeAngleRadians](modules.md#normalizeangleradians)
|
|
31
32
|
|
|
@@ -37,10 +38,31 @@
|
|
|
37
38
|
|
|
38
39
|
#### Defined in
|
|
39
40
|
|
|
40
|
-
[src/MathConstants.ts:1](https://github.com/Immugio/three-math-extensions/blob/
|
|
41
|
+
[src/MathConstants.ts:1](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/MathConstants.ts#L1)
|
|
41
42
|
|
|
42
43
|
## Functions
|
|
43
44
|
|
|
45
|
+
### isPointInPolygon
|
|
46
|
+
|
|
47
|
+
▸ **isPointInPolygon**(`p`, `point`): `boolean`
|
|
48
|
+
|
|
49
|
+
#### Parameters
|
|
50
|
+
|
|
51
|
+
| Name | Type |
|
|
52
|
+
| :------ | :------ |
|
|
53
|
+
| `p` | [`Point2`](interfaces/Point2.md)[] |
|
|
54
|
+
| `point` | [`Point2`](interfaces/Point2.md) |
|
|
55
|
+
|
|
56
|
+
#### Returns
|
|
57
|
+
|
|
58
|
+
`boolean`
|
|
59
|
+
|
|
60
|
+
#### Defined in
|
|
61
|
+
|
|
62
|
+
[src/isPointInPolygon.ts:3](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/isPointInPolygon.ts#L3)
|
|
63
|
+
|
|
64
|
+
___
|
|
65
|
+
|
|
44
66
|
### normalizeAngleDegrees
|
|
45
67
|
|
|
46
68
|
▸ **normalizeAngleDegrees**(`angle`): `number`
|
|
@@ -59,7 +81,7 @@ Normalizes an angle in degrees to the range [0, 360].
|
|
|
59
81
|
|
|
60
82
|
#### Defined in
|
|
61
83
|
|
|
62
|
-
[src/normalizeAngleDegrees.ts:5](https://github.com/Immugio/three-math-extensions/blob/
|
|
84
|
+
[src/normalizeAngleDegrees.ts:5](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/normalizeAngleDegrees.ts#L5)
|
|
63
85
|
|
|
64
86
|
___
|
|
65
87
|
|
|
@@ -81,4 +103,4 @@ Normalize an angle in radians to the range of 0 to 2π.
|
|
|
81
103
|
|
|
82
104
|
#### Defined in
|
|
83
105
|
|
|
84
|
-
[src/normalizeAngleRadians.ts:7](https://github.com/Immugio/three-math-extensions/blob/
|
|
106
|
+
[src/normalizeAngleRadians.ts:7](https://github.com/Immugio/three-math-extensions/blob/66cba15/src/normalizeAngleRadians.ts#L7)
|
package/esm/Line2D.js
CHANGED
|
@@ -511,9 +511,11 @@ export class Line2D {
|
|
|
511
511
|
return this;
|
|
512
512
|
}
|
|
513
513
|
/**
|
|
514
|
-
* Returns the intersection point of two lines.
|
|
514
|
+
* Returns the intersection point of two lines.
|
|
515
|
+
* @param other
|
|
516
|
+
* @param lineSegmentOnly If true, only return the intersection if it is within the line segments. Otherwise, return the intersection if the lines intersect anywhere.
|
|
515
517
|
*/
|
|
516
|
-
intersect(other) {
|
|
518
|
+
intersect(other, lineSegmentOnly) {
|
|
517
519
|
// Check if none of the lines are of length 0
|
|
518
520
|
if ((this.start.x === this.end.x && this.start.y === this.end.y) || (other.start.x === other.end.x && other.start.y === other.end.y)) {
|
|
519
521
|
return null;
|
|
@@ -524,6 +526,13 @@ export class Line2D {
|
|
|
524
526
|
return null;
|
|
525
527
|
}
|
|
526
528
|
const ua = ((other.end.x - other.start.x) * (this.start.y - other.start.y) - (other.end.y - other.start.y) * (this.start.x - other.start.x)) / denominator;
|
|
529
|
+
// Check if the intersection point is within the bounds of the line segments if required
|
|
530
|
+
if (lineSegmentOnly) {
|
|
531
|
+
const ub = ((this.end.x - this.start.x) * (this.start.y - other.start.y) - (this.end.y - this.start.y) * (this.start.x - other.start.x)) / denominator;
|
|
532
|
+
if (ua < 0 || ua > 1 || ub < 0 || ub > 1) {
|
|
533
|
+
return null;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
527
536
|
// Return an object with the x and y coordinates of the intersection
|
|
528
537
|
const x = this.start.x + ua * (this.end.x - this.start.x);
|
|
529
538
|
const y = this.start.y + ua * (this.end.y - this.start.y);
|
package/esm/index.js
CHANGED
|
@@ -9,3 +9,4 @@ export { Rectangle } from "./Rectangle";
|
|
|
9
9
|
export { normalizeAngleDegrees } from "./normalizeAngleDegrees";
|
|
10
10
|
export { normalizeAngleRadians } from "./normalizeAngleRadians";
|
|
11
11
|
export { TwoPI } from "./MathConstants";
|
|
12
|
+
export { isPointInPolygon } from "./isPointInPolygon";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function isPointInPolygon(p, point) {
|
|
2
|
+
const x = point.x, y = point.y;
|
|
3
|
+
let i, j, c = false;
|
|
4
|
+
for (i = 0, j = p.length - 1; i < p.length; j = i++) {
|
|
5
|
+
if ((((p[i].y <= y) && (y < p[j].y)) ||
|
|
6
|
+
((p[j].y <= y) && (y < p[i].y))) &&
|
|
7
|
+
(x < (p[j].x - p[i].x) * (y - p[i].y) / (p[j].y - p[i].y) + p[i].x)) {
|
|
8
|
+
c = !c;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return c;
|
|
12
|
+
}
|
package/package.json
CHANGED
package/src/Line2D.ts
CHANGED
|
@@ -600,9 +600,11 @@ export class Line2D {
|
|
|
600
600
|
}
|
|
601
601
|
|
|
602
602
|
/**
|
|
603
|
-
* Returns the intersection point of two lines.
|
|
603
|
+
* Returns the intersection point of two lines.
|
|
604
|
+
* @param other
|
|
605
|
+
* @param lineSegmentOnly If true, only return the intersection if it is within the line segments. Otherwise, return the intersection if the lines intersect anywhere.
|
|
604
606
|
*/
|
|
605
|
-
public intersect(other: Line2D): Vec2 {
|
|
607
|
+
public intersect(other: Line2D, lineSegmentOnly?: boolean): Vec2 {
|
|
606
608
|
// Check if none of the lines are of length 0
|
|
607
609
|
if ((this.start.x === this.end.x && this.start.y === this.end.y) || (other.start.x === other.end.x && other.start.y === other.end.y)) {
|
|
608
610
|
return null;
|
|
@@ -617,6 +619,14 @@ export class Line2D {
|
|
|
617
619
|
|
|
618
620
|
const ua = ((other.end.x - other.start.x) * (this.start.y - other.start.y) - (other.end.y - other.start.y) * (this.start.x - other.start.x)) / denominator;
|
|
619
621
|
|
|
622
|
+
// Check if the intersection point is within the bounds of the line segments if required
|
|
623
|
+
if (lineSegmentOnly) {
|
|
624
|
+
const ub = ((this.end.x - this.start.x) * (this.start.y - other.start.y) - (this.end.y - this.start.y) * (this.start.x - other.start.x)) / denominator;
|
|
625
|
+
if (ua < 0 || ua > 1 || ub < 0 || ub > 1) {
|
|
626
|
+
return null;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
|
|
620
630
|
// Return an object with the x and y coordinates of the intersection
|
|
621
631
|
const x = this.start.x + ua * (this.end.x - this.start.x);
|
|
622
632
|
const y = this.start.y + ua * (this.end.y - this.start.y);
|
package/src/index.ts
CHANGED
|
@@ -10,4 +10,5 @@ export { normalizeAngleDegrees } from "./normalizeAngleDegrees";
|
|
|
10
10
|
export { normalizeAngleRadians } from "./normalizeAngleRadians";
|
|
11
11
|
export { TwoPI } from "./MathConstants";
|
|
12
12
|
export { Point2 } from "./Point2";
|
|
13
|
-
export { Point3 } from "./Point3";
|
|
13
|
+
export { Point3 } from "./Point3";
|
|
14
|
+
export { isPointInPolygon } from "./isPointInPolygon";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Point2 } from "./Point2";
|
|
2
|
+
|
|
3
|
+
export function isPointInPolygon(p: Point2[], point: Point2): boolean {
|
|
4
|
+
|
|
5
|
+
const x = point.x, y = point.y;
|
|
6
|
+
|
|
7
|
+
let i: number, j: number, c = false;
|
|
8
|
+
|
|
9
|
+
for (i = 0, j = p.length - 1; i < p.length; j = i++) {
|
|
10
|
+
|
|
11
|
+
if ((((p[i].y <= y) && (y < p[j].y)) ||
|
|
12
|
+
((p[j].y <= y) && (y < p[i].y))) &&
|
|
13
|
+
(x < (p[j].x - p[i].x) * (y - p[i].y) / (p[j].y - p[i].y) + p[i].x)) {
|
|
14
|
+
c = !c;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return c;
|
|
19
|
+
}
|
package/types/Line2D.d.ts
CHANGED
|
@@ -199,9 +199,11 @@ export declare class Line2D {
|
|
|
199
199
|
*/
|
|
200
200
|
extendToOrTrimAtIntersection(other: Line2D, maxDistanceToIntersection?: number): this;
|
|
201
201
|
/**
|
|
202
|
-
* Returns the intersection point of two lines.
|
|
202
|
+
* Returns the intersection point of two lines.
|
|
203
|
+
* @param other
|
|
204
|
+
* @param lineSegmentOnly If true, only return the intersection if it is within the line segments. Otherwise, return the intersection if the lines intersect anywhere.
|
|
203
205
|
*/
|
|
204
|
-
intersect(other: Line2D): Vec2;
|
|
206
|
+
intersect(other: Line2D, lineSegmentOnly?: boolean): Vec2;
|
|
205
207
|
/**
|
|
206
208
|
* Check that the line section intersect and that they are in the specified angle to each other
|
|
207
209
|
* @param other Line
|
package/types/index.d.ts
CHANGED