@immugio/three-math-extensions 0.0.13 → 0.0.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/CHANGELOG.md +12 -1
- package/HowToRelease.txt +13 -0
- package/README.md +4 -7
- package/cjs/Vec2.js +5 -5
- package/cjs/Vec3.js +46 -7
- package/docs/README.md +5 -0
- package/docs/classes/Line2D.md +1092 -0
- package/docs/classes/Line3D.md +732 -0
- package/docs/classes/Vec2.md +167 -0
- package/docs/classes/Vec3.md +288 -0
- package/docs/modules.md +12 -0
- package/esm/Vec2.js +5 -5
- package/esm/Vec3.js +46 -7
- package/package.json +3 -1
- package/src/Vec2.ts +5 -5
- package/src/Vec3.ts +47 -8
- package/types/Vec2.d.ts +4 -4
- package/types/Vec3.d.ts +46 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,7 +7,18 @@ 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.0.
|
|
10
|
+
## [0.0.14](https://github.com/Immugio/three-math-extensions/compare/0.0.13...0.0.14)
|
|
11
|
+
|
|
12
|
+
### Commits
|
|
13
|
+
|
|
14
|
+
- Generate documentation using TSDoc [`304c3a8`](https://github.com/Immugio/three-math-extensions/commit/304c3a84b5dcc49183db57083f550d134ae641b2)
|
|
15
|
+
- Improve documentation for Vec2 and Vec3 [`6a2373d`](https://github.com/Immugio/three-math-extensions/commit/6a2373d8b6754a87720dcaea5d98336bfa7bc5b5)
|
|
16
|
+
- Clean up documentation [`70c8d5e`](https://github.com/Immugio/three-math-extensions/commit/70c8d5efe8b7095d7a03af637df3af5d46615293)
|
|
17
|
+
- Documentation improvements [`160db8b`](https://github.com/Immugio/three-math-extensions/commit/160db8ba6d6e5eb63a4e91ed9c40efd6fa70181a)
|
|
18
|
+
- Documentation improvements [`2f3e676`](https://github.com/Immugio/three-math-extensions/commit/2f3e6768b3b0139b60688fc151a4084f15566f8d)
|
|
19
|
+
- Revert npm ignore [`590b26a`](https://github.com/Immugio/three-math-extensions/commit/590b26a9e57fc41466b51e711f3f5c648e2d56ed)
|
|
20
|
+
|
|
21
|
+
## [0.0.13](https://github.com/Immugio/three-math-extensions/compare/0.0.12...0.0.13) - 2022-12-21
|
|
11
22
|
|
|
12
23
|
### Commits
|
|
13
24
|
|
package/HowToRelease.txt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Update documentation:
|
|
2
|
+
npx typedoc --plugin typedoc-plugin-markdown --out docs src/index.ts --excludeExternals --excludeProtected --excludePrivate --githubPages false
|
|
3
|
+
|
|
4
|
+
Before release
|
|
5
|
+
- Ensure clean working directory
|
|
6
|
+
- Ensure that the last release commit has a tag that matches the latest release number in the format "0.0.11". This step should have been completed in the previous release. It's only mentioned here in case it's for any reason missing.
|
|
7
|
+
- Run "prerelease" script to verify that the code builds and the tests pass
|
|
8
|
+
|
|
9
|
+
Release:
|
|
10
|
+
- Bump up version in package.json e.g. "0.0.11" -> "0.0.12"
|
|
11
|
+
- Run "version" script, it should add the new commits since the last release into `CHANGELOG.md`
|
|
12
|
+
- Commit and push the changes in `package.json` and `CHANGELOG.md`, ideally, call the commit as the new release e.g. "`0.0.12`". This is not necessary but makes it easier to find
|
|
13
|
+
- **Tag the commit** the new version number. In this example "`0.0.12`" and push. This is required for CI to build and publish to npm.
|
package/README.md
CHANGED
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/Immugio/three-math-extensions/actions/workflows/build.yml)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
- Run "version" script, it should add the new commits since the last release into `CHANGELOG.md`
|
|
10
|
-
- Commit and push the changes in `package.json` and `CHANGELOG.md`, ideally, call the commit as the new release e.g. "`0.0.12`". This is not necessary but makes it easier to find
|
|
11
|
-
- NOW THE CRITICAL PART - **tag the commit** with the new version number. In this example "`0.0.12`" and push. This is required for CI to build and release and publish to npm.
|
|
5
|
+
- [Line2D](docs/classes/Line2D.md)
|
|
6
|
+
- [Line3D](docs/classes/Line3D.md)
|
|
7
|
+
- [Vec2](docs/classes/Vec2.md)
|
|
8
|
+
- [Vec3](docs/classes/Vec3.md)
|
package/cjs/Vec2.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.Vec2 = void 0;
|
|
|
4
4
|
const three_1 = require("three");
|
|
5
5
|
const Vec3_1 = require("./Vec3");
|
|
6
6
|
/**
|
|
7
|
-
* Vec2 represents a 2D vector. It extends `Vector2` from the `
|
|
7
|
+
* Vec2 represents a 2D vector. It extends `Vector2` from the `threejs` library.
|
|
8
8
|
*/
|
|
9
9
|
class Vec2 extends three_1.Vector2 {
|
|
10
10
|
/**
|
|
@@ -41,12 +41,12 @@ class Vec2 extends three_1.Vector2 {
|
|
|
41
41
|
return this;
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
* Projects this Vec2 instance to a Vec3 instance in 3D space.
|
|
45
|
-
* @param
|
|
44
|
+
* Projects this Vec2 instance to a Vec3 instance in 3D space. Vec2.y becomes Vec3.z. and Vec3.y is provided as an argument.
|
|
45
|
+
* @param y - The y value of the new Vec3 instance.
|
|
46
46
|
* @returns A new Vec3 instance.
|
|
47
47
|
*/
|
|
48
|
-
in3DSpace(
|
|
49
|
-
return new Vec3_1.Vec3(this.x,
|
|
48
|
+
in3DSpace(y = 0) {
|
|
49
|
+
return new Vec3_1.Vec3(this.x, y, this.y);
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Determines if this Vec2 instance is near the target Vec2.
|
package/cjs/Vec3.js
CHANGED
|
@@ -3,11 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Vec3 = void 0;
|
|
4
4
|
const three_1 = require("three");
|
|
5
5
|
const Vec2_1 = require("./Vec2");
|
|
6
|
+
/**
|
|
7
|
+
* Vec3 represents a 2D vector. It extends `Vector3` from the `threejs` library.
|
|
8
|
+
*/
|
|
6
9
|
class Vec3 extends three_1.Vector3 {
|
|
7
10
|
#target;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new Vec3 instance from an {x, y, z} object.
|
|
13
|
+
* @param point - The {x, y, z} instance.
|
|
14
|
+
* @returns A new Vec3 instance.
|
|
15
|
+
*/
|
|
8
16
|
static fromPoint(point) {
|
|
9
17
|
return new Vec3(point.x, point.y, point.z);
|
|
10
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Moves this Vec3 instance towards the target Vec3 by the given amount.
|
|
21
|
+
* @param target - The target Vec3.
|
|
22
|
+
* @param amount - The distance to move.
|
|
23
|
+
* @returns This Vec3 instance.
|
|
24
|
+
*/
|
|
11
25
|
moveTowards(target, amount) {
|
|
12
26
|
if (this.#target === undefined) {
|
|
13
27
|
this.#target = new three_1.Vector3();
|
|
@@ -16,40 +30,65 @@ class Vec3 extends three_1.Vector3 {
|
|
|
16
30
|
this.add(this.#target.sub(this).normalize().multiplyScalar(amount));
|
|
17
31
|
return this;
|
|
18
32
|
}
|
|
19
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Moves this Vec3 instance halfway towards the target Vec3 by the given amount.
|
|
35
|
+
* @param target - The target Vec3.
|
|
36
|
+
* @returns This Vec3 instance.
|
|
37
|
+
*/
|
|
38
|
+
moveHalfWayTowards(target) {
|
|
20
39
|
if (this.#target === undefined) {
|
|
21
40
|
this.#target = new three_1.Vector3();
|
|
22
41
|
}
|
|
23
42
|
return this.moveTowards(target, this.distanceTo(target) / 2);
|
|
24
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Adds y amount to this Vec3 instance and return this
|
|
46
|
+
* @param y
|
|
47
|
+
*/
|
|
25
48
|
addY(y) {
|
|
26
49
|
this.y += y;
|
|
27
50
|
return this;
|
|
28
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Adds x amount to this Vec3 instance and return this
|
|
54
|
+
* @param x
|
|
55
|
+
*/
|
|
29
56
|
addX(x) {
|
|
30
57
|
this.x += x;
|
|
31
58
|
return this;
|
|
32
59
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
60
|
+
/**
|
|
61
|
+
* Returns a clone of the point closest to this from the given points.
|
|
62
|
+
* @param points
|
|
63
|
+
*/
|
|
39
64
|
closest(...points) {
|
|
40
65
|
const withDistances = points.map(p => ({ point: p, distance: this.distanceTo(p) }));
|
|
41
66
|
const closest = withDistances.reduce((a, b) => a.distance < b.distance ? a : b);
|
|
42
67
|
return Vec3.fromPoint(closest.point);
|
|
43
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Returns a clone of this Vec3 instance with y and z swapped.
|
|
71
|
+
*/
|
|
44
72
|
toPointWithFlippedYZ() {
|
|
45
73
|
return new Vec3(this.x, this.z, this.y);
|
|
46
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Projects this Vec3 instance onto 2d plan. Vec3.z becomes Vec2.y and Vec3.y is ignored.
|
|
77
|
+
*/
|
|
47
78
|
onPlan() {
|
|
48
79
|
return new Vec2_1.Vec2(this.x, this.z);
|
|
49
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Get distance to another vector while ignoring the y-axis.
|
|
83
|
+
* @param point
|
|
84
|
+
*/
|
|
50
85
|
horizontalDistanceTo(point) {
|
|
51
86
|
return new three_1.Vector3(this.x, 0, this.z).distanceTo(new three_1.Vector3(point.x, 0, point.z));
|
|
52
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Determines if this Vec2 instance is near the target Vec2.
|
|
90
|
+
* maxDistance is the maximum distance between the two vectors within which they are considered `near`.
|
|
91
|
+
*/
|
|
53
92
|
isNear(v, maxDistance = undefined) {
|
|
54
93
|
if (maxDistance === undefined) {
|
|
55
94
|
return this.equals(v);
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
@immugio/three-math-extensions / [Exports](modules.md)
|
|
2
|
+
|
|
3
|
+
# Set of utilities for 2d and 3d line math built on top of three.js
|
|
4
|
+
|
|
5
|
+
[](https://github.com/Immugio/three-math-extensions/actions/workflows/build.yml)
|