@immugio/three-math-extensions 0.2.5 → 0.2.6

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 CHANGED
@@ -7,11 +7,13 @@ 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.5](https://github.com/Immugio/three-math-extensions/compare/16.15.10...0.2.5)
10
+ ## [0.2.6](https://github.com/Immugio/three-math-extensions/compare/16.15.10...0.2.6)
11
11
 
12
12
  ### Commits
13
13
 
14
14
  - Add Rectangle, update Polygon [`58ee875`](https://github.com/Immugio/three-math-extensions/commit/58ee87539af8f9ade186e5250cba9e01926da514)
15
+ - Improve Line2D.closestPointToPoint, add Vec2.signedAngle [`151f214`](https://github.com/Immugio/three-math-extensions/commit/151f21462e0358057ad8e9d75d5782563a1061f6)
16
+ - Improve documentation [`d0fcb51`](https://github.com/Immugio/three-math-extensions/commit/d0fcb5132f127b4382ac5f7291575a061b8ec121)
15
17
  - Vec3, Line3D - update documentation [`67d9c32`](https://github.com/Immugio/three-math-extensions/commit/67d9c328e08cc0a5599932d2f0529e97f31c9213)
16
18
  - Add Polygon [`629cff8`](https://github.com/Immugio/three-math-extensions/commit/629cff8ecbb963477e8ea76d7f8b16d95435cbad)
17
19
  - Add Vec2.signedAngle [`863c8f2`](https://github.com/Immugio/three-math-extensions/commit/863c8f27f11288cbda535e21bb688206259269ed)
@@ -19,8 +21,11 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
19
21
  - Line2D and Line3D to return this instead of specific type [`761ef6a`](https://github.com/Immugio/three-math-extensions/commit/761ef6a9d8cc4e35120b666576794e521aa3b991)
20
22
  - Add Polygon to exports [`ed66775`](https://github.com/Immugio/three-math-extensions/commit/ed66775c33e961835b23843222b822cfd9c16b1d)
21
23
  - Vec2.fromPoint and Vec3.fromPoint should accept null [`4b871af`](https://github.com/Immugio/three-math-extensions/commit/4b871af297bdcbe8584f1e2b99d602247b77687c)
24
+ - Excluded files from build [`ec70614`](https://github.com/Immugio/three-math-extensions/commit/ec70614bc7df7a98f854c7a6693365118e04faf7)
22
25
 
23
- ## [16.15.10](https://github.com/Immugio/three-math-extensions/compare/0.2.4...16.15.10) - 2023-01-02
26
+ ## [16.15.10](https://github.com/Immugio/three-math-extensions/compare/0.2.5...16.15.10) - 2023-01-02
27
+
28
+ ## [0.2.5](https://github.com/Immugio/three-math-extensions/compare/0.2.4...0.2.5) - 2023-04-11
24
29
 
25
30
  ## [0.2.4](https://github.com/Immugio/three-math-extensions/compare/0.2.3...0.2.4) - 2023-04-11
26
31
 
@@ -132,19 +137,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
132
137
 
133
138
  - Release 0.0.4 - tag pattern 4 [`ab9ad4e`](https://github.com/Immugio/three-math-extensions/commit/ab9ad4e49477a991482ed6d4d3a3ca4687a70b44)
134
139
 
135
- ## [0.0.7](https://github.com/Immugio/three-math-extensions/compare/0.0.6...0.0.7) - 2022-11-21
136
-
137
- ## [0.0.6](https://github.com/Immugio/three-math-extensions/compare/0.0.4...0.0.6) - 2022-11-24
138
-
139
- ### Commits
140
-
141
- - Improve API, minor bug fix, improve test coverage [`881a5f0`](https://github.com/Immugio/three-math-extensions/commit/881a5f096823f0d5fd90faa76cd602f076291bc5)
142
- - Add .npmignore [`f58329a`](https://github.com/Immugio/three-math-extensions/commit/f58329a86b96589bb574d6ebed37d4cc4474663a)
143
- - Correct change log version [`c6244bf`](https://github.com/Immugio/three-math-extensions/commit/c6244bf1488ad21bcc5589d1dff62c41d8182d48)
144
- - Release 0.0.4 - tag pattern 6 [`c1c5454`](https://github.com/Immugio/three-math-extensions/commit/c1c54541ed400e1ad49bf42fe8926cd5293efefd)
145
- - Release 0.0.4 - tag pattern 5 [`5245eed`](https://github.com/Immugio/three-math-extensions/commit/5245eed60195103e989c0fadf9bd642f39ef4589)
146
-
147
- ## 0.0.4 - 2022-11-21
140
+ ## 0.0.7 - 2022-11-21
148
141
 
149
142
  ### Commits
150
143
 
@@ -161,7 +154,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
161
154
  - Edit publish script condition [`dc77d89`](https://github.com/Immugio/three-math-extensions/commit/dc77d8978d87daab8732d6429ad1b01ba0ca6f97)
162
155
  - CI to use node version 16 [`dc42650`](https://github.com/Immugio/three-math-extensions/commit/dc426508939de922cc0316b7652bbd09aeed4610)
163
156
  - Action rename [`26a1f01`](https://github.com/Immugio/three-math-extensions/commit/26a1f014827faab2c02d30ca8ed18dac8f9ff8af)
164
- - Release 0.0.4 - tag pattern 4 [`ab9ad4e`](https://github.com/Immugio/three-math-extensions/commit/ab9ad4e49477a991482ed6d4d3a3ca4687a70b44)
165
157
  - Release 0.0.4 - tag pattern 3 [`d7d4c8f`](https://github.com/Immugio/three-math-extensions/commit/d7d4c8f546e6550868ddd06a5213fdec6c68bcd2)
166
158
  - Release 0.0.4 - tag pattern 2 [`0dcf801`](https://github.com/Immugio/three-math-extensions/commit/0dcf80190bd67a3ca93d45131a403201ab39e00f)
167
159
  - Release 0.0.4 - tag pattern [`e7f2f76`](https://github.com/Immugio/three-math-extensions/commit/e7f2f76aa247e1c51f0522c300a7aaf07253039c)
package/README.md CHANGED
@@ -1,8 +1,88 @@
1
- # Set of utilities for 2d and 3d line math built on top of three.js
1
+ # Set of utilities for 2d and 3d math built on top of three.js
2
2
 
3
3
  [![Build](https://github.com/Immugio/three-math-extensions/actions/workflows/build.yml/badge.svg)](https://github.com/Immugio/three-math-extensions/actions/workflows/build.yml)
4
4
 
5
+ [@immugio/three-math-extensions](README.md) / Exports
6
+
7
+ # @immugio/three-math-extensions
8
+
9
+ ## Table of contents
10
+
11
+ ### Classes
12
+
13
+ - [BoundingBox](docs/classes/BoundingBox.md)
5
14
  - [Line2D](docs/classes/Line2D.md)
6
15
  - [Line3D](docs/classes/Line3D.md)
16
+ - [Polygon](docs/classes/Polygon.md)
17
+ - [Rectangle](docs/classes/Rectangle.md)
18
+ - [Size2](docs/classes/Size2.md)
7
19
  - [Vec2](docs/classes/Vec2.md)
8
- - [Vec3](docs/classes/Vec3.md)
20
+ - [Vec3](docs/classes/Vec3.md)
21
+
22
+ ### Interfaces
23
+
24
+ - [Point2](docs/interfaces/Point2.md)
25
+ - [Point3](docs/interfaces/Point3.md)
26
+
27
+ ### Variables
28
+
29
+ - [TwoPI](docs/modules.md#twopi)
30
+
31
+ ### Functions
32
+
33
+ - [normalizeAngleDegrees](docs/modules.md#normalizeangledegrees)
34
+ - [normalizeAngleRadians](docs/modules.md#normalizeangleradians)
35
+
36
+ ## Variables
37
+
38
+ ### TwoPI
39
+
40
+ • `Const` **TwoPI**: `number`
41
+
42
+ #### Defined in
43
+
44
+ [src/MathConstants.ts:1](https://github.com/Immugio/three-math-extensions/blob/151f214/src/MathConstants.ts#L1)
45
+
46
+ ## Functions
47
+
48
+ ### normalizeAngleDegrees
49
+
50
+ ▸ **normalizeAngleDegrees**(`angle`): `number`
51
+
52
+ Normalizes an angle in degrees to the range [0, 360].
53
+
54
+ #### Parameters
55
+
56
+ | Name | Type | Description |
57
+ | :------ | :------ | :------ |
58
+ | `angle` | `number` | in degrees |
59
+
60
+ #### Returns
61
+
62
+ `number`
63
+
64
+ #### Defined in
65
+
66
+ [src/normalizeAngleDegrees.ts:5](https://github.com/Immugio/three-math-extensions/blob/151f214/src/normalizeAngleDegrees.ts#L5)
67
+
68
+ ___
69
+
70
+ ### normalizeAngleRadians
71
+
72
+ ▸ **normalizeAngleRadians**(`angle`): `number`
73
+
74
+ Normalize an angle in radians to the range of 0 to 2π.
75
+
76
+ #### Parameters
77
+
78
+ | Name | Type | Description |
79
+ | :------ | :------ | :------ |
80
+ | `angle` | `number` | in radians |
81
+
82
+ #### Returns
83
+
84
+ `number`
85
+
86
+ #### Defined in
87
+
88
+ [src/normalizeAngleRadians.ts:7](https://github.com/Immugio/three-math-extensions/blob/151f214/src/normalizeAngleRadians.ts#L7)
package/cjs/Line2D.js CHANGED
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Line2D = void 0;
4
4
  const three_1 = require("three");
5
5
  const Vec2_1 = require("./Vec2");
6
+ const three_2 = require("three");
7
+ const _startP = /*@__PURE__*/ new Vec2_1.Vec2();
8
+ const _startEnd = /*@__PURE__*/ new Vec2_1.Vec2();
6
9
  class Line2D {
7
10
  start;
8
11
  end;
@@ -329,34 +332,28 @@ class Line2D {
329
332
  return result;
330
333
  }
331
334
  /**
332
- * Returns the closest point parameter on the **infinite** line to the given point.
335
+ * Returns the closest point on the line to the given point.
333
336
  * @param point
337
+ * @param clampToLine boolean (optional)
338
+ * @param target Vec2 (optional)
334
339
  */
335
- closestPointToPointParameterOnInfiniteLine(point) {
336
- const startP = new Vec2_1.Vec2().subVectors(point, this.start);
337
- const startEnd = new Vec2_1.Vec2().subVectors(this.end, this.start);
338
- const startEnd2 = startEnd.dot(startEnd);
339
- const startEnd_startP = startEnd.dot(startP);
340
- return startEnd_startP / startEnd2;
340
+ closestPointToPoint(point, clampToLine, target) {
341
+ const t = this.closestPointToPointParameter(point, clampToLine);
342
+ return this.delta(target || new Vec2_1.Vec2()).multiplyScalar(t).add(this.start);
341
343
  }
342
- /**
343
- * Returns the closest point on the **infinite** line to the given point.
344
- * @param point
345
- */
346
- closestPointOnInfiniteLine(point) {
347
- const t = this.closestPointToPointParameterOnInfiniteLine(point);
348
- return new Vec2_1.Vec2().subVectors(this.end, this.start).multiplyScalar(t).add(this.start);
344
+ delta(target) {
345
+ return target.subVectors(this.end, this.start);
349
346
  }
350
- /**
351
- * Returns the closest point on the line **section** to the given point.
352
- * @param point
353
- */
354
- closestPointOnLine(point) {
355
- const closestPoint = this.closestPointOnInfiniteLine(point);
356
- if (this.isPointOnLineSection(closestPoint)) {
357
- return closestPoint;
347
+ closestPointToPointParameter(point, clampToLine) {
348
+ _startP.subVectors(point, this.start);
349
+ _startEnd.subVectors(this.end, this.start);
350
+ const startEnd2 = _startEnd.dot(_startEnd);
351
+ const startEnd_startP = _startEnd.dot(_startP);
352
+ let t = startEnd_startP / startEnd2;
353
+ if (clampToLine) {
354
+ t = three_2.MathUtils.clamp(t, 0, 1);
358
355
  }
359
- return closestPoint.distanceTo(this.start) < closestPoint.distanceTo(this.end) ? this.start : this.end;
356
+ return t;
360
357
  }
361
358
  /**
362
359
  * Returns the distance between the **infinite** line and the point.
@@ -466,11 +463,11 @@ class Line2D {
466
463
  return;
467
464
  }
468
465
  if (!this.isPointOnLineSection(lineToTrim.start)) {
469
- const closest = this.closestPointOnLine(lineToTrim.start);
466
+ const closest = this.closestPointToPoint(lineToTrim.start, true);
470
467
  lineToTrim.start.copy(closest);
471
468
  }
472
469
  if (!this.isPointOnLineSection(lineToTrim.end)) {
473
- const closest = this.closestPointOnLine(lineToTrim.end);
470
+ const closest = this.closestPointToPoint(lineToTrim.end, true);
474
471
  lineToTrim.end.copy(closest);
475
472
  }
476
473
  }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TwoPI = void 0;
4
+ exports.TwoPI = 2 * Math.PI;
package/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeAngleRadians = exports.normalizeAngleDegrees = exports.Rectangle = exports.BoundingBox = exports.Polygon = exports.Size2 = exports.Line3D = exports.Line2D = exports.Vec3 = exports.Vec2 = void 0;
3
+ exports.TwoPI = exports.normalizeAngleRadians = exports.normalizeAngleDegrees = exports.Rectangle = exports.BoundingBox = exports.Polygon = exports.Size2 = exports.Line3D = exports.Line2D = exports.Vec3 = exports.Vec2 = void 0;
4
4
  var Vec2_1 = require("./Vec2");
5
5
  Object.defineProperty(exports, "Vec2", { enumerable: true, get: function () { return Vec2_1.Vec2; } });
6
6
  var Vec3_1 = require("./Vec3");
@@ -21,3 +21,5 @@ var normalizeAngleDegrees_1 = require("./normalizeAngleDegrees");
21
21
  Object.defineProperty(exports, "normalizeAngleDegrees", { enumerable: true, get: function () { return normalizeAngleDegrees_1.normalizeAngleDegrees; } });
22
22
  var normalizeAngleRadians_1 = require("./normalizeAngleRadians");
23
23
  Object.defineProperty(exports, "normalizeAngleRadians", { enumerable: true, get: function () { return normalizeAngleRadians_1.normalizeAngleRadians; } });
24
+ var MathConstants_1 = require("./MathConstants");
25
+ Object.defineProperty(exports, "TwoPI", { enumerable: true, get: function () { return MathConstants_1.TwoPI; } });
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeAngleDegrees = void 0;
4
+ /**
5
+ * Normalizes an angle in degrees to the range [0, 360].
6
+ * @param angle in degrees
7
+ */
4
8
  function normalizeAngleDegrees(angle) {
5
9
  return ((angle % 360) + 360) % 360;
6
10
  }
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeAngleRadians = void 0;
4
+ const MathConstants_1 = require("./MathConstants");
5
+ /**
6
+ * Normalize an angle in radians to the range of 0 to 2π.
7
+ * @param angle in radians
8
+ */
4
9
  function normalizeAngleRadians(angle) {
5
- const twoPi = 2 * Math.PI;
6
- angle = angle % twoPi; // Use modulus to get the angle within the range of 0 to 2π
10
+ angle = angle % MathConstants_1.TwoPI; // Use modulus to get the angle within the range of 0 to 2π
7
11
  if (angle < 0) { // Add 2π if the angle is negative
8
- angle = angle + twoPi;
12
+ angle = angle + MathConstants_1.TwoPI;
9
13
  }
10
14
  return angle;
11
15
  }
@@ -40,7 +40,7 @@
40
40
 
41
41
  #### Defined in
42
42
 
43
- [src/BoundingBox.ts:4](https://github.com/Immugio/three-math-extensions/blob/c004965/src/BoundingBox.ts#L4)
43
+ [src/BoundingBox.ts:4](https://github.com/Immugio/three-math-extensions/blob/151f214/src/BoundingBox.ts#L4)
44
44
 
45
45
  ## Properties
46
46
 
@@ -50,7 +50,7 @@
50
50
 
51
51
  #### Defined in
52
52
 
53
- [src/BoundingBox.ts:4](https://github.com/Immugio/three-math-extensions/blob/c004965/src/BoundingBox.ts#L4)
53
+ [src/BoundingBox.ts:4](https://github.com/Immugio/three-math-extensions/blob/151f214/src/BoundingBox.ts#L4)
54
54
 
55
55
  ___
56
56
 
@@ -60,7 +60,7 @@ ___
60
60
 
61
61
  #### Defined in
62
62
 
63
- [src/BoundingBox.ts:4](https://github.com/Immugio/three-math-extensions/blob/c004965/src/BoundingBox.ts#L4)
63
+ [src/BoundingBox.ts:4](https://github.com/Immugio/three-math-extensions/blob/151f214/src/BoundingBox.ts#L4)
64
64
 
65
65
  ___
66
66
 
@@ -70,7 +70,7 @@ ___
70
70
 
71
71
  #### Defined in
72
72
 
73
- [src/BoundingBox.ts:4](https://github.com/Immugio/three-math-extensions/blob/c004965/src/BoundingBox.ts#L4)
73
+ [src/BoundingBox.ts:4](https://github.com/Immugio/three-math-extensions/blob/151f214/src/BoundingBox.ts#L4)
74
74
 
75
75
  ___
76
76
 
@@ -80,7 +80,7 @@ ___
80
80
 
81
81
  #### Defined in
82
82
 
83
- [src/BoundingBox.ts:4](https://github.com/Immugio/three-math-extensions/blob/c004965/src/BoundingBox.ts#L4)
83
+ [src/BoundingBox.ts:4](https://github.com/Immugio/three-math-extensions/blob/151f214/src/BoundingBox.ts#L4)
84
84
 
85
85
  ## Accessors
86
86
 
@@ -94,7 +94,7 @@ ___
94
94
 
95
95
  #### Defined in
96
96
 
97
- [src/BoundingBox.ts:11](https://github.com/Immugio/three-math-extensions/blob/c004965/src/BoundingBox.ts#L11)
97
+ [src/BoundingBox.ts:11](https://github.com/Immugio/three-math-extensions/blob/151f214/src/BoundingBox.ts#L11)
98
98
 
99
99
  ## Methods
100
100
 
@@ -114,4 +114,4 @@ ___
114
114
 
115
115
  #### Defined in
116
116
 
117
- [src/BoundingBox.ts:7](https://github.com/Immugio/three-math-extensions/blob/c004965/src/BoundingBox.ts#L7)
117
+ [src/BoundingBox.ts:7](https://github.com/Immugio/three-math-extensions/blob/151f214/src/BoundingBox.ts#L7)