build-dxf 0.1.160 → 0.1.162
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 +1 -1
- package/src/build.js +30 -14
- package/src/utils/algorithms/Polygon.d.ts +14 -0
package/package.json
CHANGED
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
|
-
|
|
11319
|
-
|
|
11320
|
-
|
|
11321
|
-
|
|
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
|
-
|
|
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);
|
|
@@ -24015,6 +24030,7 @@ if (typeof window !== "undefined") {
|
|
|
24015
24030
|
}
|
|
24016
24031
|
if (typeof globalThis !== "undefined") {
|
|
24017
24032
|
globalThis.Log = Log;
|
|
24033
|
+
globalThis.TEST = false;
|
|
24018
24034
|
}
|
|
24019
24035
|
async function createEditor(dom, camera, orbitControls = false, viewPermission) {
|
|
24020
24036
|
const mp = await Promise.resolve().then(() => index);
|
|
@@ -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 {};
|