build-dxf 0.1.90 → 0.1.92

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.90",
3
+ "version": "0.1.92",
4
4
  "description": "线段构建双线墙壁的dxf版本",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
package/src/build.js CHANGED
@@ -1753,6 +1753,9 @@ class PointVirtualGrid {
1753
1753
  point2.currentData[this.id].id = id;
1754
1754
  return true;
1755
1755
  }
1756
+ updates(point2) {
1757
+ point2.forEach((p2) => this.update(p2));
1758
+ }
1756
1759
  /**
1757
1760
  * 获取通过坐标,获取唯一网格索引
1758
1761
  * @param point
@@ -2613,6 +2616,8 @@ function mergeLineUserData(newLine, line2) {
2613
2616
  line2 = [...line2].sort((a2, b4) => a2.length(true) - b4.length(true));
2614
2617
  return line2.forEach((l) => mergeLineUserData(newLine, l));
2615
2618
  }
2619
+ if (line2.userData.isPassageEntrance === false) delete line2.userData.isPassageEntrance;
2620
+ if (newLine.userData.isPassageEntrance === false) delete newLine.userData.isPassageEntrance;
2616
2621
  const { drawWindow, passageEntrance, ...opt } = line2.userData;
2617
2622
  Object.keys(opt).forEach((key) => {
2618
2623
  if (opt[key] === void 0) delete opt[key];
@@ -6327,7 +6332,12 @@ function clippingInsertObjectDoubleWall(lines) {
6327
6332
  const startResult = startResults[0], endResult = endResults[0];
6328
6333
  if (startResult.targetLine !== endResult.targetLine) {
6329
6334
  const pl1 = startResult.targetLine.projectLineSegment(wioLine), pl2 = endResult.targetLine.projectLineSegment(wioLine), finalPl = pl1.length() > pl2.length() ? pl1 : pl2;
6330
- polygons.push(new Polygon([wioLine.start, finalPl.start, finalPl.end, wioLine.end]));
6335
+ polygons.push(new Polygon([
6336
+ wioLine.projectPoint(finalPl.start, false),
6337
+ finalPl.start,
6338
+ finalPl.end,
6339
+ wioLine.projectPoint(finalPl.end, false)
6340
+ ]));
6331
6341
  return;
6332
6342
  }
6333
6343
  polygons.push(new Polygon([wioLine.start, startResult.intersectPoint, endResult.intersectPoint, wioLine.end]));
@@ -6751,8 +6761,7 @@ function initData(lines) {
6751
6761
  }
6752
6762
  function getPeDoubleDoorCircles(lines, peDoubleDoorLines) {
6753
6763
  let allLines = [...lines, ...peDoubleDoorLines];
6754
- const notFoundLines = [];
6755
- const circlesList = [];
6764
+ let notFoundLines = [], circlesList = [];
6756
6765
  for (let i = 0; i < peDoubleDoorLines.length; i++) {
6757
6766
  const line = peDoubleDoorLines[i];
6758
6767
  let { circles } = maxiCircles.miniCircle(allLines, { circleEdges: [line] });
@@ -6798,7 +6807,9 @@ function buildDoubleWallGroup_(lines_, clearInternalLine = false) {
6798
6807
  lines_ = lines_.filter((line) => !internalEdgesSet.has(line));
6799
6808
  return lines_;
6800
6809
  }
6801
- const buildDoubleWallGroup = Object.assign(buildDoubleWallGroup_, {
6810
+ const buildDoubleWallGroup = Object.assign((lines_, clearInternalLine) => {
6811
+ return buildDoubleWallGroup_(lines_, clearInternalLine);
6812
+ }, {
6802
6813
  setTrajectory(trajectory_) {
6803
6814
  if (trajectory_) trajectory = Object.values(trajectory_);
6804
6815
  else trajectory = void 0;
@@ -6945,7 +6956,7 @@ class DoubleWallHelper {
6945
6956
  static buildGroup(lineSegments) {
6946
6957
  const otherLines = [];
6947
6958
  lineSegments = lineSegments.filter((line) => {
6948
- if (line.userData.isDoor || line.userData.isBalconyRailing || line.userData.isWindowWall || line.userData.isBayWindow) {
6959
+ if (line.userData.isDoor || line.userData.isBalconyRailing || line.userData.isBayWindowWin || line.userData.isBayWindow) {
6949
6960
  otherLines.push(line);
6950
6961
  return false;
6951
6962
  }
@@ -6991,6 +7002,9 @@ class WallGroupManager {
6991
7002
  if (fun(group)) return group;
6992
7003
  }
6993
7004
  }
7005
+ findGroupByType(type) {
7006
+ return this.findGroup((group) => group.type === type);
7007
+ }
6994
7008
  /** 查找所有符合条件的组
6995
7009
  * @param fun
6996
7010
  * @returns
@@ -7003,9 +7017,19 @@ class WallGroupManager {
7003
7017
  }
7004
7018
  return list;
7005
7019
  }
7020
+ findGroupsByType(type) {
7021
+ if (typeof type === "string") type = [type];
7022
+ const set2 = new Set(type);
7023
+ return this.findGroups((group) => set2.has(group.type));
7024
+ }
7006
7025
  static fromByLines(lineSegments) {
7007
7026
  const wallGroupManager = new WallGroupManager();
7008
7027
  const removeLines = [];
7028
+ const doubleWalls = LineGroupType.getGroupsByType(lineSegments, "doubleWall");
7029
+ doubleWalls.forEach((doubleWall) => {
7030
+ wallGroupManager.add({ type: "doubleWall", lines: doubleWall });
7031
+ removeLines.push(...doubleWall);
7032
+ });
7009
7033
  const bayWindowGroups = LineGroupType.getGroupsByType(lineSegments, "bayWindow");
7010
7034
  bayWindowGroups.forEach((bayWindowGroup) => {
7011
7035
  wallGroupManager.add({
@@ -7018,11 +7042,6 @@ class WallGroupManager {
7018
7042
  const doors = lineSegments.filter((line) => line.userData.isDoor);
7019
7043
  wallGroupManager.add({ type: "door", lines: doors });
7020
7044
  removeLines.push(...doors);
7021
- const doubleWalls = LineGroupType.getGroupsByType(lineSegments, "doubleWall");
7022
- doubleWalls.forEach((doubleWall) => {
7023
- wallGroupManager.add({ type: "doubleWall", lines: doubleWall });
7024
- removeLines.push(...doubleWall);
7025
- });
7026
7045
  const set2 = new Set(removeLines), walls = [], windowLines = [], balconyRailingLines = [];
7027
7046
  lineSegments.filter((line) => !set2.has(line)).forEach((line) => {
7028
7047
  if (line.userData.isBayWindow) return;
@@ -8379,10 +8398,9 @@ class DxfDataPlugin extends Pipeline {
8379
8398
  */
