@immugio/three-math-extensions 0.2.25 → 0.2.27
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 +17 -2
- package/cjs/Polygon.js +10 -0
- package/esm/Polygon.js +10 -0
- package/package.json +1 -1
- package/src/Polygon.ts +16 -4
- package/types/Polygon.d.ts +5 -3
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.
|
|
10
|
+
## [0.2.27](https://github.com/Immugio/three-math-extensions/compare/16.15.10...0.2.27)
|
|
11
11
|
|
|
12
12
|
### Commits
|
|
13
13
|
|
|
@@ -36,8 +36,10 @@ 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)
|
|
42
|
+
- Add Polygon.translate [`a77136a`](https://github.com/Immugio/three-math-extensions/commit/a77136aea1c2dbdbba725c14ba0bc2115ae56ffc)
|
|
41
43
|
- Line3D.groupConnectedLines now supports line breaks [`417a9ea`](https://github.com/Immugio/three-math-extensions/commit/417a9ea471bf4c539f73f5fb170c962a78ee4ab4)
|
|
42
44
|
- Add Line2D.projectOn [`4c52c5c`](https://github.com/Immugio/three-math-extensions/commit/4c52c5c2e649fbddb72ce3fca60cfd3f1319f72f)
|
|
43
45
|
- Line2D.clipLines to support tolerances [`e397290`](https://github.com/Immugio/three-math-extensions/commit/e3972909339f01f0c018ad49e14b958d18e489e5)
|
|
@@ -61,7 +63,20 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
61
63
|
- Excluded files from build [`ec70614`](https://github.com/Immugio/three-math-extensions/commit/ec70614bc7df7a98f854c7a6693365118e04faf7)
|
|
62
64
|
- Correct test file extension [`91b5e2a`](https://github.com/Immugio/three-math-extensions/commit/91b5e2ad338e8404704381a36813dcce5f00d978)
|
|
63
65
|
|
|
64
|
-
## [16.15.10](https://github.com/Immugio/three-math-extensions/compare/0.2.
|
|
66
|
+
## [16.15.10](https://github.com/Immugio/three-math-extensions/compare/0.2.26...16.15.10) - 2023-01-02
|
|
67
|
+
|
|
68
|
+
## [0.2.26](https://github.com/Immugio/three-math-extensions/compare/0.2.25...0.2.26) - 2024-09-06
|
|
69
|
+
|
|
70
|
+
### Commits
|
|
71
|
+
|
|
72
|
+
- Add Polygon.translate [`a77136a`](https://github.com/Immugio/three-math-extensions/commit/a77136aea1c2dbdbba725c14ba0bc2115ae56ffc)
|
|
73
|
+
|
|
74
|
+
## [0.2.25](https://github.com/Immugio/three-math-extensions/compare/0.2.24...0.2.25) - 2024-07-11
|
|
75
|
+
|
|
76
|
+
### Commits
|
|
77
|
+
|
|
78
|
+
- Documentation update [`fc82582`](https://github.com/Immugio/three-math-extensions/commit/fc82582fa7d6042d51bf9ac5841cc94346211f3d)
|
|
79
|
+
- Line2D.clipLines to support tolerances [`e397290`](https://github.com/Immugio/three-math-extensions/commit/e3972909339f01f0c018ad49e14b958d18e489e5)
|
|
65
80
|
|
|
66
81
|
## [0.2.24](https://github.com/Immugio/three-math-extensions/compare/0.2.23...0.2.24) - 2024-05-10
|
|
67
82
|
|
package/cjs/Polygon.js
CHANGED
|
@@ -101,6 +101,16 @@ class Polygon {
|
|
|
101
101
|
point.x = point.x < centerX ? centerX + xDistanceToCenter : centerX - xDistanceToCenter;
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
+
translate(translate) {
|
|
105
|
+
this.contour.forEach(p => p.add(translate));
|
|
106
|
+
this.holes?.forEach(hole => hole.forEach(p => p.add(translate)));
|
|
107
|
+
return this;
|
|
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
|
+
}
|
|
104
114
|
toRectangle() {
|
|
105
115
|
const bounding = this.boundingBox();
|
|
106
116
|
return new Rectangle_1.Rectangle(bounding.minX, bounding.maxX, bounding.minY, bounding.maxY);
|
package/esm/Polygon.js
CHANGED
|
@@ -98,6 +98,16 @@ export class Polygon {
|
|
|
98
98
|
point.x = point.x < centerX ? centerX + xDistanceToCenter : centerX - xDistanceToCenter;
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
+
translate(translate) {
|
|
102
|
+
this.contour.forEach(p => p.add(translate));
|
|
103
|
+
this.holes?.forEach(hole => hole.forEach(p => p.add(translate)));
|
|
104
|
+
return this;
|
|
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
|
+
}
|
|
101
111
|
toRectangle() {
|
|
102
112
|
const bounding = this.boundingBox();
|
|
103
113
|
return new Rectangle(bounding.minX, bounding.maxX, bounding.minY, bounding.maxY);
|
package/package.json
CHANGED
package/src/Polygon.ts
CHANGED
|
@@ -28,7 +28,7 @@ export class Polygon {
|
|
|
28
28
|
return new Vec2(maxX - minX, maxY - minY);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
public centerOnOrigin():
|
|
31
|
+
public centerOnOrigin(): this {
|
|
32
32
|
const center = this.center();
|
|
33
33
|
|
|
34
34
|
function centerPoints(points: Vec2[]): void {
|
|
@@ -56,7 +56,7 @@ export class Polygon {
|
|
|
56
56
|
return new Vec2(x, y);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
public ensureLastPoint():
|
|
59
|
+
public ensureLastPoint(): this {
|
|
60
60
|
function ensure(points: Vec2[]): void {
|
|
61
61
|
if (!points[0].equals(points.at(-1))) {
|
|
62
62
|
points.push(points[0].clone());
|
|
@@ -95,7 +95,7 @@ export class Polygon {
|
|
|
95
95
|
]);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
public flip():
|
|
98
|
+
public flip(): this {
|
|
99
99
|
const centerX = this.center().x;
|
|
100
100
|
this.flipSingle(centerX, this.contour);
|
|
101
101
|
this.holes?.forEach(hole => this.flipSingle(centerX, hole));
|
|
@@ -110,13 +110,25 @@ export class Polygon {
|
|
|
110
110
|
return isPointInPolygon(this.contour, point) && (this.holes || []).every(hole => !isPointInPolygon(hole, point));
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
private flipSingle(centerX: number, poly: Vec2[]) {
|
|
113
|
+
private flipSingle(centerX: number, poly: Vec2[]): void {
|
|
114
114
|
for (const point of poly) {
|
|
115
115
|
const xDistanceToCenter = Math.abs(centerX - point.x);
|
|
116
116
|
point.x = point.x < centerX ? centerX + xDistanceToCenter : centerX - xDistanceToCenter;
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
public translate(translate: Vec2): this {
|
|
121
|
+
this.contour.forEach(p => p.add(translate));
|
|
122
|
+
this.holes?.forEach(hole => hole.forEach(p => p.add(translate)));
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
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
|
+
|
|
120
132
|
public toRectangle(): Rectangle {
|
|
121
133
|
const bounding = this.boundingBox();
|
|
122
134
|
return new Rectangle(bounding.minX, bounding.maxX, bounding.minY, bounding.maxY);
|
package/types/Polygon.d.ts
CHANGED
|
@@ -9,15 +9,17 @@ export declare class Polygon {
|
|
|
9
9
|
static fromPoints(contour: Point2[], holes?: Point2[][]): Polygon;
|
|
10
10
|
static fromSize(width: number, height: number): Polygon;
|
|
11
11
|
get size(): Vec2;
|
|
12
|
-
centerOnOrigin():
|
|
12
|
+
centerOnOrigin(): this;
|
|
13
13
|
center(): Vec2;
|
|
14
|
-
ensureLastPoint():
|
|
14
|
+
ensureLastPoint(): this;
|
|
15
15
|
boundingBox(): BoundingBox;
|
|
16
16
|
toBoundingPolygon(): Polygon;
|
|
17
|
-
flip():
|
|
17
|
+
flip(): this;
|
|
18
18
|
perimeter(): number;
|
|
19
19
|
containsPoint(point: Vec2): boolean;
|
|
20
20
|
private flipSingle;
|
|
21
|
+
translate(translate: Vec2): this;
|
|
22
|
+
rotate(angle: number, center?: Vec2): this;
|
|
21
23
|
toRectangle(): Rectangle;
|
|
22
24
|
clone(): Polygon;
|
|
23
25
|
equals(other: Polygon): boolean;
|