@immugio/three-math-extensions 0.2.2 → 0.2.5

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,19 +7,34 @@ 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.2](https://github.com/Immugio/three-math-extensions/compare/16.15.10...0.2.2)
10
+ ## [0.2.5](https://github.com/Immugio/three-math-extensions/compare/16.15.10...0.2.5)
11
11
 
12
12
  ### Commits
13
13
 
14
14
  - Add Rectangle, update Polygon [`58ee875`](https://github.com/Immugio/three-math-extensions/commit/58ee87539af8f9ade186e5250cba9e01926da514)
15
15
  - Vec3, Line3D - update documentation [`67d9c32`](https://github.com/Immugio/three-math-extensions/commit/67d9c328e08cc0a5599932d2f0529e97f31c9213)
16
16
  - Add Polygon [`629cff8`](https://github.com/Immugio/three-math-extensions/commit/629cff8ecbb963477e8ea76d7f8b16d95435cbad)
17
+ - Add Vec2.signedAngle [`863c8f2`](https://github.com/Immugio/three-math-extensions/commit/863c8f27f11288cbda535e21bb688206259269ed)
17
18
  - Polygon from bounding size [`eae6701`](https://github.com/Immugio/three-math-extensions/commit/eae67012f57f426f8b5259b765000447ce06d608)
18
19
  - Line2D and Line3D to return this instead of specific type [`761ef6a`](https://github.com/Immugio/three-math-extensions/commit/761ef6a9d8cc4e35120b666576794e521aa3b991)
19
20
  - Add Polygon to exports [`ed66775`](https://github.com/Immugio/three-math-extensions/commit/ed66775c33e961835b23843222b822cfd9c16b1d)
20
21
  - Vec2.fromPoint and Vec3.fromPoint should accept null [`4b871af`](https://github.com/Immugio/three-math-extensions/commit/4b871af297bdcbe8584f1e2b99d602247b77687c)
21
22
 
22
- ## [16.15.10](https://github.com/Immugio/three-math-extensions/compare/0.2.1...16.15.10) - 2023-01-02
23
+ ## [16.15.10](https://github.com/Immugio/three-math-extensions/compare/0.2.4...16.15.10) - 2023-01-02
24
+
25
+ ## [0.2.4](https://github.com/Immugio/three-math-extensions/compare/0.2.3...0.2.4) - 2023-04-11
26
+
27
+ ## [0.2.3](https://github.com/Immugio/three-math-extensions/compare/0.2.2...0.2.3) - 2023-04-11
28
+
29
+ ### Commits
30
+
31
+ - Add Vec2.signedAngle [`863c8f2`](https://github.com/Immugio/three-math-extensions/commit/863c8f27f11288cbda535e21bb688206259269ed)
32
+
33
+ ## [0.2.2](https://github.com/Immugio/three-math-extensions/compare/0.2.1...0.2.2) - 2023-04-11
34
+
35
+ ### Commits
36
+
37
+ - Line2D and Line3D to return this instead of specific type [`761ef6a`](https://github.com/Immugio/three-math-extensions/commit/761ef6a9d8cc4e35120b666576794e521aa3b991)
23
38
 
24
39
  ## [0.2.1](https://github.com/Immugio/three-math-extensions/compare/0.2.0...0.2.1) - 2023-03-28
25
40
 
package/cjs/Vec2.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Vec2 = void 0;
4
4
  const three_1 = require("three");
5
5
  const Vec3_1 = require("./Vec3");
6
+ const normalizeAngleRadians_1 = require("./normalizeAngleRadians");
6
7
  /**
7
8
  * Vec2 represents a 2D vector. It extends `Vector2` from the `threejs` library.
8
9
  */
@@ -58,5 +59,12 @@ class Vec2 extends three_1.Vector2 {
58
59
  }
59
60
  return this.distanceTo(v) <= maxDistance;
60
61
  }
62
+ /**
63
+ * Returns the angle between this vector and positive x-axis, the return value is between 0 and 2PI
64
+ */
65
+ signedAngle() {
66
+ const signed_angle = Math.atan2(this.y, this.x) - Math.atan2(0, 1);
67
+ return (0, normalizeAngleRadians_1.normalizeAngleRadians)(signed_angle);
68
+ }
61
69
  }
62
70
  exports.Vec2 = Vec2;
package/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Rectangle = exports.BoundingBox = exports.Polygon = exports.Size2 = exports.Line3D = exports.Line2D = exports.Vec3 = exports.Vec2 = void 0;
3
+ 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");
@@ -17,3 +17,7 @@ var BoundingBox_1 = require("./BoundingBox");
17
17
  Object.defineProperty(exports, "BoundingBox", { enumerable: true, get: function () { return BoundingBox_1.BoundingBox; } });
18
18
  var Rectangle_1 = require("./Rectangle");
19
19
  Object.defineProperty(exports, "Rectangle", { enumerable: true, get: function () { return Rectangle_1.Rectangle; } });
20
+ var normalizeAngleDegrees_1 = require("./normalizeAngleDegrees");
21
+ Object.defineProperty(exports, "normalizeAngleDegrees", { enumerable: true, get: function () { return normalizeAngleDegrees_1.normalizeAngleDegrees; } });
22
+ var normalizeAngleRadians_1 = require("./normalizeAngleRadians");
23
+ Object.defineProperty(exports, "normalizeAngleRadians", { enumerable: true, get: function () { return normalizeAngleRadians_1.normalizeAngleRadians; } });
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeAngleDegrees = void 0;
4
+ function normalizeAngleDegrees(angle) {
5
+ return ((angle % 360) + 360) % 360;
6
+ }
7
+ exports.normalizeAngleDegrees = normalizeAngleDegrees;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeAngleRadians = void 0;
4
+ 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π
7
+ if (angle < 0) { // Add 2π if the angle is negative
8
+ angle = angle + twoPi;
9
+ }
10
+ return angle;
11
+ }
12
+ exports.normalizeAngleRadians = normalizeAngleRadians;
package/esm/Vec2.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Vector2 } from "three";
2
2
  import { Vec3 } from "./Vec3";
3
+ import { normalizeAngleRadians } from "./normalizeAngleRadians";
3
4
  /**
4
5
  * Vec2 represents a 2D vector. It extends `Vector2` from the `threejs` library.
5
6
  */
@@ -55,4 +56,11 @@ export class Vec2 extends Vector2 {
55
56
  }
56
57
  return this.distanceTo(v) <= maxDistance;
57
58
  }
59
+ /**
60
+ * Returns the angle between this vector and positive x-axis, the return value is between 0 and 2PI
61
+ */
62
+ signedAngle() {
63
+ const signed_angle = Math.atan2(this.y, this.x) - Math.atan2(0, 1);
64
+ return normalizeAngleRadians(signed_angle);
65
+ }
58
66
  }
package/esm/index.js CHANGED
@@ -6,3 +6,5 @@ export { Size2 } from "./Size2";
6
6
  export { Polygon } from "./Polygon";
7
7
  export { BoundingBox } from "./BoundingBox";
8
8
  export { Rectangle } from "./Rectangle";
9
+ export { normalizeAngleDegrees } from "./normalizeAngleDegrees";
10
+ export { normalizeAngleRadians } from "./normalizeAngleRadians";
@@ -0,0 +1,3 @@
1
+ export function normalizeAngleDegrees(angle) {
2
+ return ((angle % 360) + 360) % 360;
3
+ }
@@ -0,0 +1,8 @@
1
+ export function normalizeAngleRadians(angle) {
2
+ const twoPi = 2 * Math.PI;
3
+ angle = angle % twoPi; // Use modulus to get the angle within the range of 0 to 2π
4
+ if (angle < 0) { // Add 2π if the angle is negative
5
+ angle = angle + twoPi;
6
+ }
7
+ return angle;
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@immugio/three-math-extensions",
3
- "version": "0.2.2",
3
+ "version": "0.2.5",
4
4
  "description": "Set of utilities for 2d and 3d line math built on top of three.js",
5
5
  "author": "Jan Mikeska <janmikeska@gmail.com>",
6
6
  "license": "ISC",
package/src/Vec2.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Vector2 } from "three";
2
2
  import { Vec3 } from "./Vec3";
3
3
  import { Point2 } from "./Point2";
4
+ import { normalizeAngleRadians } from "./normalizeAngleRadians";
4
5
 
5
6
  /**
6
7
  * Vec2 represents a 2D vector. It extends `Vector2` from the `threejs` library.
@@ -63,4 +64,12 @@ export class Vec2 extends Vector2 {
63
64
 
64
65
  return this.distanceTo(v) <= maxDistance;
65
66
  }
67
+
68
+ /**
69
+ * Returns the angle between this vector and positive x-axis, the return value is between 0 and 2PI
70
+ */
71
+ public signedAngle(): number {
72
+ const signed_angle = Math.atan2(this.y, this.x) - Math.atan2(0, 1);
73
+ return normalizeAngleRadians(signed_angle);
74
+ }
66
75
  }
package/src/index.ts CHANGED
@@ -5,4 +5,6 @@ export { Line3D } from "./Line3D";
5
5
  export { Size2 } from "./Size2";
6
6
  export { Polygon } from "./Polygon";
7
7
  export { BoundingBox } from "./BoundingBox";
8
- export { Rectangle } from "./Rectangle";
8
+ export { Rectangle } from "./Rectangle";
9
+ export { normalizeAngleDegrees } from "./normalizeAngleDegrees";
10
+ export { normalizeAngleRadians } from "./normalizeAngleRadians";
@@ -0,0 +1,3 @@
1
+ export function normalizeAngleDegrees(angle: number): number {
2
+ return ((angle % 360) + 360) % 360;
3
+ }
@@ -0,0 +1,9 @@
1
+ export function normalizeAngleRadians(angle: number): number {
2
+ const twoPi = 2 * Math.PI;
3
+ angle = angle % twoPi; // Use modulus to get the angle within the range of 0 to 2π
4
+ if (angle < 0) { // Add 2π if the angle is negative
5
+ angle = angle + twoPi;
6
+ }
7
+ return angle;
8
+ }
9
+
package/types/Vec2.d.ts CHANGED
@@ -35,4 +35,8 @@ export declare class Vec2 extends Vector2 {
35
35
  * maxDistance is the maximum distance between the two vectors within which they are considered `near`.
36
36
  */
37
37
  isNear(v: Vector2, maxDistance?: number): boolean;
38
+ /**
39
+ * Returns the angle between this vector and positive x-axis, the return value is between 0 and 2PI
40
+ */
41
+ signedAngle(): number;
38
42
  }
package/types/index.d.ts CHANGED
@@ -6,3 +6,5 @@ export { Size2 } from "./Size2";
6
6
  export { Polygon } from "./Polygon";
7
7
  export { BoundingBox } from "./BoundingBox";
8
8
  export { Rectangle } from "./Rectangle";
9
+ export { normalizeAngleDegrees } from "./normalizeAngleDegrees";
10
+ export { normalizeAngleRadians } from "./normalizeAngleRadians";
@@ -0,0 +1 @@
1
+ export declare function normalizeAngleDegrees(angle: number): number;
@@ -0,0 +1 @@
1
+ export declare function normalizeAngleRadians(angle: number): number;