@immugio/three-math-extensions 0.2.25 → 0.2.26
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 +10 -2
- package/cjs/Polygon.js +5 -0
- package/esm/Polygon.js +5 -0
- package/package.json +1 -1
- package/src/Polygon.ts +10 -4
- package/types/Polygon.d.ts +4 -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.26](https://github.com/Immugio/three-math-extensions/compare/16.15.10...0.2.26)
|
|
11
11
|
|
|
12
12
|
### Commits
|
|
13
13
|
|
|
@@ -38,6 +38,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
38
38
|
- Add Vec2.fromPoints to accept multiple points [`a261402`](https://github.com/Immugio/three-math-extensions/commit/a2614027cf5fb8263189b48f7e0bb9a23a552c15)
|
|
39
39
|
- Add Vec2.parallelTo [`989874d`](https://github.com/Immugio/three-math-extensions/commit/989874dcfe122d3ee84d8d56d79cb88e4e441736)
|
|
40
40
|
- Line2D.intersect - enable line segments intersection only [`1f1470e`](https://github.com/Immugio/three-math-extensions/commit/1f1470e1cf00118e643f5c44a135e0baf6b76d41)
|
|
41
|
+
- Add Polygon.translate [`a77136a`](https://github.com/Immugio/three-math-extensions/commit/a77136aea1c2dbdbba725c14ba0bc2115ae56ffc)
|
|
41
42
|
- Line3D.groupConnectedLines now supports line breaks [`417a9ea`](https://github.com/Immugio/three-math-extensions/commit/417a9ea471bf4c539f73f5fb170c962a78ee4ab4)
|
|
42
43
|
- Add Line2D.projectOn [`4c52c5c`](https://github.com/Immugio/three-math-extensions/commit/4c52c5c2e649fbddb72ce3fca60cfd3f1319f72f)
|
|
43
44
|
- Line2D.clipLines to support tolerances [`e397290`](https://github.com/Immugio/three-math-extensions/commit/e3972909339f01f0c018ad49e14b958d18e489e5)
|
|
@@ -61,7 +62,14 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
61
62
|
- Excluded files from build [`ec70614`](https://github.com/Immugio/three-math-extensions/commit/ec70614bc7df7a98f854c7a6693365118e04faf7)
|
|
62
63
|
- Correct test file extension [`91b5e2a`](https://github.com/Immugio/three-math-extensions/commit/91b5e2ad338e8404704381a36813dcce5f00d978)
|
|
63
64
|
|
|
64
|
-
## [16.15.10](https://github.com/Immugio/three-math-extensions/compare/0.2.
|
|
65
|
+
## [16.15.10](https://github.com/Immugio/three-math-extensions/compare/0.2.25...16.15.10) - 2023-01-02
|
|
66
|
+
|
|
67
|
+
## [0.2.25](https://github.com/Immugio/three-math-extensions/compare/0.2.24...0.2.25) - 2024-07-11
|
|
68
|
+
|
|
69
|
+
### Commits
|
|
70
|
+
|
|
71
|
+
- Documentation update [`fc82582`](https://github.com/Immugio/three-math-extensions/commit/fc82582fa7d6042d51bf9ac5841cc94346211f3d)
|
|
72
|
+
- Line2D.clipLines to support tolerances [`e397290`](https://github.com/Immugio/three-math-extensions/commit/e3972909339f01f0c018ad49e14b958d18e489e5)
|
|
65
73
|
|
|
66
74
|
## [0.2.24](https://github.com/Immugio/three-math-extensions/compare/0.2.23...0.2.24) - 2024-05-10
|
|
67
75
|
|
package/cjs/Polygon.js
CHANGED
|
@@ -101,6 +101,11 @@ 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
|
+
}
|
|
104
109
|
toRectangle() {
|
|
105
110
|
const bounding = this.boundingBox();
|
|
106
111
|
return new Rectangle_1.Rectangle(bounding.minX, bounding.maxX, bounding.minY, bounding.maxY);
|
package/esm/Polygon.js
CHANGED
|
@@ -98,6 +98,11 @@ 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
|
+
}
|
|
101
106
|
toRectangle() {
|
|
102
107
|
const bounding = this.boundingBox();
|
|
103
108
|
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,19 @@ 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
|
+
|
|
120
126
|
public toRectangle(): Rectangle {
|
|
121
127
|
const bounding = this.boundingBox();
|
|
122
128
|
return new Rectangle(bounding.minX, bounding.maxX, bounding.minY, bounding.maxY);
|
package/types/Polygon.d.ts
CHANGED
|
@@ -9,15 +9,16 @@ 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;
|
|
21
22
|
toRectangle(): Rectangle;
|
|
22
23
|
clone(): Polygon;
|
|
23
24
|
equals(other: Polygon): boolean;
|