8380
8399
  static initData(cad, lines) {
8381
8400
  const wallGroupManager = WallGroupManager.fromByLines(lines);
8382
- const doubleWallGroups = wallGroupManager.findGroups((group) => group.type === "doubleWall"), balconyRailingGroups = wallGroupManager.findGroups((group) => group.type === "balconyRailing"), doorGroups = wallGroupManager.findGroups((group) => group.type === "door"), jointGroups = wallGroupManager.findGroups((group) => group.type === "wall" || group.type === "bayWindow" || group.type === "window"), doubleWalls = doubleWallGroups.map((group) => group.lines), jointLines = jointGroups.map((group) => group.lines).flat(2), { bayWindowLines, wallLines } = jointLines.reduce((opt, line) => (line.userData.isBayWindow ? opt.bayWindowLines.push(line) : opt.wallLines.push(line), opt), { bayWindowLines: [], wallLines: [] }), doorLines = doorGroups.map((group) => group.lines).flat(2), balconyRailingLines = balconyRailingGroups.map((group) => group.lines).flat(2), doubleWallsQuat = doubleWallGroups.map((group) => group.lines).flatMap((lines2) => clippingInsertObjectDoubleWall(lines2)), {
8401
+ const doubleWallGroups = wallGroupManager.findGroupsByType("doubleWall"), balconyRailingGroups = wallGroupManager.findGroupsByType("balconyRailing"), doorGroups = wallGroupManager.findGroupsByType("door"), jointGroups = wallGroupManager.findGroupsByType(["wall", "bayWindow", "window"]), doubleWalls = doubleWallGroups.map((group) => group.lines), jointLines = jointGroups.map((group) => group.lines).flat(2), { bayWindowLines, wallLines } = jointLines.reduce((opt, line) => (line.userData.isBayWindow ? opt.bayWindowLines.push(line) : opt.wallLines.push(line), opt), { bayWindowLines: [], wallLines: [] }), doorLines = doorGroups.map((group) => group.lines).flat(2), balconyRailingLines = balconyRailingGroups.map((group) => group.lines).flat(2), doubleWallsQuat = doubleWallGroups.map((group) => group.lines).flatMap((lines2) => clippingInsertObjectDoubleWall(lines2)), {
8383
8402
  window: windowLines,
8384
8403
  door,
8385
- passageEntrance,
8386
8404
  untreatedDoubleWallGroup,
8387
8405
  untreatedWall
8388
8406
  } = WallInsertObjectDrawData.handleHoleDrawData(doubleWallsQuat, wallLines, lines);
@@ -8501,9 +8519,11 @@ class BoundExt {
8501
8519
  grid.update(point2);
8502
8520
  });
8503
8521
  line.translate(wallWidth * 0.5, direction);
8522
+ grid.updates(line.points);
8504
8523
  });
