rm-graphical-computing-node 1.0.150 → 1.0.151

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.
Files changed (2) hide show
  1. package/dist/index.mjs +88 -6
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -5939,6 +5939,73 @@ var pointInRectRegion = (point2, regions, epsilon3 = 1e-6) => {
5939
5939
  }
5940
5940
  return isInside;
5941
5941
  };
5942
+ function getRectIntersectionRatio(rect1, rect2) {
5943
+ if (!rect1 || !rect2 || rect1.length !== 4 || rect2.length !== 4) {
5944
+ return 0;
5945
+ }
5946
+ const cross3 = (a, b, c) => (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
5947
+ const polygonArea4 = (points) => {
5948
+ let area2 = 0;
5949
+ for (let i = 0; i < points.length; i++) {
5950
+ const p1 = points[i];
5951
+ const p2 = points[(i + 1) % points.length];
5952
+ area2 += p1.x * p2.y - p2.x * p1.y;
5953
+ }
5954
+ return Math.abs(area2) / 2;
5955
+ };
5956
+ const area1 = polygonArea4(rect1);
5957
+ if (area1 <= 1e-12) return 0;
5958
+ let clip = [...rect2];
5959
+ let signedArea2 = 0;
5960
+ for (let i = 0; i < 4; i++) {
5961
+ const a = clip[i];
5962
+ const b = clip[(i + 1) % 4];
5963
+ signedArea2 += a.x * b.y - b.x * a.y;
5964
+ }
5965
+ if (signedArea2 < 0) {
5966
+ clip.reverse();
5967
+ }
5968
+ let output = [...rect1];
5969
+ for (let i = 0; i < 4; i++) {
5970
+ const A = clip[i];
5971
+ const B2 = clip[(i + 1) % 4];
5972
+ const input = output;
5973
+ output = [];
5974
+ if (!input.length) break;
5975
+ const intersection = (S2, E) => {
5976
+ const dx1 = E.x - S2.x;
5977
+ const dy1 = E.y - S2.y;
5978
+ const dx2 = B2.x - A.x;
5979
+ const dy2 = B2.y - A.y;
5980
+ const denom = dx1 * dy2 - dy1 * dx2;
5981
+ if (Math.abs(denom) < 1e-12) return E.clone();
5982
+ const t = ((A.x - S2.x) * dy2 - (A.y - S2.y) * dx2) / denom;
5983
+ return new THREE3.Vector3(
5984
+ S2.x + t * dx1,
5985
+ S2.y + t * dy1,
5986
+ 0
5987
+ );
5988
+ };
5989
+ const inside = (P) => cross3(A, B2, P) >= -1e-10;
5990
+ let S = input[input.length - 1];
5991
+ for (const E of input) {
5992
+ const sInside = inside(S);
5993
+ const eInside = inside(E);
5994
+ if (eInside) {
5995
+ if (!sInside) {
5996
+ output.push(intersection(S, E));
5997
+ }
5998
+ output.push(E);
5999
+ } else if (sInside) {
6000
+ output.push(intersection(S, E));
6001
+ }
6002
+ S = E;
6003
+ }
6004
+ }
6005
+ if (output.length < 3) return 0;
6006
+ const intersectionArea = polygonArea4(output);
6007
+ return Math.max(0, Math.min(100, intersectionArea / area1 * 100));
6008
+ }
5942
6009
 
5943
6010
  // src/utils/updateLine.mjs
5944
6011
  import * as THREE4 from "three";
@@ -12499,8 +12566,8 @@ var getMergeMeaning = (allProjectionResults, wallLines, wallVerifyType, averageP
12499
12566
  let boxVecJ = null;
12500
12567
  boxVecJ = getObbLongSideDirection(cloneData.obb);
12501
12568
  let finMergeObj = false;
12502
- for (let k = j + 1; k < array.length; k++) {
12503
- if (array[k].obb == null || delData.has(k))
12569
+ for (let k = 0; k < array.length; k++) {
12570
+ if (array[k].obb == null || delData.has(k) || j == k)
12504
12571
  continue;
12505
12572
  let minKZ = 0;
12506
12573
  let maxKZ = 0;
@@ -12524,18 +12591,33 @@ var getMergeMeaning = (allProjectionResults, wallLines, wallVerifyType, averageP
12524
12591
  ) {
12525
12592
  let tol = array[k].type == "door frame" ? 0.5 : 0.5;
12526
12593
  let boxVecK = getObbLongSideDirection(array[k].obb);
12527
- let f = calculateClosePointWithOBB(array[k].points, cloneData.obb, 1);
12594
+ let obbPointsK = getOBBPoints(array[k].obb);
12595
+ let obbPointsClone = getOBBPoints(cloneData.obb);
12596
+ let f = getRectIntersectionRatio(
12597
+ [obbPointsK[0], obbPointsK[1], obbPointsK[2], obbPointsK[3]],
12598
+ [obbPointsClone[0], obbPointsClone[1], obbPointsClone[2], obbPointsClone[3]]
12599
+ );
12528
12600
  if (boxVecJ.length > 0.2 && boxVecK.length > 0.2 || f > 0.3) {
12529
12601
  let isPPPP = isParallel(boxVecJ.direction, boxVecK.direction, tol);
12530
- if ((!isPPPP || !isPPPP.parallel) && f < 0.7) {
12602
+ if ((!isPPPP || !isPPPP.parallel) && f < 70) {
12531
12603
  continue;
12532
12604
  }
12533
12605
  }
12534
12606
  }
12535
12607
  let isMerge = false;
12536
12608
  if (cloneData.type == "pipe" && !pipeIsVerticalJ) {
12537
- let f = calculateClosePointWithOBB(array[k].points, cloneData.obb);
12538
- isMerge = f > 0.3;
12609
+ let obbPointsK = getOBBPoints(array[k].obb);
12610
+ let obbPointsClone = getOBBPoints(cloneData.obb);
12611
+ let f = getRectIntersectionRatio(
12612
+ [obbPointsK[0], obbPointsK[1], obbPointsK[2], obbPointsK[3]],
12613
+ [obbPointsClone[0], obbPointsClone[1], obbPointsClone[2], obbPointsClone[3]]
12614
+ );
12615
+ const overlapHeight = Math.max(0, Math.min(array[k].maxz, cloneData.maxz) - Math.max(array[k].minz, cloneData.minz));
12616
+ let arrayKHeight = array[k].maxz - array[k].minz;
12617
+ let cloneHeight = cloneData.maxz - cloneData.minz;
12618
+ let arrayKOverlapRatio = overlapHeight / arrayKHeight;
12619
+ let cloneOverlapRatio = overlapHeight / cloneHeight;
12620
+ isMerge = f > 30 && (arrayKOverlapRatio > 0.5 || cloneOverlapRatio > 0.5);
12539
12621
  } else {
12540
12622
  isMerge = cloneData.obb.intersectsOBB(array[k].obb, 0.01);
12541
12623
  if (!isMerge)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rm-graphical-computing-node",
3
- "version": "1.0.150",
3
+ "version": "1.0.151",
4
4
  "description": "墙体/梁线/点云语义计算库(依赖 Python 与 three.js)",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",