@immugio/three-math-extensions 0.2.23 → 0.2.24
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 +7 -1
- package/cjs/Polygon.js +8 -0
- package/cjs/index.js +3 -1
- package/cjs/polygonPerimeter.js +15 -0
- package/esm/Polygon.js +8 -0
- package/esm/index.js +1 -0
- package/esm/polygonPerimeter.js +11 -0
- package/package.json +1 -1
- package/src/Polygon.ts +10 -0
- package/src/index.ts +2 -1
- package/src/polygonPerimeter.ts +14 -0
- package/types/Polygon.d.ts +2 -0
- package/types/index.d.ts +1 -0
- package/types/polygonPerimeter.d.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,7 +7,13 @@ 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.24](https://github.com/Immugio/three-math-extensions/compare/0.2.23...0.2.24)
|
|
11
|
+
|
|
12
|
+
### Commits
|
|
13
|
+
|
|
14
|
+
- Add Polygon.containsPoint and Polygon.perimeter [`9bdf2dd`](https://github.com/Immugio/three-math-extensions/commit/9bdf2ddb5823878b5d41dadf14a225f7a1f0fd8f)
|
|
15
|
+
|
|
16
|
+
## [0.2.23](https://github.com/Immugio/three-math-extensions/compare/0.2.22...0.2.23) - 2024-04-16
|
|
11
17
|
|
|
12
18
|
### Commits
|
|
13
19
|
|
package/cjs/Polygon.js
CHANGED
|
@@ -4,6 +4,8 @@ exports.Polygon = void 0;
|
|
|
4
4
|
const Vec2_1 = require("./Vec2");
|
|
5
5
|
const Rectangle_1 = require("./Rectangle");
|
|
6
6
|
const BoundingBox_1 = require("./BoundingBox");
|
|
7
|
+
const polygonPerimeter_1 = require("./polygonPerimeter");
|
|
8
|
+
const isPointInPolygon_1 = require("./isPointInPolygon");
|
|
7
9
|
class Polygon {
|
|
8
10
|
contour;
|
|
9
11
|
holes;
|
|
@@ -87,6 +89,12 @@ class Polygon {
|
|
|
87
89
|
this.holes?.forEach(hole => this.flipSingle(centerX, hole));
|
|
88
90
|
return this;
|
|
89
91
|
}
|
|
92
|
+
perimeter() {
|
|
93
|
+
return (0, polygonPerimeter_1.polygonPerimeter)(this.contour);
|
|
94
|
+
}
|
|
95
|
+
containsPoint(point) {
|
|
96
|
+
return (0, isPointInPolygon_1.isPointInPolygon)(this.contour, point) && (this.holes || []).every(hole => !(0, isPointInPolygon_1.isPointInPolygon)(hole, point));
|
|
97
|
+
}
|
|
90
98
|
flipSingle(centerX, poly) {
|
|
91
99
|
for (const point of poly) {
|
|
92
100
|
const xDistanceToCenter = Math.abs(centerX - point.x);
|
package/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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.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");
|
|
@@ -32,3 +32,5 @@ var directions2d_1 = require("./directions2d");
|
|
|
32
32
|
Object.defineProperty(exports, "directions2d", { enumerable: true, get: function () { return directions2d_1.directions2d; } });
|
|
33
33
|
var isContinuousClosedShape_1 = require("./isContinuousClosedShape");
|
|
34
34
|
Object.defineProperty(exports, "isContinuousClosedShape", { enumerable: true, get: function () { return isContinuousClosedShape_1.isContinuousClosedShape; } });
|
|
35
|
+
var polygonPerimeter_1 = require("./polygonPerimeter");
|
|
36
|
+
Object.defineProperty(exports, "polygonPerimeter", { enumerable: true, get: function () { return polygonPerimeter_1.polygonPerimeter; } });
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.polygonPerimeter = void 0;
|
|
4
|
+
function polygonPerimeter(polygon, forceClosedPolygon = false) {
|
|
5
|
+
if (forceClosedPolygon && !polygon[0].equals(polygon.at(-1))) {
|
|
6
|
+
polygon = [...polygon];
|
|
7
|
+
polygon.push(polygon[0].clone());
|
|
8
|
+
}
|
|
9
|
+
let length = 0;
|
|
10
|
+
for (let i = 0; i < polygon.length - 1; i++) {
|
|
11
|
+
length += polygon[i].distanceTo(polygon[i + 1]);
|
|
12
|
+
}
|
|
13
|
+
return length;
|
|
14
|
+
}
|
|
15
|
+
exports.polygonPerimeter = polygonPerimeter;
|
package/esm/Polygon.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Vec2 } from "./Vec2";
|
|
2
2
|
import { Rectangle } from "./Rectangle";
|
|
3
3
|
import { BoundingBox } from "./BoundingBox";
|
|
4
|
+
import { polygonPerimeter } from "./polygonPerimeter";
|
|
5
|
+
import { isPointInPolygon } from "./isPointInPolygon";
|
|
4
6
|
export class Polygon {
|
|
5
7
|
contour;
|
|
6
8
|
holes;
|
|
@@ -84,6 +86,12 @@ export class Polygon {
|
|
|
84
86
|
this.holes?.forEach(hole => this.flipSingle(centerX, hole));
|
|
85
87
|
return this;
|
|
86
88
|
}
|
|
89
|
+
perimeter() {
|
|
90
|
+
return polygonPerimeter(this.contour);
|
|
91
|
+
}
|
|
92
|
+
containsPoint(point) {
|
|
93
|
+
return isPointInPolygon(this.contour, point) && (this.holes || []).every(hole => !isPointInPolygon(hole, point));
|
|
94
|
+
}
|
|
87
95
|
flipSingle(centerX, poly) {
|
|
88
96
|
for (const point of poly) {
|
|
89
97
|
const xDistanceToCenter = Math.abs(centerX - point.x);
|
package/esm/index.js
CHANGED
|
@@ -13,3 +13,4 @@ export { isPointInPolygon } from "./isPointInPolygon";
|
|
|
13
13
|
export { directions } from "./directions";
|
|
14
14
|
export { directions2d } from "./directions2d";
|
|
15
15
|
export { isContinuousClosedShape } from "./isContinuousClosedShape";
|
|
16
|
+
export { polygonPerimeter } from "./polygonPerimeter";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function polygonPerimeter(polygon, forceClosedPolygon = false) {
|
|
2
|
+
if (forceClosedPolygon && !polygon[0].equals(polygon.at(-1))) {
|
|
3
|
+
polygon = [...polygon];
|
|
4
|
+
polygon.push(polygon[0].clone());
|
|
5
|
+
}
|
|
6
|
+
let length = 0;
|
|
7
|
+
for (let i = 0; i < polygon.length - 1; i++) {
|
|
8
|
+
length += polygon[i].distanceTo(polygon[i + 1]);
|
|
9
|
+
}
|
|
10
|
+
return length;
|
|
11
|
+
}
|
package/package.json
CHANGED
package/src/Polygon.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import { Vec2 } from "./Vec2";
|
|
3
3
|
import { Rectangle } from "./Rectangle";
|
|
4
4
|
import { BoundingBox } from "./BoundingBox";
|
|
5
|
+
import { polygonPerimeter } from "./polygonPerimeter";
|
|
6
|
+
import { isPointInPolygon } from "./isPointInPolygon";
|
|
5
7
|
|
|
6
8
|
export class Polygon {
|
|
7
9
|
|
|
@@ -100,6 +102,14 @@ export class Polygon {
|
|
|
100
102
|
return this;
|
|
101
103
|
}
|
|
102
104
|
|
|
105
|
+
public perimeter(): number {
|
|
106
|
+
return polygonPerimeter(this.contour);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public containsPoint(point: Vec2): boolean {
|
|
110
|
+
return isPointInPolygon(this.contour, point) && (this.holes || []).every(hole => !isPointInPolygon(hole, point));
|
|
111
|
+
}
|
|
112
|
+
|
|
103
113
|
private flipSingle(centerX: number, poly: Vec2[]) {
|
|
104
114
|
for (const point of poly) {
|
|
105
115
|
const xDistanceToCenter = Math.abs(centerX - point.x);
|
package/src/index.ts
CHANGED
|
@@ -14,4 +14,5 @@ export { Point3 } from "./Point3";
|
|
|
14
14
|
export { isPointInPolygon } from "./isPointInPolygon";
|
|
15
15
|
export { directions } from "./directions";
|
|
16
16
|
export { directions2d } from "./directions2d";
|
|
17
|
-
export { isContinuousClosedShape } from "./isContinuousClosedShape";
|
|
17
|
+
export { isContinuousClosedShape } from "./isContinuousClosedShape";
|
|
18
|
+
export { polygonPerimeter } from "./polygonPerimeter";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Vec2 } from "./Vec2";
|
|
2
|
+
|
|
3
|
+
export function polygonPerimeter(polygon: Vec2[], forceClosedPolygon: boolean = false): number {
|
|
4
|
+
if (forceClosedPolygon && !polygon[0].equals(polygon.at(-1))) {
|
|
5
|
+
polygon = [...polygon];
|
|
6
|
+
polygon.push(polygon[0].clone());
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
let length = 0;
|
|
10
|
+
for (let i = 0; i < polygon.length - 1; i++) {
|
|
11
|
+
length += polygon[i].distanceTo(polygon[i + 1]);
|
|
12
|
+
}
|
|
13
|
+
return length;
|
|
14
|
+
}
|
package/types/Polygon.d.ts
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -15,3 +15,4 @@ export { isPointInPolygon } from "./isPointInPolygon";
|
|
|
15
15
|
export { directions } from "./directions";
|
|
16
16
|
export { directions2d } from "./directions2d";
|
|
17
17
|
export { isContinuousClosedShape } from "./isContinuousClosedShape";
|
|
18
|
+
export { polygonPerimeter } from "./polygonPerimeter";
|