build-dxf 0.1.126 → 0.1.127

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "build-dxf",
3
- "version": "0.1.126",
3
+ "version": "0.1.127",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
package/src/build.js CHANGED
@@ -684,54 +684,71 @@ class PointSpatialHash {
684
684
  }
685
685
  return null;
686
686
  }
687
- /** 通过点,从近到远辐射查找,同一格子,不保证远近
688
- * 返回第一个满足条件的目标
687
+ /** 通过点,从近到远按圈层搜索
688
+ * 同一圈内不保证距离顺序
689
+ * 返回第一个满足条件的圈层
689
690
  */
690
- nearestSearch(point2, fn2, maxRing = 1e3) {
691
+ searchByRing(point2, fn2, maxRing = 1e3) {
692
+ let gridCount = this.map.size;
691
693
  const centerI = Math.floor(point2.x / this.gridSize);
692
694
  const centerJ = Math.floor(point2.y / this.gridSize);
693
- const set2 = this.map.get(this.getGridId(centerI, centerJ));
694
- if (set2) {
695
+ const currentCircle = [];
696
+ const appendGrid = (i, j) => {
697
+ const set2 = this.map.get(this.getGridId(i, j));
698
+ if (!set2) return;
699
+ gridCount--;
695
700
  for (const target of set2) {
696
- if (fn2(target)) return target;
701
+ currentCircle.push({
702
+ point: target.point,
703
+ userData: target.userData,
704
+ distanceSq: point2.distanceSquared(target.point)
705
+ });
697
706
  }
707
+ };
708
+ appendGrid(centerI, centerJ);
709
+ if (fn2(currentCircle, 0)) {
710
+ return currentCircle;
698
711
  }
712
+ if (gridCount === 0) return null;
699
713
  for (let r2 = 1; r2 <= maxRing; r2++) {
714
+ currentCircle.length = 0;
700
715
  const minI = centerI - r2;
701
716
  const maxI = centerI + r2;
702
717
  const minJ = centerJ - r2;
703
718
  const maxJ = centerJ + r2;
704
719
  for (let i = minI; i <= maxI; i++) {
705
- let set22 = this.map.get(this.getGridId(i, minJ));
706
- if (set22) {
707
- for (const target of set22) {
708
- if (fn2(target)) return target;
709
- }
710
- }
711
- set22 = this.map.get(this.getGridId(i, maxJ));
712
- if (set22) {
713
- for (const target of set22) {
714
- if (fn2(target)) return target;
715
- }
716
- }
720
+ appendGrid(i, minJ);
721
+ appendGrid(i, maxJ);
717
722
  }
718
723
  for (let j = minJ + 1; j < maxJ; j++) {
719
- let set22 = this.map.get(this.getGridId(minI, j));
720
- if (set22) {
721
- for (const target of set22) {
722
- if (fn2(target)) return target;
723
- }
724
- }
725
- set22 = this.map.get(this.getGridId(maxI, j));
726
- if (set22) {
727
- for (const target of set22) {
728
- if (fn2(target)) return target;
729
- }
730
- }
724
+ appendGrid(minI, j);
725
+ appendGrid(maxI, j);
726
+ }
727
+ if (fn2(currentCircle, r2)) {
728
+ return currentCircle;
731
729
  }
730
+ if (gridCount === 0) return null;
732
731
  }
733
732
  return null;
734
733
  }
734
+ /**
735
+ * @param point
736
+ * @param excludeSelf
737
+ * @returns
738
+ */
739
+ findNearest(point2, excludeSelf = true) {
740
+ let nearest = null;
741
+ this.searchByRing(point2, (circle) => {
742
+ for (const item of circle) {
743
+ if (excludeSelf && item.point === point2) continue;
744
+ if (!nearest || item.distanceSq < nearest.distanceSq) {
745
+ nearest = item;
746
+ }
747
+ }
748
+ return nearest !== null;
749
+ });
750
+ return nearest;
751
+ }
735
752
  /**
736
753
  * @param point
737
754
  */
@@ -11080,7 +11097,7 @@ function innerWallLine(lines, trajectory2) {
11080
11097
  lud.forEachPathLine((start, end, line, index2, endType, indxeList) => {
11081
11098
  temLine.start.copy(start);
11082
11099
  temLine.end.copy(end);
11083
- const wallWidth = line.userData.wallWidth ?? DEFAULT_WALL_WIDTH;
11100
+ const wallWidth = DEFAULT_WALL_WIDTH;
11084
11101
  wallWidths[index2] = wallWidth;
11085
11102
  const hw = indxeList.length ? Math.max(...indxeList.map((i) => wallWidths[i])) * 0.5 : wallWidth * 0.5;
11086
11103
  if (index2 !== 0) {
@@ -10,6 +10,11 @@ type Target<T> = {
10
10
  type NodeSet<T> = Set<Target<T>>;
11
11
  export type PvgTarget<T> = Target<T>;
12
12
  export type ResultList<T = any> = Array<Target<T>>;
13
+ export type CircleResult<T = any> = {
14
+ point: Point;
15
+ distanceSq: number;
16
+ userData?: T;
17
+ };
13
18
  export declare class PointSpatialHash<T = Record<string, any>> {
14
19
  map: Map<string, NodeSet<T>>;
15
20
  gridSize: number;
@@ -109,10 +114,17 @@ export declare class PointSpatialHash<T = Record<string, any>> {
109
114
  point: Point;
110
115
  userData: T;
111
116
  } | null;
112
- /** 通过点,从近到远辐射查找,同一格子,不保证远近
113
- * 返回第一个满足条件的目标
117
+ /** 通过点,从近到远按圈层搜索
118
+ * 同一圈内不保证距离顺序
119
+ * 返回第一个满足条件的圈层
120
+ */
121
+ searchByRing(point: Point, fn: (circle: CircleResult<T>[], circleNum: number) => boolean, maxRing?: number): CircleResult<T>[] | null;
122
+ /**
123
+ * @param point
124
+ * @param excludeSelf
125
+ * @returns
114
126
  */
115
- nearestSearch(point: Point, fn: (target: Target<T>) => boolean, maxRing?: number): Target<T> | null;
127
+ findNearest(point: Point, excludeSelf?: boolean): CircleResult<T> | null;
116
128
  /**
117
129
  * @param point
118
130
  */