@immugio/three-math-extensions 0.3.6 → 0.3.8
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 +13 -1
- package/cjs/Polygon.js +9 -14
- package/cjs/ensurePolygonLastPoint.js +9 -0
- package/cjs/ensurePolygonOpen.js +9 -0
- package/cjs/index.js +5 -1
- package/esm/Polygon.js +9 -14
- package/esm/ensurePolygonLastPoint.js +5 -0
- package/esm/ensurePolygonOpen.js +5 -0
- package/esm/index.js +2 -0
- package/package.json +1 -1
- package/src/Polygon.ts +10 -16
- package/src/ensurePolygonLastPoint.ts +7 -0
- package/src/ensurePolygonOpen.ts +7 -0
- package/src/index.ts +3 -1
- package/types/ensurePolygonLastPoint.d.ts +2 -0
- package/types/ensurePolygonOpen.d.ts +2 -0
- package/types/index.d.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,7 +7,19 @@ 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.3.
|
|
10
|
+
## [0.3.8](https://github.com/Immugio/three-math-extensions/compare/0.3.7...0.3.8)
|
|
11
|
+
|
|
12
|
+
### Commits
|
|
13
|
+
|
|
14
|
+
- ensurePolygonLastPoint and ensurePolygonOpen functions to be also available as separate functions [`09036c1`](https://github.com/Immugio/three-math-extensions/commit/09036c18f9c9f579076d97a7b7cdcbffd345826a)
|
|
15
|
+
|
|
16
|
+
## [0.3.7](https://github.com/Immugio/three-math-extensions/compare/0.3.6...0.3.7) - 2026-01-16
|
|
17
|
+
|
|
18
|
+
### Commits
|
|
19
|
+
|
|
20
|
+
- Polygon - Account for empty contour when calculating bounding box [`56bb6a9`](https://github.com/Immugio/three-math-extensions/commit/56bb6a9577eea00b756779aa2a78688b3bb1f2b8)
|
|
21
|
+
|
|
22
|
+
## [0.3.6](https://github.com/Immugio/three-math-extensions/compare/0.3.5...0.3.6) - 2026-01-13
|
|
11
23
|
|
|
12
24
|
### Commits
|
|
13
25
|
|
package/cjs/Polygon.js
CHANGED
|
@@ -10,6 +10,8 @@ const isPolygonClockwise_1 = require("./isPolygonClockwise");
|
|
|
10
10
|
const ensurePolygonClockwise_1 = require("./ensurePolygonClockwise");
|
|
11
11
|
const containsPoint_1 = require("./containsPoint");
|
|
12
12
|
const getPolygonArea_1 = require("./getPolygonArea");
|
|
13
|
+
const ensurePolygonLastPoint_1 = require("./ensurePolygonLastPoint");
|
|
14
|
+
const ensurePolygonOpen_1 = require("./ensurePolygonOpen");
|
|
13
15
|
class Polygon {
|
|
14
16
|
contour;
|
|
15
17
|
holes;
|
|
@@ -53,26 +55,16 @@ class Polygon {
|
|
|
53
55
|
return new Vec2_1.Vec2(x, y);
|
|
54
56
|
}
|
|
55
57
|
ensureLastPoint() {
|
|
56
|
-
|
|
57
|
-
if (!points[0].equals(points.at(-1))) {
|
|
58
|
-
points.push(points[0].clone());
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
ensure(this.contour);
|
|
58
|
+
(0, ensurePolygonLastPoint_1.ensurePolygonLastPoint)(this.contour);
|
|
62
59
|
for (const hole of this.holes || []) {
|
|
63
|
-
|
|
60
|
+
(0, ensurePolygonLastPoint_1.ensurePolygonLastPoint)(hole);
|
|
64
61
|
}
|
|
65
62
|
return this;
|
|
66
63
|
}
|
|
67
64
|
ensureOpen() {
|
|
68
|
-
|
|
69
|
-
if (points.length > 2 && points[0].equals(points.at(-1))) {
|
|
70
|
-
points.pop();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
ensure(this.contour);
|
|
65
|
+
(0, ensurePolygonOpen_1.ensurePolygonOpen)(this.contour);
|
|
74
66
|
for (const hole of this.holes || []) {
|
|
75
|
-
|
|
67
|
+
(0, ensurePolygonOpen_1.ensurePolygonOpen)(hole);
|
|
76
68
|
}
|
|
77
69
|
return this;
|
|
78
70
|
}
|
|
@@ -80,6 +72,9 @@ class Polygon {
|
|
|
80
72
|
return (0, getPolygonArea_1.getPolygonArea)(this.contour);
|
|
81
73
|
}
|
|
82
74
|
boundingBox() {
|
|
75
|
+
if (!this.contour.length) {
|
|
76
|
+
return new BoundingBox_1.BoundingBox(0, 0, 0, 0);
|
|
77
|
+
}
|
|
83
78
|
let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
|
|
84
79
|
for (const p of this.contour) {
|
|
85
80
|
if (minX > p.x)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensurePolygonLastPoint = void 0;
|
|
4
|
+
function ensurePolygonLastPoint(points) {
|
|
5
|
+
if (!points[0].equals(points.at(-1))) {
|
|
6
|
+
points.push(points[0].clone());
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.ensurePolygonLastPoint = ensurePolygonLastPoint;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensurePolygonOpen = void 0;
|
|
4
|
+
function ensurePolygonOpen(points) {
|
|
5
|
+
if (points.length > 2 && points[0].equals(points.at(-1))) {
|
|
6
|
+
points.pop();
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.ensurePolygonOpen = ensurePolygonOpen;
|
package/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPolygonArea = exports.containsPoints = exports.containsPoint = exports.ensurePolygonClockwise = exports.isPolygonClockwise = exports.sortLinesByConnections = exports.extendOrTrimPolylinesAtIntersections = exports.offsetPolyline = exports.polygonPerimeter = exports.isContinuousClosedShape = exports.directions2d = exports.directions = exports.isPointInPolygon = exports.HalfPI = exports.TwoPI = exports.normalizeAngleRadians = exports.normalizeAngleDegrees = exports.Rectangle = exports.BoundingBox = exports.Polygon = exports.Size2 = exports.Line3D = exports.Line2D = exports.Vec3 = exports.Vec2 = void 0;
|
|
3
|
+
exports.ensurePolygonOpen = exports.ensurePolygonLastPoint = exports.getPolygonArea = exports.containsPoints = exports.containsPoint = exports.ensurePolygonClockwise = exports.isPolygonClockwise = exports.sortLinesByConnections = exports.extendOrTrimPolylinesAtIntersections = exports.offsetPolyline = exports.polygonPerimeter = exports.isContinuousClosedShape = exports.directions2d = exports.directions = exports.isPointInPolygon = exports.HalfPI = 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");
|
|
@@ -49,3 +49,7 @@ Object.defineProperty(exports, "containsPoint", { enumerable: true, get: functio
|
|
|
49
49
|
Object.defineProperty(exports, "containsPoints", { enumerable: true, get: function () { return containsPoint_1.containsPoints; } });
|
|
50
50
|
var getPolygonArea_1 = require("./getPolygonArea");
|
|
51
51
|
Object.defineProperty(exports, "getPolygonArea", { enumerable: true, get: function () { return getPolygonArea_1.getPolygonArea; } });
|
|
52
|
+
var ensurePolygonLastPoint_1 = require("./ensurePolygonLastPoint");
|
|
53
|
+
Object.defineProperty(exports, "ensurePolygonLastPoint", { enumerable: true, get: function () { return ensurePolygonLastPoint_1.ensurePolygonLastPoint; } });
|
|
54
|
+
var ensurePolygonOpen_1 = require("./ensurePolygonOpen");
|
|
55
|
+
Object.defineProperty(exports, "ensurePolygonOpen", { enumerable: true, get: function () { return ensurePolygonOpen_1.ensurePolygonOpen; } });
|
package/esm/Polygon.js
CHANGED
|
@@ -7,6 +7,8 @@ import { isPolygonClockwise } from "./isPolygonClockwise";
|
|
|
7
7
|
import { ensurePolygonClockwise } from "./ensurePolygonClockwise";
|
|
8
8
|
import { containsPoint } from "./containsPoint";
|
|
9
9
|
import { getPolygonArea } from "./getPolygonArea";
|
|
10
|
+
import { ensurePolygonLastPoint } from "./ensurePolygonLastPoint";
|
|
11
|
+
import { ensurePolygonOpen } from "./ensurePolygonOpen";
|
|
10
12
|
export class Polygon {
|
|
11
13
|
contour;
|
|
12
14
|
holes;
|
|
@@ -50,26 +52,16 @@ export class Polygon {
|
|
|
50
52
|
return new Vec2(x, y);
|
|
51
53
|
}
|
|
52
54
|
ensureLastPoint() {
|
|
53
|
-
|
|
54
|
-
if (!points[0].equals(points.at(-1))) {
|
|
55
|
-
points.push(points[0].clone());
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
ensure(this.contour);
|
|
55
|
+
ensurePolygonLastPoint(this.contour);
|
|
59
56
|
for (const hole of this.holes || []) {
|
|
60
|
-
|
|
57
|
+
ensurePolygonLastPoint(hole);
|
|
61
58
|
}
|
|
62
59
|
return this;
|
|
63
60
|
}
|
|
64
61
|
ensureOpen() {
|
|
65
|
-
|
|
66
|
-
if (points.length > 2 && points[0].equals(points.at(-1))) {
|
|
67
|
-
points.pop();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
ensure(this.contour);
|
|
62
|
+
ensurePolygonOpen(this.contour);
|
|
71
63
|
for (const hole of this.holes || []) {
|
|
72
|
-
|
|
64
|
+
ensurePolygonOpen(hole);
|
|
73
65
|
}
|
|
74
66
|
return this;
|
|
75
67
|
}
|
|
@@ -77,6 +69,9 @@ export class Polygon {
|
|
|
77
69
|
return getPolygonArea(this.contour);
|
|
78
70
|
}
|
|
79
71
|
boundingBox() {
|
|
72
|
+
if (!this.contour.length) {
|
|
73
|
+
return new BoundingBox(0, 0, 0, 0);
|
|
74
|
+
}
|
|
80
75
|
let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
|
|
81
76
|
for (const p of this.contour) {
|
|
82
77
|
if (minX > p.x)
|
package/esm/index.js
CHANGED
|
@@ -21,3 +21,5 @@ export { isPolygonClockwise } from "./isPolygonClockwise";
|
|
|
21
21
|
export { ensurePolygonClockwise } from "./ensurePolygonClockwise";
|
|
22
22
|
export { containsPoint, containsPoints } from "./containsPoint";
|
|
23
23
|
export { getPolygonArea } from "./getPolygonArea";
|
|
24
|
+
export { ensurePolygonLastPoint } from "./ensurePolygonLastPoint";
|
|
25
|
+
export { ensurePolygonOpen } from "./ensurePolygonOpen";
|
package/package.json
CHANGED
package/src/Polygon.ts
CHANGED
|
@@ -8,6 +8,8 @@ import { isPolygonClockwise } from "./isPolygonClockwise";
|
|
|
8
8
|
import { ensurePolygonClockwise } from "./ensurePolygonClockwise";
|
|
9
9
|
import { containsPoint } from "./containsPoint";
|
|
10
10
|
import { getPolygonArea } from "./getPolygonArea";
|
|
11
|
+
import { ensurePolygonLastPoint } from "./ensurePolygonLastPoint";
|
|
12
|
+
import { ensurePolygonOpen } from "./ensurePolygonOpen";
|
|
11
13
|
|
|
12
14
|
export class Polygon {
|
|
13
15
|
|
|
@@ -61,32 +63,20 @@ export class Polygon {
|
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
public ensureLastPoint(): this {
|
|
64
|
-
|
|
65
|
-
if (!points[0].equals(points.at(-1))) {
|
|
66
|
-
points.push(points[0].clone());
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
ensure(this.contour);
|
|
66
|
+
ensurePolygonLastPoint(this.contour);
|
|
71
67
|
|
|
72
68
|
for (const hole of this.holes || []) {
|
|
73
|
-
|
|
69
|
+
ensurePolygonLastPoint(hole);
|
|
74
70
|
}
|
|
75
71
|
|
|
76
72
|
return this;
|
|
77
73
|
}
|
|
78
74
|
|
|
79
75
|
public ensureOpen(): this {
|
|
80
|
-
|
|
81
|
-
if (points.length > 2 && points[0].equals(points.at(-1))) {
|
|
82
|
-
points.pop();
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
ensure(this.contour);
|
|
76
|
+
ensurePolygonOpen(this.contour);
|
|
87
77
|
|
|
88
78
|
for (const hole of this.holes || []) {
|
|
89
|
-
|
|
79
|
+
ensurePolygonOpen(hole);
|
|
90
80
|
}
|
|
91
81
|
|
|
92
82
|
return this;
|
|
@@ -97,6 +87,10 @@ export class Polygon {
|
|
|
97
87
|
}
|
|
98
88
|
|
|
99
89
|
public boundingBox(): BoundingBox {
|
|
90
|
+
if (!this.contour.length) {
|
|
91
|
+
return new BoundingBox(0, 0, 0, 0);
|
|
92
|
+
}
|
|
93
|
+
|
|
100
94
|
let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
|
|
101
95
|
|
|
102
96
|
for (const p of this.contour) {
|
package/src/index.ts
CHANGED
|
@@ -22,4 +22,6 @@ export { sortLinesByConnections } from "./sortLinesByConnections";
|
|
|
22
22
|
export { isPolygonClockwise } from "./isPolygonClockwise";
|
|
23
23
|
export { ensurePolygonClockwise } from "./ensurePolygonClockwise";
|
|
24
24
|
export { containsPoint, containsPoints } from "./containsPoint";
|
|
25
|
-
export { getPolygonArea } from "./getPolygonArea";
|
|
25
|
+
export { getPolygonArea } from "./getPolygonArea";
|
|
26
|
+
export { ensurePolygonLastPoint } from "./ensurePolygonLastPoint";
|
|
27
|
+
export { ensurePolygonOpen } from "./ensurePolygonOpen";
|
package/types/index.d.ts
CHANGED
|
@@ -23,3 +23,5 @@ export { isPolygonClockwise } from "./isPolygonClockwise";
|
|
|
23
23
|
export { ensurePolygonClockwise } from "./ensurePolygonClockwise";
|
|
24
24
|
export { containsPoint, containsPoints } from "./containsPoint";
|
|
25
25
|
export { getPolygonArea } from "./getPolygonArea";
|
|
26
|
+
export { ensurePolygonLastPoint } from "./ensurePolygonLastPoint";
|
|
27
|
+
export { ensurePolygonOpen } from "./ensurePolygonOpen";
|