@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/CHANGELOG.md +13 -1
- package/README.md +11 -3
- package/cjs/Line2D.js +566 -566
- package/cjs/Line3D.js +392 -392
- package/cjs/Point2.js +2 -2
- package/cjs/Point3.js +2 -2
- package/cjs/Vec2.js +62 -34
- package/cjs/Vec3.js +63 -63
- package/cjs/index.js +11 -11
- package/esm/Line2D.js +562 -562
- package/esm/Line3D.js +388 -388
- package/esm/Point2.js +1 -1
- package/esm/Point3.js +1 -1
- package/esm/Vec2.js +58 -30
- package/esm/Vec3.js +59 -59
- package/esm/index.js +4 -4
- package/package.json +52 -52
- package/src/Line2D.ts +660 -660
- package/src/Line3D.ts +470 -470
- package/src/Point2.ts +3 -3
- package/src/Point3.ts +6 -6
- package/src/Vec2.ts +65 -37
- package/src/Vec3.ts +77 -77
- package/src/index.ts +3 -3
- package/types/Line2D.d.ts +222 -222
- package/types/Line3D.d.ts +151 -151
- package/types/Point2.d.ts +4 -4
- package/types/Point3.d.ts +5 -5
- package/types/Vec2.d.ts +38 -10
- package/types/Vec3.d.ts +18 -18
- package/types/index.d.ts +4 -4
package/cjs/Point2.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/cjs/Point3.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/cjs/Vec2.js
CHANGED
|
@@ -1,34 +1,62 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Vec2 = void 0;
|
|
4
|
-
const three_1 = require("three");
|
|
5
|
-
const Vec3_1 = require("./Vec3");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Vec2 = void 0;
|
|
4
|
+
const three_1 = require("three");
|
|
5
|
+
const Vec3_1 = require("./Vec3");
|
|
6
|
+
/**
|
|
7
|
+
* Vec2 represents a 2D vector. It extends `Vector2` from the `three` library.
|
|
8
|
+
*/
|
|
9
|
+
class Vec2 extends three_1.Vector2 {
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new Vec2 instance from an {x, y} object.
|
|
12
|
+
* @param point - The {x, y} instance.
|
|
13
|
+
* @returns A new Vec2 instance.
|
|
14
|
+
*/
|
|
15
|
+
static fromPoint(point) {
|
|
16
|
+
return new Vec2(point.x, point.y);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Moves this Vec2 instance towards the target Vec2 by the given amount.
|
|
20
|
+
* @param target - The target Vec2.
|
|
21
|
+
* @param amount - The distance to move.
|
|
22
|
+
* @returns This Vec2 instance.
|
|
23
|
+
*/
|
|
24
|
+
moveTowards(target, amount) {
|
|
25
|
+
const move = target.clone().sub(this).normalize().multiplyScalar(amount);
|
|
26
|
+
this.add(move);
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Rounds the x and y values of this Vec2 instance if they are close to an integer value.
|
|
31
|
+
* @param max - The maximum difference between the value and the nearest integer.
|
|
32
|
+
* @returns This Vec2 instance.
|
|
33
|
+
*/
|
|
34
|
+
roundIfCloseToInteger(max = 0.000000000001) {
|
|
35
|
+
if (Math.abs(this.x - Math.round(this.x)) < max) {
|
|
36
|
+
this.x = Math.round(this.x);
|
|
37
|
+
}
|
|
38
|
+
if (Math.abs(this.y - Math.round(this.y)) < max) {
|
|
39
|
+
this.y = Math.round(this.y);
|
|
40
|
+
}
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Projects this Vec2 instance to a Vec3 instance in 3D space.
|
|
45
|
+
* @param z - The z value of the new Vec3 instance.
|
|
46
|
+
* @returns A new Vec3 instance.
|
|
47
|
+
*/
|
|
48
|
+
in3DSpace(z = 0) {
|
|
49
|
+
return new Vec3_1.Vec3(this.x, z, this.y);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Determines if this Vec2 instance is near the target Vec2.
|
|
53
|
+
* maxDistance is the maximum distance between the two vectors within which they are considered `near`.
|
|
54
|
+
*/
|
|
55
|
+
isNear(v, maxDistance = undefined) {
|
|
56
|
+
if (!maxDistance) {
|
|
57
|
+
return this.equals(v);
|
|
58
|
+
}
|
|
59
|
+
return this.distanceTo(v) <= maxDistance;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.Vec2 = Vec2;
|
package/cjs/Vec3.js
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Vec3 = void 0;
|
|
4
|
-
const three_1 = require("three");
|
|
5
|
-
const Vec2_1 = require("./Vec2");
|
|
6
|
-
class Vec3 extends three_1.Vector3 {
|
|
7
|
-
#target;
|
|
8
|
-
static fromPoint(point) {
|
|
9
|
-
return new Vec3(point.x, point.y, point.z);
|
|
10
|
-
}
|
|
11
|
-
moveTowards(target, amount) {
|
|
12
|
-
if (this.#target === undefined) {
|
|
13
|
-
this.#target = new three_1.Vector3();
|
|
14
|
-
}
|
|
15
|
-
this.#target.copy(target);
|
|
16
|
-
this.add(this.#target.sub(this).normalize().multiplyScalar(amount));
|
|
17
|
-
return this;
|
|
18
|
-
}
|
|
19
|
-
centerTowards(target) {
|
|
20
|
-
if (this.#target === undefined) {
|
|
21
|
-
this.#target = new three_1.Vector3();
|
|
22
|
-
}
|
|
23
|
-
return this.moveTowards(target, this.distanceTo(target) / 2);
|
|
24
|
-
}
|
|
25
|
-
addY(y) {
|
|
26
|
-
this.y += y;
|
|
27
|
-
return this;
|
|
28
|
-
}
|
|
29
|
-
addX(x) {
|
|
30
|
-
this.x += x;
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
scale(p) {
|
|
34
|
-
this.x *= p.x;
|
|
35
|
-
this.y *= p.y;
|
|
36
|
-
this.z *= p.z;
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
closest(...points) {
|
|
40
|
-
const withDistances = points.map(p => ({ point: p, distance: this.distanceTo(p) }));
|
|
41
|
-
const closest = withDistances.reduce((a, b) => a.distance < b.distance ? a : b);
|
|
42
|
-
return Vec3.fromPoint(closest.point);
|
|
43
|
-
}
|
|
44
|
-
toPointWithFlippedYZ() {
|
|
45
|
-
return new Vec3(this.x, this.z, this.y);
|
|
46
|
-
}
|
|
47
|
-
onPlan() {
|
|
48
|
-
return new Vec2_1.Vec2(this.x, this.z);
|
|
49
|
-
}
|
|
50
|
-
horizontalDistanceTo(point) {
|
|
51
|
-
return new three_1.Vector3(this.x, 0, this.z).distanceTo(new three_1.Vector3(point.x, 0, point.z));
|
|
52
|
-
}
|
|
53
|
-
isNear(v, maxDistance = undefined) {
|
|
54
|
-
if (maxDistance === undefined) {
|
|
55
|
-
return this.equals(v);
|
|
56
|
-
}
|
|
57
|
-
return this.distanceTo(v) <= maxDistance;
|
|
58
|
-
}
|
|
59
|
-
clone() {
|
|
60
|
-
return super.clone();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.Vec3 = Vec3;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Vec3 = void 0;
|
|
4
|
+
const three_1 = require("three");
|
|
5
|
+
const Vec2_1 = require("./Vec2");
|
|
6
|
+
class Vec3 extends three_1.Vector3 {
|
|
7
|
+
#target;
|
|
8
|
+
static fromPoint(point) {
|
|
9
|
+
return new Vec3(point.x, point.y, point.z);
|
|
10
|
+
}
|
|
11
|
+
moveTowards(target, amount) {
|
|
12
|
+
if (this.#target === undefined) {
|
|
13
|
+
this.#target = new three_1.Vector3();
|
|
14
|
+
}
|
|
15
|
+
this.#target.copy(target);
|
|
16
|
+
this.add(this.#target.sub(this).normalize().multiplyScalar(amount));
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
centerTowards(target) {
|
|
20
|
+
if (this.#target === undefined) {
|
|
21
|
+
this.#target = new three_1.Vector3();
|
|
22
|
+
}
|
|
23
|
+
return this.moveTowards(target, this.distanceTo(target) / 2);
|
|
24
|
+
}
|
|
25
|
+
addY(y) {
|
|
26
|
+
this.y += y;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
addX(x) {
|
|
30
|
+
this.x += x;
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
scale(p) {
|
|
34
|
+
this.x *= p.x;
|
|
35
|
+
this.y *= p.y;
|
|
36
|
+
this.z *= p.z;
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
closest(...points) {
|
|
40
|
+
const withDistances = points.map(p => ({ point: p, distance: this.distanceTo(p) }));
|
|
41
|
+
const closest = withDistances.reduce((a, b) => a.distance < b.distance ? a : b);
|
|
42
|
+
return Vec3.fromPoint(closest.point);
|
|
43
|
+
}
|
|
44
|
+
toPointWithFlippedYZ() {
|
|
45
|
+
return new Vec3(this.x, this.z, this.y);
|
|
46
|
+
}
|
|
47
|
+
onPlan() {
|
|
48
|
+
return new Vec2_1.Vec2(this.x, this.z);
|
|
49
|
+
}
|
|
50
|
+
horizontalDistanceTo(point) {
|
|
51
|
+
return new three_1.Vector3(this.x, 0, this.z).distanceTo(new three_1.Vector3(point.x, 0, point.z));
|
|
52
|
+
}
|
|
53
|
+
isNear(v, maxDistance = undefined) {
|
|
54
|
+
if (maxDistance === undefined) {
|
|
55
|
+
return this.equals(v);
|
|
56
|
+
}
|
|
57
|
+
return this.distanceTo(v) <= maxDistance;
|
|
58
|
+
}
|
|
59
|
+
clone() {
|
|
60
|
+
return super.clone();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.Vec3 = Vec3;
|
package/cjs/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Line3D = exports.Line2D = exports.Vec3 = exports.Vec2 = void 0;
|
|
4
|
-
var Vec2_1 = require("./Vec2");
|
|
5
|
-
Object.defineProperty(exports, "Vec2", { enumerable: true, get: function () { return Vec2_1.Vec2; } });
|
|
6
|
-
var Vec3_1 = require("./Vec3");
|
|
7
|
-
Object.defineProperty(exports, "Vec3", { enumerable: true, get: function () { return Vec3_1.Vec3; } });
|
|
8
|
-
var Line2D_1 = require("./Line2D");
|
|
9
|
-
Object.defineProperty(exports, "Line2D", { enumerable: true, get: function () { return Line2D_1.Line2D; } });
|
|
10
|
-
var Line3D_1 = require("./Line3D");
|
|
11
|
-
Object.defineProperty(exports, "Line3D", { enumerable: true, get: function () { return Line3D_1.Line3D; } });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Line3D = exports.Line2D = exports.Vec3 = exports.Vec2 = void 0;
|
|
4
|
+
var Vec2_1 = require("./Vec2");
|
|
5
|
+
Object.defineProperty(exports, "Vec2", { enumerable: true, get: function () { return Vec2_1.Vec2; } });
|
|
6
|
+
var Vec3_1 = require("./Vec3");
|
|
7
|
+
Object.defineProperty(exports, "Vec3", { enumerable: true, get: function () { return Vec3_1.Vec3; } });
|
|
8
|
+
var Line2D_1 = require("./Line2D");
|
|
9
|
+
Object.defineProperty(exports, "Line2D", { enumerable: true, get: function () { return Line2D_1.Line2D; } });
|
|
10
|
+
var Line3D_1 = require("./Line3D");
|
|
11
|
+
Object.defineProperty(exports, "Line3D", { enumerable: true, get: function () { return Line3D_1.Line3D; } });
|