rm-graphical-computing-node 1.0.35 → 1.0.37
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/dist/index.mjs +27 -15
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -8271,21 +8271,26 @@ var OBB = class _OBB extends OBB_ {
|
|
|
8271
8271
|
* @returns
|
|
8272
8272
|
*/
|
|
8273
8273
|
static fromByPath2D(path3, origin, height, obb_ = new _OBB()) {
|
|
8274
|
-
|
|
8275
|
-
|
|
8276
|
-
|
|
8277
|
-
|
|
8278
|
-
|
|
8279
|
-
|
|
8280
|
-
|
|
8281
|
-
|
|
8282
|
-
|
|
8283
|
-
|
|
8284
|
-
|
|
8285
|
-
|
|
8286
|
-
|
|
8287
|
-
|
|
8288
|
-
|
|
8274
|
+
let obb = null;
|
|
8275
|
+
try {
|
|
8276
|
+
const result = smallestSurroundingRectangleByArea({
|
|
8277
|
+
type: "Polygon",
|
|
8278
|
+
coordinates: [path3.map((p) => [p.x, p.y])]
|
|
8279
|
+
});
|
|
8280
|
+
if (!result) throw new Error("2d obb \u83B7\u53D6\u5931\u8D25");
|
|
8281
|
+
const rectangle = result.geometry.coordinates[0];
|
|
8282
|
+
const width1 = distance(rectangle[0], rectangle[1]);
|
|
8283
|
+
const width2 = distance(rectangle[1], rectangle[2]);
|
|
8284
|
+
const angle = Math.atan2(rectangle[1][1] - rectangle[0][1], rectangle[1][0] - rectangle[0][0]);
|
|
8285
|
+
vec3.set(width1, width2, height);
|
|
8286
|
+
euler.set(0, 0, angle);
|
|
8287
|
+
const [x, y] = getCenter(rectangle);
|
|
8288
|
+
origin.x = x;
|
|
8289
|
+
origin.y = y;
|
|
8290
|
+
obb = this.from(vec3, origin, euler, obb_);
|
|
8291
|
+
} catch (error) {
|
|
8292
|
+
return null;
|
|
8293
|
+
}
|
|
8289
8294
|
return obb;
|
|
8290
8295
|
}
|
|
8291
8296
|
};
|
|
@@ -8349,6 +8354,9 @@ function calculateClosePointRatioWithGrid2(pointsA, pointsB, threshold = 5e-3, m
|
|
|
8349
8354
|
}
|
|
8350
8355
|
return closePointsCount / pointsA.length;
|
|
8351
8356
|
}
|
|
8357
|
+
function isNumber2(num) {
|
|
8358
|
+
return !isNaN(num) && num !== null && !Array.isArray(num);
|
|
8359
|
+
}
|
|
8352
8360
|
function calculateClosePointWithOBB(points, box, maxCalculate = 0.5) {
|
|
8353
8361
|
let closePointsCount = 0;
|
|
8354
8362
|
let calculate = 0;
|
|
@@ -8427,6 +8435,8 @@ function getCenterAndPointHeight(points) {
|
|
|
8427
8435
|
function getObb(path3, center, h, z) {
|
|
8428
8436
|
const pathPoints = [];
|
|
8429
8437
|
for (let p = 0; p < path3.length; p++) {
|
|
8438
|
+
if (!isNumber2(path3[p][0]) || !isNumber2(path3[p][1]))
|
|
8439
|
+
continue;
|
|
8430
8440
|
pathPoints.push(new THREE8.Vector3(
|
|
8431
8441
|
path3[p][0],
|
|
8432
8442
|
path3[p][1],
|
|
@@ -8436,6 +8446,8 @@ function getObb(path3, center, h, z) {
|
|
|
8436
8446
|
if (pathPoints.length == 0)
|
|
8437
8447
|
return null;
|
|
8438
8448
|
const obb = OBB.fromByPath2D(pathPoints, center, h);
|
|
8449
|
+
if (obb == null)
|
|
8450
|
+
return null;
|
|
8439
8451
|
obb.center.z = z;
|
|
8440
8452
|
return obb;
|
|
8441
8453
|
}
|