@immugio/three-math-extensions 0.2.26 → 0.2.28

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,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.26](https://github.com/Immugio/three-math-extensions/compare/16.15.10...0.2.26)
10
+ ## [0.2.28](https://github.com/Immugio/three-math-extensions/compare/16.15.10...0.2.28)
11
11
 
12
12
  ### Commits
13
13
 
@@ -36,6 +36,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
36
36
  - Add Vec2.signedAngle [`863c8f2`](https://github.com/Immugio/three-math-extensions/commit/863c8f27f11288cbda535e21bb688206259269ed)
37
37
  - Add parallelism check to Line2D [`18064ee`](https://github.com/Immugio/three-math-extensions/commit/18064ee35a28e2c4d656f3dfb543b545044167dd)
38
38
  - Add Vec2.fromPoints to accept multiple points [`a261402`](https://github.com/Immugio/three-math-extensions/commit/a2614027cf5fb8263189b48f7e0bb9a23a552c15)
39
+ - Add Polygon.rotate [`4f2d581`](https://github.com/Immugio/three-math-extensions/commit/4f2d5814cdb3df067ab0a0cefcdfdb7a71696312)
39
40
  - Add Vec2.parallelTo [`989874d`](https://github.com/Immugio/three-math-extensions/commit/989874dcfe122d3ee84d8d56d79cb88e4e441736)
40
41
  - Line2D.intersect - enable line segments intersection only [`1f1470e`](https://github.com/Immugio/three-math-extensions/commit/1f1470e1cf00118e643f5c44a135e0baf6b76d41)
41
42
  - Add Polygon.translate [`a77136a`](https://github.com/Immugio/three-math-extensions/commit/a77136aea1c2dbdbba725c14ba0bc2115ae56ffc)
@@ -44,6 +45,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
44
45
  - Line2D.clipLines to support tolerances [`e397290`](https://github.com/Immugio/three-math-extensions/commit/e3972909339f01f0c018ad49e14b958d18e489e5)
45
46
  - Add functionality for incrementing x, y, z coordinates [`b292dcc`](https://github.com/Immugio/three-math-extensions/commit/b292dcc4e8f7f0f2a63e1810c482d96ca6bebebe)
46
47
  - Add Line3D.index [`7ed13d2`](https://github.com/Immugio/three-math-extensions/commit/7ed13d213748056c9dafd86288c3bcec9a28d1ba)
48
+ - Add Polygon.roundIfCloseToInteger, Vec3.roundIfCloseToInteger [`ee9a90d`](https://github.com/Immugio/three-math-extensions/commit/ee9a90de07eb9827d1a53cdac65be3a51862cdc2)
47
49
  - Polygon from bounding size [`eae6701`](https://github.com/Immugio/three-math-extensions/commit/eae67012f57f426f8b5259b765000447ce06d608)
48
50
  - Add Vec3.fromPoints [`62684d7`](https://github.com/Immugio/three-math-extensions/commit/62684d7f6dc1318d345ed74288bb6afd5394e1d3)
49
51
  - Line2D and Line3D to return this instead of specific type [`761ef6a`](https://github.com/Immugio/three-math-extensions/commit/761ef6a9d8cc4e35120b666576794e521aa3b991)
@@ -62,7 +64,19 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
62
64
  - Excluded files from build [`ec70614`](https://github.com/Immugio/three-math-extensions/commit/ec70614bc7df7a98f854c7a6693365118e04faf7)
63
65
  - Correct test file extension [`91b5e2a`](https://github.com/Immugio/three-math-extensions/commit/91b5e2ad338e8404704381a36813dcce5f00d978)
64
66
 
65
- ## [16.15.10](https://github.com/Immugio/three-math-extensions/compare/0.2.25...16.15.10) - 2023-01-02
67
+ ## [16.15.10](https://github.com/Immugio/three-math-extensions/compare/0.2.27...16.15.10) - 2023-01-02
68
+
69
+ ## [0.2.27](https://github.com/Immugio/three-math-extensions/compare/0.2.26...0.2.27) - 2024-09-10
70
+
71
+ ### Commits
72
+
73
+ - Add Polygon.rotate [`4f2d581`](https://github.com/Immugio/three-math-extensions/commit/4f2d5814cdb3df067ab0a0cefcdfdb7a71696312)
74
+
75
+ ## [0.2.26](https://github.com/Immugio/three-math-extensions/compare/0.2.25...0.2.26) - 2024-09-06
76
+
77
+ ### Commits
78
+
79
+ - Add Polygon.translate [`a77136a`](https://github.com/Immugio/three-math-extensions/commit/a77136aea1c2dbdbba725c14ba0bc2115ae56ffc)
66
80
 
67
81
  ## [0.2.25](https://github.com/Immugio/three-math-extensions/compare/0.2.24...0.2.25) - 2024-07-11
68
82
 
package/cjs/Polygon.js CHANGED
@@ -106,6 +106,11 @@ class Polygon {
106
106
  this.holes?.forEach(hole => hole.forEach(p => p.add(translate)));
107
107
  return this;
108
108
  }
109
+ rotate(angle, center = this.center()) {
110
+ this.contour.forEach(p => p.rotateAround(center, angle));
111
+ this.holes?.forEach(hole => hole.forEach(p => p.rotateAround(center, angle)));
112
+ return this;
113
+ }
109
114
  toRectangle() {
110
115
  const bounding = this.boundingBox();
111
116
  return new Rectangle_1.Rectangle(bounding.minX, bounding.maxX, bounding.minY, bounding.maxY);
@@ -113,6 +118,11 @@ class Polygon {
113
118
  clone() {
114
119
  return new Polygon(this.contour.map(p => p.clone()), this.holes?.map(h => h.map(p => p.clone())));
115
120
  }
121
+ roundIfCloseToInteger(max = 0.000000000001) {
122
+ this.contour.forEach(p => p.roundIfCloseToInteger(max));
123
+ this.holes?.forEach(h => h.forEach(p => p.roundIfCloseToInteger(max)));
124
+ return this;
125
+ }
116
126
  equals(other) {
117
127
  if (this.contour.length !== other.contour.length) {
118
128
  return false;
package/cjs/Vec2.js CHANGED
@@ -62,6 +62,12 @@ class Vec2 extends three_1.Vector2 {
62
62
  if (Math.abs(this.y - Math.round(this.y)) < max) {
63
63
  this.y = Math.round(this.y);
64
64
  }
65
+ if (Object.is(this.x, -0)) {
66
+ this.x = 0;
67
+ }
68
+ if (Object.is(this.y, -0)) {
69
+ this.y = 0;
70
+ }
65
71
  return this;
66
72
  }
67
73
  /**
package/cjs/Vec3.js CHANGED
@@ -81,6 +81,27 @@ class Vec3 extends three_1.Vector3 {
81
81
  const closest = withDistances.reduce((a, b) => a.distance < b.distance ? a : b);
82
82
  return Vec3.fromPoint(closest.point);
83
83
  }
84
+ roundIfCloseToInteger(max = 0.000000000001) {
85
+ if (Math.abs(this.x - Math.round(this.x)) < max) {
86
+ this.x = Math.round(this.x);
87
+ }
88
+ if (Math.abs(this.y - Math.round(this.y)) < max) {
89
+ this.y = Math.round(this.y);
90
+ }
91
+ if (Math.abs(this.z - Math.round(this.z)) < max) {
92
+ this.z = Math.round(this.z);
93
+ }
94
+ if (Object.is(this.x, -0)) {
95
+ this.x = 0;
96
+ }
97
+ if (Object.is(this.y, -0)) {
98
+ this.y = 0;
99
+ }
100
+ if (Object.is(this.z, -0)) {
101
+ this.z = 0;
102
+ }
103
+ return this;
104
+ }
84
105
  /**
85
106
  * Returns a clone of this Vec3 instance with y and z swapped.
86
107
  */
package/esm/Polygon.js CHANGED
@@ -103,6 +103,11 @@ export class Polygon {
103
103
  this.holes?.forEach(hole => hole.forEach(p => p.add(translate)));
104
104
  return this;
105
105
  }
106
+ rotate(angle, center = this.center()) {
107
+ this.contour.forEach(p => p.rotateAround(center, angle));
108
+ this.holes?.forEach(hole => hole.forEach(p => p.rotateAround(center, angle)));
109
+ return this;
110
+ }
106
111
  toRectangle() {
107
112
  const bounding = this.boundingBox();
108
113
  return new Rectangle(bounding.minX, bounding.maxX, bounding.minY, bounding.maxY);
@@ -110,6 +115,11 @@ export class Polygon {
110
115
  clone() {
111
116
  return new Polygon(this.contour.map(p => p.clone()), this.holes?.map(h => h.map(p => p.clone())));
112
117
  }
118
+ roundIfCloseToInteger(max = 0.000000000001) {
119
+ this.contour.forEach(p => p.roundIfCloseToInteger(max));
120
+ this.holes?.forEach(h => h.forEach(p => p.roundIfCloseToInteger(max)));
121
+ return this;
122
+ }
113
123
  equals(other) {
114
124
  if (this.contour.length !== other.contour.length) {
115
125
  return false;
package/esm/Vec2.js CHANGED
@@ -59,6 +59,12 @@ export class Vec2 extends Vector2 {
59
59
  if (Math.abs(this.y - Math.round(this.y)) < max) {
60
60
  this.y = Math.round(this.y);
61
61
  }
62
+ if (Object.is(this.x, -0)) {
63
+ this.x = 0;
64
+ }
65
+ if (Object.is(this.y, -0)) {
66
+ this.y = 0;
67
+ }
62
68
  return this;
63
69
  }
64
70
  /**
package/esm/Vec3.js CHANGED
@@ -78,6 +78,27 @@ export class Vec3 extends Vector3 {
78
78
  const closest = withDistances.reduce((a, b) => a.distance < b.distance ? a : b);
79
79
  return Vec3.fromPoint(closest.point);
80
80
  }
81
+ roundIfCloseToInteger(max = 0.000000000001) {
82
+ if (Math.abs(this.x - Math.round(this.x)) < max) {
83
+ this.x = Math.round(this.x);
84
+ }
85
+ if (Math.abs(this.y - Math.round(this.y)) < max) {
86
+ this.y = Math.round(this.y);
87
+ }
88
+ if (Math.abs(this.z - Math.round(this.z)) < max) {
89
+ this.z = Math.round(this.z);
90
+ }
91
+ if (Object.is(this.x, -0)) {
92
+ this.x = 0;
93
+ }
94
+ if (Object.is(this.y, -0)) {
95
+ this.y = 0;
96
+ }
97
+ if (Object.is(this.z, -0)) {
98
+ this.z = 0;
99
+ }
100
+ return this;
101
+ }
81
102
  /**
82
103
  * Returns a clone of this Vec3 instance with y and z swapped.
83
104
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@immugio/three-math-extensions",
3
- "version": "0.2.26",
3
+ "version": "0.2.28",
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/Polygon.ts CHANGED
@@ -123,6 +123,12 @@ export class Polygon {
123
123
  return this;
124
124
  }
125
125
 
126
+ public rotate(angle: number, center = this.center()): this {
127
+ this.contour.forEach(p => p.rotateAround(center, angle));
128
+ this.holes?.forEach(hole => hole.forEach(p => p.rotateAround(center, angle)));
129
+ return this;
130
+ }
131
+
126
132
  public toRectangle(): Rectangle {
127
133
  const bounding = this.boundingBox();
128
134
  return new Rectangle(bounding.minX, bounding.maxX, bounding.minY, bounding.maxY);
@@ -132,6 +138,12 @@ export class Polygon {
132
138
  return new Polygon(this.contour.map(p => p.clone()), this.holes?.map(h => h.map(p => p.clone())));
133
139
  }
134
140
 
141
+ public roundIfCloseToInteger(max: number = 0.000000000001): this {
142
+ this.contour.forEach(p => p.roundIfCloseToInteger(max));
143
+ this.holes?.forEach(h => h.forEach(p => p.roundIfCloseToInteger(max)));
144
+ return this;
145
+ }
146
+
135
147
  public equals(other: Polygon): boolean {
136
148
  if (this.contour.length !== other.contour.length) {
137
149
  return false;
package/src/Vec2.ts CHANGED
@@ -67,6 +67,12 @@ export class Vec2 extends Vector2 {
67
67
  if (Math.abs(this.y - Math.round(this.y)) < max) {
68
68
  this.y = Math.round(this.y);
69
69
  }
70
+ if (Object.is(this.x, -0)) {
71
+ this.x = 0;
72
+ }
73
+ if (Object.is(this.y, -0)) {
74
+ this.y = 0;
75
+ }
70
76
  return this;
71
77
  }
72
78
 
package/src/Vec3.ts CHANGED
@@ -94,6 +94,28 @@ export class Vec3 extends Vector3 {
94
94
  return Vec3.fromPoint(closest.point);
95
95
  }
96
96
 
97
+ public roundIfCloseToInteger(max: number = 0.000000000001): this {
98
+ if (Math.abs(this.x - Math.round(this.x)) < max) {
99
+ this.x = Math.round(this.x);
100
+ }
101
+ if (Math.abs(this.y - Math.round(this.y)) < max) {
102
+ this.y = Math.round(this.y);
103
+ }
104
+ if (Math.abs(this.z - Math.round(this.z)) < max) {
105
+ this.z = Math.round(this.z);
106
+ }
107
+ if (Object.is(this.x, -0)) {
108
+ this.x = 0;
109
+ }
110
+ if (Object.is(this.y, -0)) {
111
+ this.y = 0;
112
+ }
113
+ if (Object.is(this.z, -0)) {
114
+ this.z = 0;
115
+ }
116
+ return this;
117
+ }
118
+
97
119
  /**
98
120
  * Returns a clone of this Vec3 instance with y and z swapped.
99
121
  */
@@ -19,7 +19,9 @@ export declare class Polygon {
19
19
  containsPoint(point: Vec2): boolean;
20
20
  private flipSingle;
21
21
  translate(translate: Vec2): this;
22
+ rotate(angle: number, center?: Vec2): this;
22
23
  toRectangle(): Rectangle;
23
24
  clone(): Polygon;
25
+ roundIfCloseToInteger(max?: number): this;
24
26
  equals(other: Polygon): boolean;
25
27
  }
package/types/Vec3.d.ts CHANGED
@@ -50,6 +50,7 @@ export declare class Vec3 extends Vector3 {
50
50
  * @param points
51
51
  */
52
52
  closest(...points: Vector3[]): Vec3;
53
+ roundIfCloseToInteger(max?: number): this;
53
54
  /**
54
55
  * Returns a clone of this Vec3 instance with y and z swapped.
55
56
  */