build-dxf 0.1.159 → 0.1.161

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.159",
3
+ "version": "0.1.161",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
package/src/build.js CHANGED
@@ -6470,6 +6470,30 @@ class Polygon extends Array {
6470
6470
  }).filter((poly) => Math.abs(poly.area()) > 0.01);
6471
6471
  return results;
6472
6472
  }
6473
+ /** 路径偏移
6474
+ * @param poly
6475
+ * @param option
6476
+ * @returns
6477
+ */
6478
+ static offset(poly, option) {
6479
+ const {
6480
+ offsetHalfWidth,
6481
+ joinType = "jtMiter",
6482
+ endType = "etOpenButt",
6483
+ scale: scale2 = 1e5
6484
+ } = option ?? {};
6485
+ const offset = new ClipperLib.ClipperOffset(2, 0.25);
6486
+ let solutions = new ClipperLib.Paths();
6487
+ offset.AddPath(
6488
+ poly.map((p2) => p2.multiplyScalar(scale2)),
6489
+ ClipperLib.JoinType[joinType],
6490
+ ClipperLib.EndType[endType]
6491
+ );
6492
+ offset.Execute(solutions, offsetHalfWidth * scale2);
6493
+ const inv = 1 / scale2;
6494
+ poly.map((p2) => p2.multiplyScalar(inv));
6495
+ return solutions.map((solution) => solution.map((p2) => Point.from(p2).multiplyScalar(1 / scale2))).map((ps2) => new Polygon(ps2))[0];
6496
+ }
6473
6497
  }
6474
6498
  function selectLocalFileFun() {
6475
6499
  return new Promise((resolve) => {
@@ -11315,21 +11339,12 @@ class CAD {
11315
11339
  } = option ?? {};
11316
11340
  const groups = LineSegmentUtils.groupBySharedPoints(lines);
11317
11341
  const polygons = groups.flatMap((group2) => Polygon.multipleFromByLines(group2));
11318
- const offset = new ClipperLib.ClipperOffset(2, 0.25);
11319
- let solutions = new ClipperLib.Paths();
11320
- for (let i = 0; i < polygons.length; i++) {
11321
- const polygon2 = polygons[i];
11322
- polygon2.forEach((p2) => p2.multiplyScalar(scale2));
11323
- offset.AddPath(
11324
- polygon2,
11325
- ClipperLib.JoinType[joinType],
11326
- ClipperLib.EndType[endType]
11327
- );
11342
+ let offsetPolygons = polygons.map((polygon2) => Polygon.offset(polygon2, { offsetHalfWidth, scale: scale2, joinType, endType })).filter(Boolean);
11343
+ if (offsetPolygons.length > 1) {
11344
+ const [first, ...other] = offsetPolygons;
11345
+ offsetPolygons = Polygon.booleanOp(first, other, { type: "Union", scale: scale2 });
11328
11346
  }
11329
- offset.Execute(solutions, offsetHalfWidth * scale2);
11330
- solutions = solutions.map((solution) => solution.map((p2) => Point.from(p2).multiplyScalar(1 / scale2)));
11331
- solutions.forEach((solution) => {
11332
- const polygon2 = new Polygon(solution);
11347
+ offsetPolygons.forEach((polygon2) => {
11333
11348
  let lines2 = mergeChainsLine(polygon2.toLines(true));
11334
11349
  lines2.forEach((line) => line.extendAlongDirection(1e-3));
11335
11350
  lines2 = splitIntersectedLine(lines2, 1e-9);
@@ -22995,7 +23010,7 @@ function getBeamNearWallVec(line) {
22995
23010
  }
22996
23011
  }
22997
23012
  function beamSupportLine(lines, {}) {
22998
- const lsh = Quadtree.from(lines);
23013
+ const lsh = Quadtree.from(lines.filter((line) => !line.userData.isBalconyRailing));
22999
23014
  lines.forEach((line) => {
23000
23015
  if (WallHole.isBeam(line)) {
23001
23016
  const findLine = line.clone();
@@ -23425,7 +23440,9 @@ class Dxf extends Component {
23425
23440
  lines = lines.filter((line) => !line.userData.isDoor);
23426
23441
  lines = BuildGroup.doubleWall(lines);
23427
23442
  lines.push(...doors);
23443
+ TEST = true;
23428
23444
  this.cad = new CAD().usePlugin(new DxfDataPlugin(lines)).usePlugin(new DxfDrawPlugin());
23445
+ TEST = false;
23429
23446
  this.dispatchEvent({
23430
23447
  type: "cadChange",
23431
23448
  cad: this.cad,
@@ -146,5 +146,19 @@ export declare class Polygon<T = any> extends Array<Point<T>> {
146
146
  * @returns
147
147
  */
148
148
  static booleanOp(subject: Polygon | Polygon[], clips: Polygon | Polygon[], opt: BooleanOpOption): Polygon<Record<string, any>>[];
149
+ /** 路径偏移
150
+ * @param poly
151
+ * @param option
152
+ * @returns
153
+ */
154
+ static offset(poly: Polygon, option: {
155
+ offsetHalfWidth: number;
156
+ joinType?: JoinType;
157
+ endType?: EndType;
158
+ type?: string;
159
+ scale?: number;
160
+ }): Polygon<Record<string, any>>;
149
161
  }
162
+ type JoinType = "jtMiter" | "jtSquare" | "jtRound";
163
+ type EndType = "etOpenSquare" | "etOpenButt" | "etOpenRound";
150
164
  export {};