8505
8524
  arrayMap.forEach((list, id) => {
8506
8525
  if (list.length >= 2) {
8526
+ if (list[0].line.isParallelTo(list[1].line, 20)) return;
8507
8527
  const p1 = list[0].line.getIntersection(list[1].line);
8508
8528
  if (p1) {
8509
8529
  list[0].point.copy(p1);
@@ -19201,7 +19221,7 @@ function stepEliminationMerge(target, _, source, oldLine) {
19201
19221
  WallInsertObject.recomputed([target]);
19202
19222
  }
19203
19223
  function linesSmoothing(lines, _) {
19204
- repetitiveTask(2, () => lines = stepElimination(lines, 0.15, stepEliminationMerge));
19224
+ repetitiveTask(2, () => lines = stepElimination(lines, 0.1, stepEliminationMerge));
19205
19225
  WallInsertObject.recomputed(lines);
19206
19226
  return lines;
19207
19227
  }
@@ -19232,6 +19252,16 @@ function shortDistanceLink(lines, radius = 0.1) {
19232
19252
  }
19233
19253
  return [...lines, ...appendLines];
19234
19254
  }
19255
+ function linkByWindow(lines, radius = 0.1) {
19256
+ const dpSet = findDiscretePoint(lines.filter((line) => !line.userData.isDoor)), pointVirtualGrid = createPointVirtualGrid(lines.filter((line) => line.userData.isBayWindow));
19257
+ for (const [point2, line] of dpSet) {
19258
+ if (line.userData.isDoor) continue;
19259
+ const list = pointVirtualGrid.queryCircle(point2, radius, true).sort((a2, b4) => a2.point.distance(point2) - b4.point.distance(point2));
19260
+ if (list.length === 0) continue;
19261
+ point2.copy(list[0].point);
19262
+ }
19263
+ return lines;
19264
+ }
19235
19265
  function preprocessing(lines) {
19236
19266
  const pointVirtualGrid = new PointVirtualGrid(), quadtree = new Quadtree(Box2.fromByLineSegment(...lines)), doors = [];
19237
19267
  lines.forEach((line) => {
@@ -19250,6 +19280,7 @@ function preprocessing(lines) {
19250
19280
  else door.userData.endIntersection = quadtree.queryPoint(door.end)[0]?.line;
19251
19281
  });
19252
19282
  lines = shortDistanceLink(lines, 0.4);
19283
+ lines = linkByWindow(lines, 0.05);
19253
19284
  pointVirtualGrid.clear();
19254
19285
  quadtree.clear();
19255
19286
  return lines;
@@ -19304,8 +19335,9 @@ function correction(lines, targettLine, option) {
19304
19335
  lines = AxisAlignCorr.start(lines, targettLine);
19305
19336
  lines = adsorption(lines, option);
19306
19337
  lines = lineSegmentClipping(lines, 1e-9);
19307
- lines = removeDangline(lines, 0.15, true);
19338
+ lines = removeDangline(lines, 0.1, false);
19308
19339
  lines = linesSmoothing(lines);
19340
+ lines = linkByWindow(lines, 0.05);
19309
19341
  let newLines = lines.filter((line) => !line.userData.isDoor);
19310
19342
  let doorLines = lines.filter((line) => line.userData.isDoor);
19311
19343
  newLines = buildBayWindowGroup(newLines, false);
@@ -19328,7 +19360,7 @@ function axisAlignCorr(lines, option, verticalReferenceLine) {
19328
19360
  lines.forEach((line) => {
19329
19361
  const id = LineGroupType.getIdByType(line, "bayWindow");
19330
19362
  if (id && line.userData.isWindow) {
19331
- line.userData.isWindowWall = true;
19363
+ line.userData.isBayWindowWin = true;
19332
19364
  }
19333
19365
  });
19334
19366
  const lineSegments = correction(lines, verticalReferenceLine, option);
@@ -19520,9 +19552,6 @@ const PRE_PROCESSOR = {
19520
19552
  /** 处理门线垂直方向有其他线段遮挡的情况
19521
19553
  */
19522
19554
  DoorSpaceHandle: doorSpaceHandle,
19523
- /** 线段平滑处理
19524
- */
19525
- LinesSmoothing: linesSmoothing,
19526
19555
  /** 移除与双线墙链接的短线段
19527
19556
  */
19528
19557
  RemoveShortDoubleWall: removeShortDoubleWall
@@ -15,7 +15,6 @@ export declare class CorrectionDxf<TEventMap extends {} = {}> extends Dxf<{} & T
15
15
  DoubleWallAlignment: typeof import('../utils/lineHandle/CadPreProcessor/doubleWallAlignment').doubleWallAlignment;
16
16
  WallHeightHandle: typeof import('../utils/lineHandle/CadPreProcessor/wallHeightHandle').wallHeightHandle;
17
17
  DoorSpaceHandle: typeof import('../utils/lineHandle/CadPreProcessor/doorSpaceHandle').doorSpaceHandle;
18
- LinesSmoothing: typeof import('../utils/lineHandle/CadPreProcessor/axisAlignCorr/linesSmoothing').linesSmoothing;
19
18
  RemoveShortDoubleWall: typeof import('../utils/lineHandle/CadPreProcessor/removeShortDoubleWall').removeShortDoubleWall;
20
19
  };
21
20
  rotateCorrCad?: CAD;
@@ -29,7 +29,6 @@ export declare class Dxf<TEventMap extends {} = {}> extends Component<{
29
29
  DoubleWallAlignment: typeof import('../utils/lineHandle/CadPreProcessor/doubleWallAlignment').doubleWallAlignment;
30
30
  WallHeightHandle: typeof import('../utils/lineHandle/CadPreProcessor/wallHeightHandle').wallHeightHandle;
31
31
  DoorSpaceHandle: typeof import('../utils/lineHandle/CadPreProcessor/doorSpaceHandle').doorSpaceHandle;
32
- LinesSmoothing: typeof import('../utils/lineHandle/CadPreProcessor/axisAlignCorr/linesSmoothing').linesSmoothing;
33
32
  RemoveShortDoubleWall: typeof import('../utils/lineHandle/CadPreProcessor/removeShortDoubleWall').removeShortDoubleWall;
34
33
  };
35
34
  width: number;
@@ -41,6 +41,7 @@ export type WallLineGlobalOption = {
41
41
  isBayWindow?: boolean;
42
42
  /** 是不是飘窗墙壁 */
43
43
  isWindowWall?: boolean;
44
+ isBayWindowWin?: boolean;
44
45
  /** 是不是阳台护栏 */
45
46
  isBalconyRailing?: boolean;
46
47
  /** 是不是门线 */
@@ -6,7 +6,6 @@ import { doubleWallAlignment } from './doubleWallAlignment';
6
6
  import { wallHeightHandle } from './wallHeightHandle';
7
7
  import { doorSpaceHandle } from './doorSpaceHandle';
8
8
  import { removeShortDoubleWall } from './removeShortDoubleWall';
9
- import { linesSmoothing } from './axisAlignCorr/linesSmoothing';
10
9
  /**
11
10
  * 默认提供的预处理函数
12
11
  */
@@ -28,9 +27,6 @@ export declare const PRE_PROCESSOR: {
28
27
  /** 处理门线垂直方向有其他线段遮挡的情况
29
28
  */
30
29
  DoorSpaceHandle: typeof doorSpaceHandle;
31
- /** 线段平滑处理
32
- */
33
- LinesSmoothing: typeof linesSmoothing;
34
30
  /** 移除与双线墙链接的短线段
35
31
  */
36
32
  RemoveShortDoubleWall: typeof removeShortDoubleWall;
@@ -7,6 +7,6 @@ import { LineUserData } from '../../../type';
7
7
  */
8
8
  export declare function buildDoubleWallGroup_(lines_: LineSegment<LineUserData>[], clearInternalLine?: boolean): LineSegment<LineUserData>[];
9
9
  /** */
10
- export declare const buildDoubleWallGroup: typeof buildDoubleWallGroup_ & {
10
+ export declare const buildDoubleWallGroup: ((lines_: LineSegment<LineUserData>[], clearInternalLine?: boolean) => LineSegment<LineUserData>[]) & {
11
11
  setTrajectory(trajectory_: Record<string, any> | undefined): void;
12
12
  };
@@ -16,10 +16,12 @@ export declare class WallGroupManager {
16
16
  * @returns
17
17
  */
18
18
  findGroup(fun: (group: IGroup) => boolean): IGroup<any> | undefined;
19
+ findGroupByType(type: string): IGroup<any> | undefined;
19
20
  /** 查找所有符合条件的组
20
21
  * @param fun
21
22
  * @returns
22
23
  */
23
24
  findGroups(fun: (group: IGroup) => boolean): IGroup<any>[];
25
+ findGroupsByType(type: string | string[]): IGroup<any>[];
24
26
  static fromByLines(lineSegments: LineSegment[]): WallGroupManager;
25
27
  }
@@ -40,6 +40,7 @@ export declare class PointVirtualGrid<T = Record<string, any>> {
40
40
  */
41
41
  removes(point: Point[]): this;
42
42
  update(point: Point): boolean;
43
+ updates(point: Point[]): void;
43
44
  /**
44
45
  * 获取通过坐标,获取唯一网格索引
45
46
  * @param point