@immugio/three-math-extensions 0.2.7 → 0.2.9
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 +21 -2
- package/cjs/Line2D.js +20 -2
- package/esm/Line2D.js +20 -2
- package/package.json +1 -1
- package/src/Line2D.ts +22 -2
- package/types/Line2D.d.ts +11 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
9
9
|
|
|
10
|
-
## [0.2.
|
|
10
|
+
## [0.2.9](https://github.com/Immugio/three-math-extensions/compare/16.15.10...0.2.9)
|
|
11
11
|
|
|
12
12
|
### Commits
|
|
13
13
|
|
|
@@ -19,15 +19,34 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
19
19
|
- Add Vec2.signedAngle [`863c8f2`](https://github.com/Immugio/three-math-extensions/commit/863c8f27f11288cbda535e21bb688206259269ed)
|
|
20
20
|
- Add Vec2.fromPoints to accept multiple points [`a261402`](https://github.com/Immugio/three-math-extensions/commit/a2614027cf5fb8263189b48f7e0bb9a23a552c15)
|
|
21
21
|
- Add Vec2.parallelTo [`989874d`](https://github.com/Immugio/three-math-extensions/commit/989874dcfe122d3ee84d8d56d79cb88e4e441736)
|
|
22
|
+
- Line2D.intersect - enable line segments intersection only [`1f1470e`](https://github.com/Immugio/three-math-extensions/commit/1f1470e1cf00118e643f5c44a135e0baf6b76d41)
|
|
22
23
|
- Polygon from bounding size [`eae6701`](https://github.com/Immugio/three-math-extensions/commit/eae67012f57f426f8b5259b765000447ce06d608)
|
|
23
24
|
- Line2D and Line3D to return this instead of specific type [`761ef6a`](https://github.com/Immugio/three-math-extensions/commit/761ef6a9d8cc4e35120b666576794e521aa3b991)
|
|
25
|
+
- Line2D.in3DSpace added [`a6ce0ec`](https://github.com/Immugio/three-math-extensions/commit/a6ce0ecb67f5c7b2a75fcc283c28af626153a4af)
|
|
24
26
|
- Line2D.hasIntersectionWithAngle to support optional tolerance [`b313bbe`](https://github.com/Immugio/three-math-extensions/commit/b313bbe118d435d53750deefd9a9e29ba6ec5c71)
|
|
25
27
|
- Line2D.hasIntersectionWithAngle - modulo all angles [`5409aa0`](https://github.com/Immugio/three-math-extensions/commit/5409aa0bc41510efa86d548e91837e44e5b6c343)
|
|
28
|
+
- Update release instructions [`5b41a2e`](https://github.com/Immugio/three-math-extensions/commit/5b41a2ed7e15450dbb6088a7f7ed0031a013badc)
|
|
26
29
|
- Add Polygon to exports [`ed66775`](https://github.com/Immugio/three-math-extensions/commit/ed66775c33e961835b23843222b822cfd9c16b1d)
|
|
27
30
|
- Vec2.fromPoint and Vec3.fromPoint should accept null [`4b871af`](https://github.com/Immugio/three-math-extensions/commit/4b871af297bdcbe8584f1e2b99d602247b77687c)
|
|
28
31
|
- Excluded files from build [`ec70614`](https://github.com/Immugio/three-math-extensions/commit/ec70614bc7df7a98f854c7a6693365118e04faf7)
|
|
29
32
|
|
|
30
|
-
## [16.15.10](https://github.com/Immugio/three-math-extensions/compare/0.2.
|
|
33
|
+
## [16.15.10](https://github.com/Immugio/three-math-extensions/compare/0.2.8...16.15.10) - 2023-01-02
|
|
34
|
+
|
|
35
|
+
## [0.2.8](https://github.com/Immugio/three-math-extensions/compare/0.2.7...0.2.8) - 2023-05-19
|
|
36
|
+
|
|
37
|
+
### Commits
|
|
38
|
+
|
|
39
|
+
- Line2D.in3DSpace added [`a6ce0ec`](https://github.com/Immugio/three-math-extensions/commit/a6ce0ecb67f5c7b2a75fcc283c28af626153a4af)
|
|
40
|
+
- Update release instructions [`5b41a2e`](https://github.com/Immugio/three-math-extensions/commit/5b41a2ed7e15450dbb6088a7f7ed0031a013badc)
|
|
41
|
+
|
|
42
|
+
## [0.2.7](https://github.com/Immugio/three-math-extensions/compare/0.2.6...0.2.7) - 2023-04-26
|
|
43
|
+
|
|
44
|
+
### Commits
|
|
45
|
+
|
|
46
|
+
- Add Vec2.fromPoints to accept multiple points [`a261402`](https://github.com/Immugio/three-math-extensions/commit/a2614027cf5fb8263189b48f7e0bb9a23a552c15)
|
|
47
|
+
- Add Vec2.parallelTo [`989874d`](https://github.com/Immugio/three-math-extensions/commit/989874dcfe122d3ee84d8d56d79cb88e4e441736)
|
|
48
|
+
- Line2D.hasIntersectionWithAngle to support optional tolerance [`b313bbe`](https://github.com/Immugio/three-math-extensions/commit/b313bbe118d435d53750deefd9a9e29ba6ec5c71)
|
|
49
|
+
- Line2D.hasIntersectionWithAngle - modulo all angles [`5409aa0`](https://github.com/Immugio/three-math-extensions/commit/5409aa0bc41510efa86d548e91837e44e5b6c343)
|
|
31
50
|
|
|
32
51
|
## [0.2.6](https://github.com/Immugio/three-math-extensions/compare/0.2.5...0.2.6) - 2023-04-14
|
|
33
52
|
|
package/cjs/Line2D.js
CHANGED
|
@@ -5,6 +5,7 @@ const three_1 = require("three");
|
|
|
5
5
|
const Vec2_1 = require("./Vec2");
|
|
6
6
|
const three_2 = require("three");
|
|
7
7
|
const MathConstants_1 = require("./MathConstants");
|
|
8
|
+
const Line3D_1 = require("./Line3D");
|
|
8
9
|
const _startP = /*@__PURE__*/ new Vec2_1.Vec2();
|
|
9
10
|
const _startEnd = /*@__PURE__*/ new Vec2_1.Vec2();
|
|
10
11
|
class Line2D {
|
|
@@ -513,9 +514,11 @@ class Line2D {
|
|
|
513
514
|
return this;
|
|
514
515
|
}
|
|
515
516
|
/**
|
|
516
|
-
* Returns the intersection point of two lines.
|
|
517
|
+
* Returns the intersection point of two lines.
|
|
518
|
+
* @param other
|
|
519
|
+
* @param lineSegmentOnly If true, only return the intersection if it is within the line segments. Otherwise, return the intersection if the lines intersect anywhere.
|
|
517
520
|
*/
|
|
518
|
-
intersect(other) {
|
|
521
|
+
intersect(other, lineSegmentOnly) {
|
|
519
522
|
// Check if none of the lines are of length 0
|
|
520
523
|
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)) {
|
|
521
524
|
return null;
|
|
@@ -526,6 +529,13 @@ class Line2D {
|
|
|
526
529
|
return null;
|
|
527
530
|
}
|
|
528
531
|
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;
|
|
532
|
+
// Check if the intersection point is within the bounds of the line segments if required
|
|
533
|
+
if (lineSegmentOnly) {
|
|
534
|
+
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;
|
|
535
|
+
if (ua < 0 || ua > 1 || ub < 0 || ub > 1) {
|
|
536
|
+
return null;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
529
539
|
// Return an object with the x and y coordinates of the intersection
|
|
530
540
|
const x = this.start.x + ua * (this.end.x - this.start.x);
|
|
531
541
|
const y = this.start.y + ua * (this.end.y - this.start.y);
|
|
@@ -552,6 +562,14 @@ class Line2D {
|
|
|
552
562
|
}
|
|
553
563
|
return null;
|
|
554
564
|
}
|
|
565
|
+
/**
|
|
566
|
+
* Project the line to 2D space. For start and end points Vec2.y becomes Vec3.z. and Vec3.y is provided as an argument.
|
|
567
|
+
* @param y - The y value of the new Vec3 instance.
|
|
568
|
+
* @returns A new Line3D instance.
|
|
569
|
+
*/
|
|
570
|
+
in3DSpace(y = 0) {
|
|
571
|
+
return new Line3D_1.Line3D(this.start.in3DSpace(y), this.end.in3DSpace(y));
|
|
572
|
+
}
|
|
555
573
|
equals(other) {
|
|
556
574
|
return !!other && this.start.equals(other.start) && this.end.equals(other.end);
|
|
557
575
|
}
|
package/esm/Line2D.js
CHANGED
|
@@ -2,6 +2,7 @@ import { Vector2 } from "three";
|
|
|
2
2
|
import { Vec2 } from "./Vec2";
|
|
3
3
|
import { MathUtils } from "three";
|
|
4
4
|
import { TwoPI } from "./MathConstants";
|
|
5
|
+
import { Line3D } from "./Line3D";
|
|
5
6
|
const _startP = /*@__PURE__*/ new Vec2();
|
|
6
7
|
const _startEnd = /*@__PURE__*/ new Vec2();
|
|
7
8
|
export class Line2D {
|
|
@@ -510,9 +511,11 @@ export class Line2D {
|
|
|
510
511
|
return this;
|
|
511
512
|
}
|
|
512
513
|
/**
|
|
513
|
-
* 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.
|
|
514
517
|
*/
|
|
515
|
-
intersect(other) {
|
|
518
|
+
intersect(other, lineSegmentOnly) {
|
|
516
519
|
// Check if none of the lines are of length 0
|
|
517
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)) {
|
|
518
521
|
return null;
|
|
@@ -523,6 +526,13 @@ export class Line2D {
|
|
|
523
526
|
return null;
|
|
524
527
|
}
|
|
525
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
|
+
}
|
|
526
536
|
// Return an object with the x and y coordinates of the intersection
|
|
527
537
|
const x = this.start.x + ua * (this.end.x - this.start.x);
|
|
528
538
|
const y = this.start.y + ua * (this.end.y - this.start.y);
|
|
@@ -549,6 +559,14 @@ export class Line2D {
|
|
|
549
559
|
}
|
|
550
560
|
return null;
|
|
551
561
|
}
|
|
562
|
+
/**
|
|
563
|
+
* Project the line to 2D space. For start and end points Vec2.y becomes Vec3.z. and Vec3.y is provided as an argument.
|
|
564
|
+
* @param y - The y value of the new Vec3 instance.
|
|
565
|
+
* @returns A new Line3D instance.
|
|
566
|
+
*/
|
|
567
|
+
in3DSpace(y = 0) {
|
|
568
|
+
return new Line3D(this.start.in3DSpace(y), this.end.in3DSpace(y));
|
|
569
|
+
}
|
|
552
570
|
equals(other) {
|
|
553
571
|
return !!other && this.start.equals(other.start) && this.end.equals(other.end);
|
|
554
572
|
}
|
package/package.json
CHANGED
package/src/Line2D.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Vector2 } from "three";
|
|
|
3
3
|
import { Vec2 } from "./Vec2";
|
|
4
4
|
import { MathUtils } from "three";
|
|
5
5
|
import { TwoPI } from "./MathConstants";
|
|
6
|
+
import { Line3D } from "./Line3D";
|
|
6
7
|
|
|
7
8
|
const _startP = /*@__PURE__*/ new Vec2();
|
|
8
9
|
const _startEnd = /*@__PURE__*/ new Vec2();
|
|
@@ -599,9 +600,11 @@ export class Line2D {
|
|
|
599
600
|
}
|
|
600
601
|
|
|
601
602
|
/**
|
|
602
|
-
* 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.
|
|
603
606
|
*/
|
|
604
|
-
public intersect(other: Line2D): Vec2 {
|
|
607
|
+
public intersect(other: Line2D, lineSegmentOnly?: boolean): Vec2 {
|
|
605
608
|
// Check if none of the lines are of length 0
|
|
606
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)) {
|
|
607
610
|
return null;
|
|
@@ -616,6 +619,14 @@ export class Line2D {
|
|
|
616
619
|
|
|
617
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;
|
|
618
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
|
+
|
|
619
630
|
// Return an object with the x and y coordinates of the intersection
|
|
620
631
|
const x = this.start.x + ua * (this.end.x - this.start.x);
|
|
621
632
|
const y = this.start.y + ua * (this.end.y - this.start.y);
|
|
@@ -649,6 +660,15 @@ export class Line2D {
|
|
|
649
660
|
return null;
|
|
650
661
|
}
|
|
651
662
|
|
|
663
|
+
/**
|
|
664
|
+
* Project the line to 2D space. For start and end points Vec2.y becomes Vec3.z. and Vec3.y is provided as an argument.
|
|
665
|
+
* @param y - The y value of the new Vec3 instance.
|
|
666
|
+
* @returns A new Line3D instance.
|
|
667
|
+
*/
|
|
668
|
+
public in3DSpace(y: number = 0): Line3D {
|
|
669
|
+
return new Line3D(this.start.in3DSpace(y), this.end.in3DSpace(y));
|
|
670
|
+
}
|
|
671
|
+
|
|
652
672
|
public equals(other: Line2D): boolean {
|
|
653
673
|
return !!other && this.start.equals(other.start) && this.end.equals(other.end);
|
|
654
674
|
}
|
package/types/Line2D.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Point2 } from "./Point2";
|
|
2
2
|
import { Vector2 } from "three";
|
|
3
3
|
import { Vec2 } from "./Vec2";
|
|
4
|
+
import { Line3D } from "./Line3D";
|
|
4
5
|
export declare class Line2D {
|
|
5
6
|
start: Vec2;
|
|
6
7
|
end: Vec2;
|
|
@@ -198,9 +199,11 @@ export declare class Line2D {
|
|
|
198
199
|
*/
|
|
199
200
|
extendToOrTrimAtIntersection(other: Line2D, maxDistanceToIntersection?: number): this;
|
|
200
201
|
/**
|
|
201
|
-
* 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.
|
|
202
205
|
*/
|
|
203
|
-
intersect(other: Line2D): Vec2;
|
|
206
|
+
intersect(other: Line2D, lineSegmentOnly?: boolean): Vec2;
|
|
204
207
|
/**
|
|
205
208
|
* Check that the line section intersect and that they are in the specified angle to each other
|
|
206
209
|
* @param other Line
|
|
@@ -209,6 +212,12 @@ export declare class Line2D {
|
|
|
209
212
|
* @param distanceTolerance number
|
|
210
213
|
*/
|
|
211
214
|
hasIntersectionWithAngle(other: Line2D, expectedAngleInRads: number, angleTolerance?: number, distanceTolerance?: number): Vec2;
|
|
215
|
+
/**
|
|
216
|
+
* Project the line to 2D space. For start and end points Vec2.y becomes Vec3.z. and Vec3.y is provided as an argument.
|
|
217
|
+
* @param y - The y value of the new Vec3 instance.
|
|
218
|
+
* @returns A new Line3D instance.
|
|
219
|
+
*/
|
|
220
|
+
in3DSpace(y?: number): Line3D;
|
|
212
221
|
equals(other: Line2D): boolean;
|
|
213
222
|
/**
|
|
214
223
|
* Deep clone of this line
|