build-dxf 0.0.20-24 → 0.0.20-26
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.d.ts +2 -0
- package/src/build.js +497 -487
- package/src/index.css +1 -1
- package/src/index3.js +853 -709
- package/src/selectLocalFile.js +3 -1
- package/src/utils/DxfSystem/components/AngleCorrectionDxf.d.ts +1 -0
- package/src/utils/DxfSystem/components/Dxf.d.ts +1 -1
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/ClippingLine.d.ts +45 -0
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/DrawDoorLine.d.ts +2 -4
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/VerticalCorrection copy.d.ts +82 -0
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/VerticalCorrection.d.ts +7 -18
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/VerticalReferenceLine.d.ts +1 -1
- package/src/utils/DxfSystem/plugin/Editor/components/Editor.d.ts +4 -1
- package/src/utils/DxfSystem/plugin/RenderPlugin/components/Renderer.d.ts +2 -0
- package/src/utils/PointVirtualGrid/index.d.ts +8 -0
package/src/build.js
CHANGED
|
@@ -4,19 +4,19 @@ import F from "clipper-lib";
|
|
|
4
4
|
import R from "dxf-writer";
|
|
5
5
|
import { OBJExporter as et } from "three/examples/jsm/exporters/OBJExporter.js";
|
|
6
6
|
import { GLTFExporter as nt } from "three/examples/jsm/exporters/GLTFExporter.js";
|
|
7
|
-
function
|
|
7
|
+
function N() {
|
|
8
8
|
return "xxxx-xxxx-4xxx-yxxx-xxxx".replace(/[xy]/g, function(y) {
|
|
9
9
|
var t = Math.random() * 16 | 0, e = y == "x" ? t : t & 3 | 8;
|
|
10
10
|
return e.toString(16);
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
class $ extends tt {
|
|
14
|
-
uuid =
|
|
14
|
+
uuid = N();
|
|
15
15
|
addEventListener(t, e, n) {
|
|
16
|
-
const { once: i = !1 } = n ?? {},
|
|
17
|
-
e(r), i &&
|
|
18
|
-
},
|
|
19
|
-
return super.addEventListener(t,
|
|
16
|
+
const { once: i = !1 } = n ?? {}, s = (r) => {
|
|
17
|
+
e(r), i && o();
|
|
18
|
+
}, o = () => this.removeEventListener(t, s);
|
|
19
|
+
return super.addEventListener(t, s), o;
|
|
20
20
|
}
|
|
21
21
|
eventRecordStack = /* @__PURE__ */ new Map();
|
|
22
22
|
addEventRecord(t, ...e) {
|
|
@@ -117,7 +117,7 @@ class it extends $ {
|
|
|
117
117
|
return e || null;
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
class
|
|
120
|
+
class f {
|
|
121
121
|
x;
|
|
122
122
|
y;
|
|
123
123
|
get X() {
|
|
@@ -207,8 +207,8 @@ class p {
|
|
|
207
207
|
* @param angle 旋转角度,单位为弧度
|
|
208
208
|
*/
|
|
209
209
|
rotate(t, e) {
|
|
210
|
-
const n = this.x - t.x, i = this.y - t.y,
|
|
211
|
-
return this.x = r + t.x, this.y =
|
|
210
|
+
const n = this.x - t.x, i = this.y - t.y, s = Math.cos(e), o = Math.sin(e), r = n * s - i * o, a = n * o + i * s;
|
|
211
|
+
return this.x = r + t.x, this.y = a + t.y, this;
|
|
212
212
|
}
|
|
213
213
|
/**
|
|
214
214
|
* 保留小数位数
|
|
@@ -233,8 +233,8 @@ class p {
|
|
|
233
233
|
* @returns
|
|
234
234
|
*/
|
|
235
235
|
normal(t) {
|
|
236
|
-
const e = this.x - t.x, n = this.y - t.y, i = Math.sqrt(e * e + n * n),
|
|
237
|
-
return new
|
|
236
|
+
const e = this.x - t.x, n = this.y - t.y, i = Math.sqrt(e * e + n * n), s = -n / i, o = e / i;
|
|
237
|
+
return new f(s, o);
|
|
238
238
|
}
|
|
239
239
|
/**
|
|
240
240
|
* 获取由传入的点到该点的单位方向向量
|
|
@@ -244,7 +244,7 @@ class p {
|
|
|
244
244
|
*/
|
|
245
245
|
direction(t) {
|
|
246
246
|
const e = this.x - t.x, n = this.y - t.y, i = Math.sqrt(e * e + n * n);
|
|
247
|
-
return i === 0 ? new
|
|
247
|
+
return i === 0 ? new f(0, 0) : new f(e / i, n / i);
|
|
248
248
|
}
|
|
249
249
|
/**
|
|
250
250
|
* 计算模长
|
|
@@ -277,10 +277,10 @@ class p {
|
|
|
277
277
|
* @returns
|
|
278
278
|
*/
|
|
279
279
|
angleBetween(t, e = "radian", n = "180") {
|
|
280
|
-
const i = this.dot(t),
|
|
281
|
-
if (
|
|
282
|
-
const r = i / (
|
|
283
|
-
return e === "radian" ? Math.acos(
|
|
280
|
+
const i = this.dot(t), s = this.magnitude(), o = t.magnitude();
|
|
281
|
+
if (s === 0 || o === 0) return 0;
|
|
282
|
+
const r = i / (s * o), a = Math.max(-1, Math.min(1, r));
|
|
283
|
+
return e === "radian" ? Math.acos(a) : e === "cos" ? a : n === "180" || this.cross(t) < 0 ? Math.acos(a) / (Math.PI / 180) : 360 - Math.acos(a) / (Math.PI / 180);
|
|
284
284
|
}
|
|
285
285
|
/** 获取向量长度
|
|
286
286
|
*/
|
|
@@ -302,7 +302,7 @@ class p {
|
|
|
302
302
|
* @returns
|
|
303
303
|
*/
|
|
304
304
|
clone() {
|
|
305
|
-
return new
|
|
305
|
+
return new f(this.x, this.y);
|
|
306
306
|
}
|
|
307
307
|
/**
|
|
308
308
|
* 克隆
|
|
@@ -319,10 +319,10 @@ class p {
|
|
|
319
319
|
};
|
|
320
320
|
}
|
|
321
321
|
static from(t) {
|
|
322
|
-
return Array.isArray(t) ? new
|
|
322
|
+
return Array.isArray(t) ? new f(t[0], t[1]) : "x" in t && "y" in t ? new f(t.x, t.y) : "X" in t && "Y" in t ? new f(t.X, t.Y) : this.zero();
|
|
323
323
|
}
|
|
324
324
|
static zero() {
|
|
325
|
-
return new
|
|
325
|
+
return new f(0, 0);
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
328
|
class v {
|
|
@@ -332,10 +332,10 @@ class v {
|
|
|
332
332
|
maxY = 0;
|
|
333
333
|
get points() {
|
|
334
334
|
return [
|
|
335
|
-
new
|
|
336
|
-
new
|
|
337
|
-
new
|
|
338
|
-
new
|
|
335
|
+
new f(this.minX, this.minY),
|
|
336
|
+
new f(this.maxX, this.minY),
|
|
337
|
+
new f(this.maxX, this.maxY),
|
|
338
|
+
new f(this.minX, this.maxY)
|
|
339
339
|
];
|
|
340
340
|
}
|
|
341
341
|
get width() {
|
|
@@ -345,7 +345,7 @@ class v {
|
|
|
345
345
|
return this.maxY - this.minY;
|
|
346
346
|
}
|
|
347
347
|
get center() {
|
|
348
|
-
return new
|
|
348
|
+
return new f(
|
|
349
349
|
this.minX + (this.maxX - this.minX) * 0.5,
|
|
350
350
|
this.minY + (this.maxY - this.minY) * 0.5
|
|
351
351
|
);
|
|
@@ -360,9 +360,9 @@ class v {
|
|
|
360
360
|
*/
|
|
361
361
|
getPaths3D(t = 0) {
|
|
362
362
|
const e = this.points, n = [];
|
|
363
|
-
return e.forEach((i,
|
|
364
|
-
const
|
|
365
|
-
n.push(i.x, i.y, t), n.push(
|
|
363
|
+
return e.forEach((i, s) => {
|
|
364
|
+
const o = e[(s + 1) % e.length];
|
|
365
|
+
n.push(i.x, i.y, t), n.push(o.x, o.y, t);
|
|
366
366
|
}), n;
|
|
367
367
|
}
|
|
368
368
|
/**
|
|
@@ -371,21 +371,21 @@ class v {
|
|
|
371
371
|
* @param line
|
|
372
372
|
*/
|
|
373
373
|
intersectLineSegment(t) {
|
|
374
|
-
const e = t.points[0], n = t.points[1], i = n.x - e.x,
|
|
375
|
-
if (i === 0 &&
|
|
374
|
+
const e = t.points[0], n = t.points[1], i = n.x - e.x, s = n.y - e.y;
|
|
375
|
+
if (i === 0 && s === 0)
|
|
376
376
|
return this.minX <= e.x && e.x <= this.maxX && this.minY <= e.y && e.y <= this.maxY;
|
|
377
|
-
let
|
|
377
|
+
let o = Number.NEGATIVE_INFINITY, r = Number.POSITIVE_INFINITY;
|
|
378
378
|
if (i !== 0) {
|
|
379
|
-
const
|
|
380
|
-
|
|
379
|
+
const a = (this.minX - e.x) / i, c = (this.maxX - e.x) / i;
|
|
380
|
+
o = Math.max(o, Math.min(a, c)), r = Math.min(r, Math.max(a, c));
|
|
381
381
|
} else if (e.x < this.minX || e.x > this.maxX)
|
|
382
382
|
return !1;
|
|
383
|
-
if (
|
|
384
|
-
const
|
|
385
|
-
|
|
383
|
+
if (s !== 0) {
|
|
384
|
+
const a = (this.minY - e.y) / s, c = (this.maxY - e.y) / s;
|
|
385
|
+
o = Math.max(o, Math.min(a, c)), r = Math.min(r, Math.max(a, c));
|
|
386
386
|
} else if (e.y < this.minY || e.y > this.maxY)
|
|
387
387
|
return !1;
|
|
388
|
-
return
|
|
388
|
+
return o <= r && o <= 1 && r >= 0;
|
|
389
389
|
}
|
|
390
390
|
/**
|
|
391
391
|
* 判断线段是在包围盒内
|
|
@@ -400,37 +400,37 @@ class v {
|
|
|
400
400
|
* @param rectangle
|
|
401
401
|
*/
|
|
402
402
|
intersectRectangle(t) {
|
|
403
|
-
const e = (
|
|
403
|
+
const e = (o) => this.minX <= o.x && o.x <= this.maxX && this.minY <= o.y && o.y <= this.maxY, n = (o) => {
|
|
404
404
|
let r = 0;
|
|
405
|
-
for (let
|
|
406
|
-
const
|
|
407
|
-
if (
|
|
408
|
-
const m = l.x !== 0 ? (
|
|
405
|
+
for (let a = 0; a < 4; a++) {
|
|
406
|
+
const c = t.points[a], h = t.points[(a + 1) % 4], l = { x: h.x - c.x, y: h.y - c.y }, d = { x: o.x - c.x, y: o.y - c.y }, p = l.x * d.y - l.y * d.x;
|
|
407
|
+
if (p === 0) {
|
|
408
|
+
const m = l.x !== 0 ? (o.x - c.x) / l.x : (o.y - c.y) / l.y;
|
|
409
409
|
if (m >= 0 && m <= 1) return !0;
|
|
410
410
|
} else {
|
|
411
|
-
const m =
|
|
411
|
+
const m = p > 0 ? 1 : -1;
|
|
412
412
|
if (r === 0 && (r = m), r !== m) return !1;
|
|
413
413
|
}
|
|
414
414
|
}
|
|
415
415
|
return !0;
|
|
416
|
-
}, i = (
|
|
416
|
+
}, i = (o, r, a, c) => {
|
|
417
417
|
const h = (u, x, w) => {
|
|
418
418
|
const S = (x.y - u.y) * (w.x - x.x) - (x.x - u.x) * (w.y - x.y);
|
|
419
419
|
return S === 0 ? 0 : S > 0 ? 1 : 2;
|
|
420
|
-
}, l = (u, x, w) => Math.min(u.x, w.x) <= x.x && x.x <= Math.max(u.x, w.x) && Math.min(u.y, w.y) <= x.y && x.y <= Math.max(u.y, w.y), d = h(
|
|
421
|
-
return !!(d !==
|
|
422
|
-
},
|
|
423
|
-
for (let
|
|
424
|
-
const r = o
|
|
425
|
-
for (let
|
|
426
|
-
const h = t.points[
|
|
427
|
-
if (i(r,
|
|
420
|
+
}, l = (u, x, w) => Math.min(u.x, w.x) <= x.x && x.x <= Math.max(u.x, w.x) && Math.min(u.y, w.y) <= x.y && x.y <= Math.max(u.y, w.y), d = h(o, r, a), p = h(o, r, c), m = h(a, c, o), g = h(a, c, r);
|
|
421
|
+
return !!(d !== p && m !== g || d === 0 && l(o, a, r) || p === 0 && l(o, c, r) || m === 0 && l(a, o, c) || g === 0 && l(a, r, c));
|
|
422
|
+
}, s = this.points;
|
|
423
|
+
for (let o = 0; o < 4; o++) {
|
|
424
|
+
const r = s[o], a = s[(o + 1) % 4];
|
|
425
|
+
for (let c = 0; c < 4; c++) {
|
|
426
|
+
const h = t.points[c], l = t.points[(c + 1) % 4];
|
|
427
|
+
if (i(r, a, h, l)) return !0;
|
|
428
428
|
}
|
|
429
429
|
}
|
|
430
|
-
for (let
|
|
431
|
-
if (e(
|
|
432
|
-
for (let
|
|
433
|
-
if (n(
|
|
430
|
+
for (let o of t.points)
|
|
431
|
+
if (e(o)) return !0;
|
|
432
|
+
for (let o of s)
|
|
433
|
+
if (n(o)) return !0;
|
|
434
434
|
return !1;
|
|
435
435
|
}
|
|
436
436
|
/**
|
|
@@ -481,8 +481,8 @@ class v {
|
|
|
481
481
|
* @returns
|
|
482
482
|
*/
|
|
483
483
|
scaleSize(t, e, n = "min") {
|
|
484
|
-
const i = t / this.width,
|
|
485
|
-
return Math[n](i,
|
|
484
|
+
const i = t / this.width, s = e / this.height;
|
|
485
|
+
return Math[n](i, s);
|
|
486
486
|
}
|
|
487
487
|
/**
|
|
488
488
|
*
|
|
@@ -519,16 +519,16 @@ class v {
|
|
|
519
519
|
);
|
|
520
520
|
}
|
|
521
521
|
}
|
|
522
|
-
function
|
|
522
|
+
function V(y) {
|
|
523
523
|
if (y === null || typeof y != "object") return y;
|
|
524
524
|
if (y instanceof Date) return new Date(y.getTime());
|
|
525
|
-
if (Array.isArray(y)) return y.map(
|
|
525
|
+
if (Array.isArray(y)) return y.map(V);
|
|
526
526
|
const t = {};
|
|
527
527
|
for (const e in y)
|
|
528
|
-
Object.prototype.hasOwnProperty.call(y, e) && (t[e] =
|
|
528
|
+
Object.prototype.hasOwnProperty.call(y, e) && (t[e] = V(y[e]));
|
|
529
529
|
return t;
|
|
530
530
|
}
|
|
531
|
-
class
|
|
531
|
+
class O {
|
|
532
532
|
points;
|
|
533
533
|
get p0() {
|
|
534
534
|
return this.points[0];
|
|
@@ -551,7 +551,7 @@ class N {
|
|
|
551
551
|
path2D(t) {
|
|
552
552
|
return this.points.flatMap((e, n) => {
|
|
553
553
|
const i = this.points[(n + 1) % this.points.length];
|
|
554
|
-
return t && t(new
|
|
554
|
+
return t && t(new f(e.x, e.y), new f(i.x, i.y)), [e.x, e.y, i.x, i.y];
|
|
555
555
|
});
|
|
556
556
|
}
|
|
557
557
|
createGeometry() {
|
|
@@ -577,16 +577,16 @@ class N {
|
|
|
577
577
|
intersectLineSegment(t) {
|
|
578
578
|
if (t.points.length !== 2)
|
|
579
579
|
throw new Error("LineSegment must have exactly 2 points");
|
|
580
|
-
const [e, n] = t.points, i = (
|
|
581
|
-
const
|
|
580
|
+
const [e, n] = t.points, i = (s, o, r, a) => {
|
|
581
|
+
const c = (g, u, x) => {
|
|
582
582
|
const w = (u.y - g.y) * (x.x - u.x) - (u.x - g.x) * (x.y - u.y);
|
|
583
583
|
return w === 0 ? 0 : w > 0 ? 1 : 2;
|
|
584
|
-
}, h = (g, u, x) => Math.min(g.x, x.x) <= u.x && u.x <= Math.max(g.x, x.x) && Math.min(g.y, x.y) <= u.y && u.y <= Math.max(g.y, x.y), l =
|
|
585
|
-
return !!(l !== d &&
|
|
584
|
+
}, h = (g, u, x) => Math.min(g.x, x.x) <= u.x && u.x <= Math.max(g.x, x.x) && Math.min(g.y, x.y) <= u.y && u.y <= Math.max(g.y, x.y), l = c(s, o, r), d = c(s, o, a), p = c(r, a, s), m = c(r, a, o);
|
|
585
|
+
return !!(l !== d && p !== m || l === 0 && h(s, r, o) || d === 0 && h(s, a, o) || p === 0 && h(r, s, a) || m === 0 && h(r, o, a));
|
|
586
586
|
};
|
|
587
|
-
for (let
|
|
588
|
-
const
|
|
589
|
-
if (i(e, n,
|
|
587
|
+
for (let s = 0; s < 4; s++) {
|
|
588
|
+
const o = this.points[s], r = this.points[(s + 1) % 4];
|
|
589
|
+
if (i(e, n, o, r))
|
|
590
590
|
return !0;
|
|
591
591
|
}
|
|
592
592
|
return !!this.containsLineSegment(t);
|
|
@@ -601,10 +601,10 @@ class N {
|
|
|
601
601
|
throw new Error("LineSegment must have exactly 2 points");
|
|
602
602
|
const e = (n) => {
|
|
603
603
|
let i = 0;
|
|
604
|
-
for (let
|
|
605
|
-
const
|
|
604
|
+
for (let s = 0; s < 4; s++) {
|
|
605
|
+
const o = this.points[s], r = this.points[(s + 1) % 4], a = { x: r.x - o.x, y: r.y - o.y }, c = { x: n.x - o.x, y: n.y - o.y }, h = a.x * c.y - a.y * c.x;
|
|
606
606
|
if (h === 0) {
|
|
607
|
-
const l =
|
|
607
|
+
const l = a.x !== 0 ? (n.x - o.x) / a.x : (n.y - o.y) / a.y;
|
|
608
608
|
if (l >= 0 && l <= 1) return !0;
|
|
609
609
|
} else {
|
|
610
610
|
const l = h > 0 ? 1 : -1;
|
|
@@ -623,24 +623,24 @@ class N {
|
|
|
623
623
|
*/
|
|
624
624
|
intersectRectangle(t) {
|
|
625
625
|
const e = [];
|
|
626
|
-
for (let
|
|
627
|
-
const
|
|
628
|
-
e.push(
|
|
626
|
+
for (let s = 0; s < 4; s++) {
|
|
627
|
+
const o = this.points[s], r = this.points[(s + 1) % 4];
|
|
628
|
+
e.push(o.normal(r));
|
|
629
629
|
}
|
|
630
|
-
for (let
|
|
631
|
-
const
|
|
632
|
-
e.push(
|
|
630
|
+
for (let s = 0; s < 4; s++) {
|
|
631
|
+
const o = t.points[s], r = t.points[(s + 1) % 4];
|
|
632
|
+
e.push(o.normal(r));
|
|
633
633
|
}
|
|
634
|
-
function n(
|
|
635
|
-
const r =
|
|
634
|
+
function n(s, o) {
|
|
635
|
+
const r = s.points.map((a) => a.dot(o));
|
|
636
636
|
return [Math.min(...r), Math.max(...r)];
|
|
637
637
|
}
|
|
638
|
-
function i(
|
|
639
|
-
return
|
|
638
|
+
function i(s, o) {
|
|
639
|
+
return s[0] < o[1] && o[0] < s[1];
|
|
640
640
|
}
|
|
641
|
-
for (const
|
|
642
|
-
const
|
|
643
|
-
if (!i(
|
|
641
|
+
for (const s of e) {
|
|
642
|
+
const o = n(this, s), r = n(t, s);
|
|
643
|
+
if (!i(o, r))
|
|
644
644
|
return !1;
|
|
645
645
|
}
|
|
646
646
|
return !0;
|
|
@@ -652,7 +652,7 @@ class N {
|
|
|
652
652
|
containsPoint(t) {
|
|
653
653
|
let e = 0, n = 0;
|
|
654
654
|
for (let i = 0; i < 4; i++) {
|
|
655
|
-
const
|
|
655
|
+
const s = this.points[i], o = this.points[(i + 1) % 4], r = (o.x - s.x) * (t.y - s.y) - (o.y - s.y) * (t.x - s.x);
|
|
656
656
|
if (r > 0) e++;
|
|
657
657
|
else if (r < 0) n++;
|
|
658
658
|
else return !1;
|
|
@@ -665,8 +665,8 @@ class N {
|
|
|
665
665
|
*/
|
|
666
666
|
toBox() {
|
|
667
667
|
let t = 1 / 0, e = -1 / 0, n = 1 / 0, i = -1 / 0;
|
|
668
|
-
return this.points.forEach((
|
|
669
|
-
e = Math.max(
|
|
668
|
+
return this.points.forEach((s) => {
|
|
669
|
+
e = Math.max(s.x, e), t = Math.min(s.x, t), i = Math.max(s.x, i), n = Math.min(s.x, n);
|
|
670
670
|
}), new v(t, e, n, i);
|
|
671
671
|
}
|
|
672
672
|
/**
|
|
@@ -676,21 +676,21 @@ class N {
|
|
|
676
676
|
* @returns
|
|
677
677
|
*/
|
|
678
678
|
static fromByLineSegment(t, e = 0.1, n = !1, i = 0.5) {
|
|
679
|
-
const
|
|
680
|
-
return new
|
|
681
|
-
new
|
|
682
|
-
new
|
|
683
|
-
new
|
|
684
|
-
new
|
|
679
|
+
const s = t.points[0], o = t.points[1], r = o.normal(s), a = n ? o.direction(s).mutiplyScalar(e * i) : f.zero(), c = n ? s.direction(o).mutiplyScalar(e * i) : f.zero(), h = r.x * e * 0.5, l = r.y * e * 0.5;
|
|
680
|
+
return new O([
|
|
681
|
+
new f(s.x + h, s.y + l).add(c),
|
|
682
|
+
new f(o.x + h, o.y + l).add(a),
|
|
683
|
+
new f(o.x - h, o.y - l).add(a),
|
|
684
|
+
new f(s.x - h, s.y - l).add(c)
|
|
685
685
|
]);
|
|
686
686
|
}
|
|
687
687
|
}
|
|
688
688
|
class L {
|
|
689
|
-
points = [new
|
|
689
|
+
points = [new f(), new f()];
|
|
690
690
|
userData = {};
|
|
691
691
|
line;
|
|
692
692
|
get center() {
|
|
693
|
-
return new
|
|
693
|
+
return new f(
|
|
694
694
|
this.points[0].x + (this.points[1].x - this.points[0].x) * 0.5,
|
|
695
695
|
this.points[0].y + (this.points[1].y - this.points[0].y) * 0.5
|
|
696
696
|
);
|
|
@@ -701,7 +701,7 @@ class L {
|
|
|
701
701
|
get end() {
|
|
702
702
|
return this.points[1];
|
|
703
703
|
}
|
|
704
|
-
constructor(t = new
|
|
704
|
+
constructor(t = new f(), e = new f()) {
|
|
705
705
|
this.points = [t, e];
|
|
706
706
|
}
|
|
707
707
|
set(t, e) {
|
|
@@ -770,15 +770,15 @@ class L {
|
|
|
770
770
|
* @returns {Rectangle}
|
|
771
771
|
*/
|
|
772
772
|
expandToRectangle(t = 0.1, e = "all") {
|
|
773
|
-
const n = this.start, i = this.end,
|
|
773
|
+
const n = this.start, i = this.end, s = i.normal(n), o = e === "bothSides" ? f.zero() : i.direction(n).mutiplyScalar(t * 0.5), r = e === "bothSides" ? f.zero() : n.direction(i).mutiplyScalar(t * 0.5), a = s.x * t * 0.5, c = s.y * t * 0.5, h = [
|
|
774
774
|
// 第一条线
|
|
775
|
-
new
|
|
776
|
-
new
|
|
775
|
+
new f(n.x + a, n.y + c).add(r),
|
|
776
|
+
new f(i.x + a, i.y + c).add(o),
|
|
777
777
|
// 第二条线
|
|
778
|
-
new
|
|
779
|
-
new
|
|
778
|
+
new f(n.x - a, n.y - c).add(r),
|
|
779
|
+
new f(i.x - a, i.y - c).add(o)
|
|
780
780
|
];
|
|
781
|
-
return new
|
|
781
|
+
return new O([0, 1, 3, 2].map((l) => h[l]));
|
|
782
782
|
}
|
|
783
783
|
/**
|
|
784
784
|
* 计算线段的长度
|
|
@@ -815,24 +815,24 @@ class L {
|
|
|
815
815
|
projectLineSegment(t) {
|
|
816
816
|
if (t.points.length !== 2 || this.points.length !== 2)
|
|
817
817
|
throw new Error("每条线段必须由两个点定义");
|
|
818
|
-
const [e, n] = t.points, [i,
|
|
819
|
-
if (
|
|
818
|
+
const [e, n] = t.points, [i, s] = this.points, o = new f(s.x - i.x, s.y - i.y);
|
|
819
|
+
if (o.x === 0 && o.y === 0)
|
|
820
820
|
throw new Error("投影目标线段的两个点不能重合");
|
|
821
821
|
const r = (m) => {
|
|
822
|
-
const g = new
|
|
823
|
-
return new
|
|
822
|
+
const g = new f(m.x - i.x, m.y - i.y), u = o.x * o.x + o.y * o.y, w = (g.x * o.x + g.y * o.y) / u, S = i.x + w * o.x, b = i.y + w * o.y;
|
|
823
|
+
return new f(S, b);
|
|
824
824
|
};
|
|
825
|
-
let
|
|
825
|
+
let a = r(e), c = r(n);
|
|
826
826
|
const h = (m) => {
|
|
827
|
-
const g = new
|
|
828
|
-
return (g.x *
|
|
827
|
+
const g = new f(m.x - i.x, m.y - i.y), u = o.x * o.x + o.y * o.y;
|
|
828
|
+
return (g.x * o.x + g.y * o.y) / u;
|
|
829
829
|
};
|
|
830
|
-
let l = h(
|
|
831
|
-
const
|
|
832
|
-
const g = Math.max(0, Math.min(1, m)), u = i.x + g *
|
|
833
|
-
return new
|
|
830
|
+
let l = h(a), d = h(c);
|
|
831
|
+
const p = (m) => {
|
|
832
|
+
const g = Math.max(0, Math.min(1, m)), u = i.x + g * o.x, x = i.y + g * o.y;
|
|
833
|
+
return new f(u, x);
|
|
834
834
|
};
|
|
835
|
-
return (l < 0 || l > 1) && (
|
|
835
|
+
return (l < 0 || l > 1) && (a = p(l)), (d < 0 || d > 1) && (c = p(d)), a.x === c.x && a.y === c.y ? new L(a, a) : new L(a, c);
|
|
836
836
|
}
|
|
837
837
|
/**
|
|
838
838
|
* 计算一条线段在另一条直线上的投影
|
|
@@ -841,34 +841,34 @@ class L {
|
|
|
841
841
|
* @returns 投影并裁剪后的线段
|
|
842
842
|
*/
|
|
843
843
|
projectPoint(t, e = !0) {
|
|
844
|
-
const [n, i] = this.points,
|
|
845
|
-
if (
|
|
844
|
+
const [n, i] = this.points, s = new f(i.x - n.x, i.y - n.y);
|
|
845
|
+
if (s.x === 0 && s.y === 0)
|
|
846
846
|
throw new Error("投影目标线段的两个点不能重合");
|
|
847
847
|
let r = ((h) => {
|
|
848
|
-
const l = new
|
|
849
|
-
return new
|
|
848
|
+
const l = new f(h.x - n.x, h.y - n.y), d = s.x * s.x + s.y * s.y, m = (l.x * s.x + l.y * s.y) / d, g = n.x + m * s.x, u = n.y + m * s.y;
|
|
849
|
+
return new f(g, u);
|
|
850
850
|
})(t);
|
|
851
851
|
if (!e) return r;
|
|
852
|
-
let
|
|
853
|
-
const l = new
|
|
854
|
-
return (l.x *
|
|
852
|
+
let c = ((h) => {
|
|
853
|
+
const l = new f(h.x - n.x, h.y - n.y), d = s.x * s.x + s.y * s.y;
|
|
854
|
+
return (l.x * s.x + l.y * s.y) / d;
|
|
855
855
|
})(r);
|
|
856
|
-
return
|
|
856
|
+
return c < 0 || c > 1 ? null : r;
|
|
857
857
|
}
|
|
858
858
|
/**
|
|
859
859
|
* 判断线段是否与另一条线段相交(包含共用端点或部分重合的情况)
|
|
860
860
|
* @param line
|
|
861
861
|
*/
|
|
862
862
|
intersectLineSegment(t) {
|
|
863
|
-
const e = this.start, n = this.end, i = t.start,
|
|
864
|
-
function
|
|
865
|
-
return (
|
|
863
|
+
const e = this.start, n = this.end, i = t.start, s = t.end;
|
|
864
|
+
function o(d, p, m) {
|
|
865
|
+
return (p.x - d.x) * (m.y - d.y) - (p.y - d.y) * (m.x - d.x);
|
|
866
866
|
}
|
|
867
|
-
function r(d,
|
|
868
|
-
return Math.min(
|
|
867
|
+
function r(d, p, m) {
|
|
868
|
+
return Math.min(p.x, m.x) - 1e-10 <= d.x && d.x <= Math.max(p.x, m.x) + 1e-10 && Math.min(p.y, m.y) - 1e-10 <= d.y && d.y <= Math.max(p.y, m.y) + 1e-10;
|
|
869
869
|
}
|
|
870
|
-
const
|
|
871
|
-
return !!(
|
|
870
|
+
const a = o(e, n, i), c = o(e, n, s), h = o(i, s, e), l = o(i, s, n);
|
|
871
|
+
return !!(a * c < 0 && h * l < 0 || Math.abs(a) < 1e-10 && r(i, e, n) || Math.abs(c) < 1e-10 && r(s, e, n) || Math.abs(h) < 1e-10 && r(e, i, s) || Math.abs(l) < 1e-10 && r(n, i, s));
|
|
872
872
|
}
|
|
873
873
|
/**
|
|
874
874
|
* 获取交点
|
|
@@ -876,11 +876,11 @@ class L {
|
|
|
876
876
|
* @returns
|
|
877
877
|
*/
|
|
878
878
|
getIntersection(t) {
|
|
879
|
-
const e = this.start, n = this.end, i = t.start,
|
|
880
|
-
if (Math.abs(
|
|
879
|
+
const e = this.start, n = this.end, i = t.start, s = t.end, o = (e.x - n.x) * (i.y - s.y) - (e.y - n.y) * (i.x - s.x);
|
|
880
|
+
if (Math.abs(o) < 1e-10)
|
|
881
881
|
return null;
|
|
882
|
-
const r = ((e.x - i.x) * (i.y -
|
|
883
|
-
return new
|
|
882
|
+
const r = ((e.x - i.x) * (i.y - s.y) - (e.y - i.y) * (i.x - s.x)) / o, a = e.x + r * (n.x - e.x), c = e.y + r * (n.y - e.y);
|
|
883
|
+
return new f(a, c);
|
|
884
884
|
}
|
|
885
885
|
/**
|
|
886
886
|
* 获取两条线段夹角
|
|
@@ -918,15 +918,15 @@ class L {
|
|
|
918
918
|
* @returns
|
|
919
919
|
*/
|
|
920
920
|
areLinesCoincident(t) {
|
|
921
|
-
const e = this.start, n = this.end, i = t.start,
|
|
922
|
-
return !isFinite(
|
|
921
|
+
const e = this.start, n = this.end, i = t.start, s = t.end, o = (n.y - e.y) / (n.x - e.x), r = e.y - o * e.x, a = (s.y - i.y) / (s.x - i.x), c = i.y - a * i.x;
|
|
922
|
+
return !isFinite(o) && !isFinite(a) ? e.x === i.x && n.x === i.x : Math.abs(o - a) < 1e-3 && Math.abs(r - c) < 1e-3;
|
|
923
923
|
}
|
|
924
924
|
clone() {
|
|
925
925
|
const t = new L(
|
|
926
926
|
this.points[0].clone(),
|
|
927
927
|
this.points[1].clone()
|
|
928
928
|
);
|
|
929
|
-
return t.userData =
|
|
929
|
+
return t.userData = { ...this.userData }, t;
|
|
930
930
|
}
|
|
931
931
|
}
|
|
932
932
|
async function G(y, t = !0) {
|
|
@@ -1045,29 +1045,29 @@ class X extends j {
|
|
|
1045
1045
|
async set(t, e = this.width, n = this.scale) {
|
|
1046
1046
|
if (typeof t == "string")
|
|
1047
1047
|
if (typeof global < "u") {
|
|
1048
|
-
const { default:
|
|
1048
|
+
const { default: o } = await import(
|
|
1049
1049
|
/* @vite-ignore */
|
|
1050
1050
|
"fs"
|
|
1051
|
-
), r =
|
|
1052
|
-
return this.set(
|
|
1051
|
+
), r = o.readFileSync(t), a = JSON.parse(r.toString("utf-8"));
|
|
1052
|
+
return this.set(a, e, n);
|
|
1053
1053
|
} else
|
|
1054
1054
|
throw new Error("非node环境不允许使用路径");
|
|
1055
1055
|
this.scale = n, this.width = e, this.originalData = t, this.lineSegments.length = 0;
|
|
1056
1056
|
const i = [];
|
|
1057
|
-
this.data = t.map(({ start:
|
|
1058
|
-
i.push(
|
|
1057
|
+
this.data = t.map(({ start: s, end: o, insetionArr: r, isDoor: a = !1, ...c }, h) => {
|
|
1058
|
+
i.push(s.z ?? 0, o.z ?? 0);
|
|
1059
1059
|
const l = new L(
|
|
1060
|
-
|
|
1061
|
-
|
|
1060
|
+
f.from(s).mutiplyScalar(n),
|
|
1061
|
+
f.from(o).mutiplyScalar(n)
|
|
1062
1062
|
);
|
|
1063
|
-
return l.userData = { isDoor:
|
|
1063
|
+
return l.userData = { isDoor: a, ...c }, this.lineSegments.push(l), [
|
|
1064
1064
|
l.points[0],
|
|
1065
1065
|
l.points[1],
|
|
1066
1066
|
(r ?? []).map((d) => d.index),
|
|
1067
|
-
|
|
1067
|
+
a,
|
|
1068
1068
|
h
|
|
1069
1069
|
];
|
|
1070
|
-
}), this.originalZAverage = i.reduce((
|
|
1070
|
+
}), this.originalZAverage = i.reduce((s, o) => s + o, 0) / i.length, this.computedOriginalSize(t, this.originalBox), this.dispatchEvent({
|
|
1071
1071
|
type: "setDta",
|
|
1072
1072
|
originalData: this.originalData,
|
|
1073
1073
|
data: this.data
|
|
@@ -1081,18 +1081,18 @@ class X extends j {
|
|
|
1081
1081
|
* @returns
|
|
1082
1082
|
*/
|
|
1083
1083
|
createGroups() {
|
|
1084
|
-
const t = [], e = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Map(),
|
|
1085
|
-
const [
|
|
1086
|
-
if (e.add(
|
|
1087
|
-
return i.has(
|
|
1088
|
-
r.push([
|
|
1089
|
-
e.has(
|
|
1084
|
+
const t = [], e = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Map(), s = (o, r, a = -1) => {
|
|
1085
|
+
const [c, h, l, d] = this.data[o];
|
|
1086
|
+
if (e.add(o), d)
|
|
1087
|
+
return i.has(o) || i.set(o, []), i.get(o)?.push(a), n.add(this.data[o]);
|
|
1088
|
+
r.push([c, h]), l.forEach((p) => {
|
|
1089
|
+
e.has(p) || s(p, r, o);
|
|
1090
1090
|
});
|
|
1091
1091
|
};
|
|
1092
|
-
return this.data.forEach((
|
|
1092
|
+
return this.data.forEach((o, r) => {
|
|
1093
1093
|
if (!e.has(r)) {
|
|
1094
|
-
const
|
|
1095
|
-
|
|
1094
|
+
const a = [];
|
|
1095
|
+
s(r, a), t.push(a);
|
|
1096
1096
|
}
|
|
1097
1097
|
}), this.doors = [...n], this.pointsGroups = t, t;
|
|
1098
1098
|
}
|
|
@@ -1102,8 +1102,8 @@ class X extends j {
|
|
|
1102
1102
|
* @returns
|
|
1103
1103
|
*/
|
|
1104
1104
|
computedSize() {
|
|
1105
|
-
const t = this.pointsGroups.flatMap((r) => r.flatMap((
|
|
1106
|
-
return this.box.set(n, i,
|
|
1105
|
+
const t = this.pointsGroups.flatMap((r) => r.flatMap((a) => [a[0].x, a[1].x])), e = this.pointsGroups.flatMap((r) => r.flatMap((a) => [a[0].y, a[1].y])), n = Math.min(...t), i = Math.min(...e), s = Math.max(...t), o = Math.max(...e);
|
|
1106
|
+
return this.box.set(n, i, s, o), this.box;
|
|
1107
1107
|
}
|
|
1108
1108
|
/** 线路拓扑
|
|
1109
1109
|
* @description 处理线路拓扑,使线路有序链接,形成长路径
|
|
@@ -1111,20 +1111,20 @@ class X extends j {
|
|
|
1111
1111
|
*/
|
|
1112
1112
|
lineTopology(t) {
|
|
1113
1113
|
const e = [];
|
|
1114
|
-
function n(
|
|
1115
|
-
const [r,
|
|
1116
|
-
e[
|
|
1117
|
-
for (let
|
|
1118
|
-
const [h, l] = t[
|
|
1119
|
-
if (!e[
|
|
1120
|
-
return n(
|
|
1114
|
+
function n(s, o) {
|
|
1115
|
+
const [r, a] = t[s];
|
|
1116
|
+
e[s] = !0, o.push(a);
|
|
1117
|
+
for (let c = 0; c < t.length; c++) {
|
|
1118
|
+
const [h, l] = t[c];
|
|
1119
|
+
if (!e[c] && Math.abs(a.x - h.x) < 1e-6 && Math.abs(a.y - h.y) < 1e-6)
|
|
1120
|
+
return n(c, o);
|
|
1121
1121
|
}
|
|
1122
1122
|
}
|
|
1123
1123
|
const i = [];
|
|
1124
|
-
for (let
|
|
1125
|
-
if (!e[
|
|
1126
|
-
const
|
|
1127
|
-
n(
|
|
1124
|
+
for (let s = 0; s < t.length; s++)
|
|
1125
|
+
if (!e[s]) {
|
|
1126
|
+
const o = [t[s][0]];
|
|
1127
|
+
n(s, o), i.push(o);
|
|
1128
1128
|
}
|
|
1129
1129
|
return i;
|
|
1130
1130
|
}
|
|
@@ -1139,8 +1139,8 @@ class X extends j {
|
|
|
1139
1139
|
}
|
|
1140
1140
|
const n = [t[0]];
|
|
1141
1141
|
for (let i = 1; i < t.length; i++) {
|
|
1142
|
-
const
|
|
1143
|
-
|
|
1142
|
+
const s = t[i], o = t[i - 1];
|
|
1143
|
+
o.includedAngle(s) < e ? o.end.copy(s.end) : n.push(s);
|
|
1144
1144
|
}
|
|
1145
1145
|
return n;
|
|
1146
1146
|
}
|
|
@@ -1151,17 +1151,17 @@ class X extends j {
|
|
|
1151
1151
|
if (t.length < 3) return t;
|
|
1152
1152
|
const e = [t[0]];
|
|
1153
1153
|
for (let n = 1; n < t.length; n++) {
|
|
1154
|
-
const i = t[n - 1],
|
|
1155
|
-
if (i.distance(
|
|
1154
|
+
const i = t[n - 1], s = t[n];
|
|
1155
|
+
if (i.distance(s) < this.width * 0.5) {
|
|
1156
1156
|
let r = 0;
|
|
1157
|
-
for (let
|
|
1158
|
-
const
|
|
1159
|
-
if (
|
|
1157
|
+
for (let a = n + 1; a < t.length; a++) {
|
|
1158
|
+
const c = t[a - 1], h = t[a];
|
|
1159
|
+
if (c.distance(h) < this.width * 0.8) r++;
|
|
1160
1160
|
else break;
|
|
1161
1161
|
}
|
|
1162
|
-
r === 0 && n + r === t.length - 1 || n == 1 && r === 1 || (r === 3 ? (e.push(t[n + 1]), n += r) : r === 5 ? (e.push(t[n + 2]), n += r) : e.push(
|
|
1162
|
+
r === 0 && n + r === t.length - 1 || n == 1 && r === 1 || (r === 3 ? (e.push(t[n + 1]), n += r) : r === 5 ? (e.push(t[n + 2]), n += r) : e.push(s));
|
|
1163
1163
|
} else
|
|
1164
|
-
e.push(
|
|
1164
|
+
e.push(s);
|
|
1165
1165
|
}
|
|
1166
1166
|
return e;
|
|
1167
1167
|
}
|
|
@@ -1172,26 +1172,26 @@ class X extends j {
|
|
|
1172
1172
|
*/
|
|
1173
1173
|
lineSegmentStraightening(t) {
|
|
1174
1174
|
for (let i = 0; i < t.length; i++) {
|
|
1175
|
-
const
|
|
1176
|
-
if (
|
|
1175
|
+
const s = t[i], o = t[(i + 1) % t.length];
|
|
1176
|
+
if (s.distance(o) > this.shortLine) {
|
|
1177
1177
|
t.push(...t.slice(0, i + 1)), t.splice(0, i + 1);
|
|
1178
1178
|
break;
|
|
1179
1179
|
}
|
|
1180
1180
|
}
|
|
1181
1181
|
const e = this.mergeSameDirectionLine(k(t)), n = [e[0]];
|
|
1182
1182
|
for (let i = 1; i < e.length; i++) {
|
|
1183
|
-
const
|
|
1184
|
-
if (
|
|
1185
|
-
n.push(
|
|
1183
|
+
const s = e[i], o = e[(e.length + i - 1) % e.length];
|
|
1184
|
+
if (s.length() > this.width * 0.9) {
|
|
1185
|
+
n.push(s);
|
|
1186
1186
|
continue;
|
|
1187
1187
|
}
|
|
1188
1188
|
const r = e[i + 1];
|
|
1189
1189
|
if (r && r.length() > this.width * 0.9) {
|
|
1190
|
-
n.push(
|
|
1190
|
+
n.push(s), n.push(r), i = i + 1;
|
|
1191
1191
|
continue;
|
|
1192
1192
|
}
|
|
1193
|
-
const
|
|
1194
|
-
|
|
1193
|
+
const a = e[i + 2];
|
|
1194
|
+
a && o.includedAngle(a) < 2 ? (i = i + 2, n.push(a)) : n.push(s);
|
|
1195
1195
|
}
|
|
1196
1196
|
return n.length > 3 ? J(this.mergeSameDirectionLine(n)) : [];
|
|
1197
1197
|
}
|
|
@@ -1201,24 +1201,24 @@ class X extends j {
|
|
|
1201
1201
|
* @param path
|
|
1202
1202
|
*/
|
|
1203
1203
|
removeShortLine(t, e = this.shortLine) {
|
|
1204
|
-
const n = k(t), i = [],
|
|
1205
|
-
for (let
|
|
1206
|
-
const r = n[
|
|
1207
|
-
if (
|
|
1204
|
+
const n = k(t), i = [], s = Math.PI / 180;
|
|
1205
|
+
for (let o = 0; o < n.length; o++) {
|
|
1206
|
+
const r = n[o], a = r.length(), c = o;
|
|
1207
|
+
if (a > e || i.length === 0) {
|
|
1208
1208
|
i.push(r);
|
|
1209
1209
|
continue;
|
|
1210
1210
|
}
|
|
1211
|
-
let h = n[++
|
|
1211
|
+
let h = n[++o];
|
|
1212
1212
|
const l = i[i.length - 1], d = l.direction();
|
|
1213
|
-
for (;
|
|
1214
|
-
const m = d.angleBetween(h.direction()) /
|
|
1213
|
+
for (; o < n.length; ) {
|
|
1214
|
+
const m = d.angleBetween(h.direction()) / s;
|
|
1215
1215
|
if (h.length() <= e || m < 4 || m > 176)
|
|
1216
|
-
h = n[++
|
|
1216
|
+
h = n[++o];
|
|
1217
1217
|
else break;
|
|
1218
1218
|
}
|
|
1219
1219
|
if (!h) continue;
|
|
1220
|
-
const
|
|
1221
|
-
if (l.length() >
|
|
1220
|
+
const p = n[o - 1];
|
|
1221
|
+
if (l.length() > p.length()) {
|
|
1222
1222
|
const m = l.getIntersection(h);
|
|
1223
1223
|
if (m) {
|
|
1224
1224
|
const g = l.points[1].clone(), u = h.points[0].clone();
|
|
@@ -1227,7 +1227,7 @@ class X extends j {
|
|
|
1227
1227
|
l.points[1].copy(h.points[0]);
|
|
1228
1228
|
i.push(h);
|
|
1229
1229
|
} else
|
|
1230
|
-
|
|
1230
|
+
o = c;
|
|
1231
1231
|
}
|
|
1232
1232
|
return i.length > 3 ? J(i) : [];
|
|
1233
1233
|
}
|
|
@@ -1236,12 +1236,12 @@ class X extends j {
|
|
|
1236
1236
|
*/
|
|
1237
1237
|
lineOffset(t = X.EndType.etOpenSquare, e = X.JoinType.jtMiter, n = 1e4) {
|
|
1238
1238
|
let i = new F.Paths();
|
|
1239
|
-
const
|
|
1240
|
-
return this.pointsGroups.forEach((
|
|
1241
|
-
const r = this.lineTopology(
|
|
1242
|
-
|
|
1243
|
-
}),
|
|
1244
|
-
let r =
|
|
1239
|
+
const s = new F.ClipperOffset(20, 0.25);
|
|
1240
|
+
return this.pointsGroups.forEach((o) => {
|
|
1241
|
+
const r = this.lineTopology(o).map((a) => a.map((c) => c.clone().mutiplyScalar(n)));
|
|
1242
|
+
s.AddPaths(r, e, t);
|
|
1243
|
+
}), s.Execute(i, this.width / 2 * n), this.wallsGroup = i.map((o) => {
|
|
1244
|
+
let r = o.map((a) => f.from(a).divisionScalar(n));
|
|
1245
1245
|
return r = this.lineSegmentStraightening(r), t == X.EndType.etOpenSquare && (r = this.squareRemoveBurr(r)), r = this.removeShortLine(r), r;
|
|
1246
1246
|
}), this.dispatchEvent({
|
|
1247
1247
|
type: "lineOffset",
|
|
@@ -1254,9 +1254,9 @@ class X extends j {
|
|
|
1254
1254
|
to3DArray(t, e = this.originalZAverage) {
|
|
1255
1255
|
const n = [];
|
|
1256
1256
|
return this.wallsGroup.forEach((i) => {
|
|
1257
|
-
for (let
|
|
1258
|
-
const
|
|
1259
|
-
n.push(
|
|
1257
|
+
for (let s = 0; s < i.length; s++) {
|
|
1258
|
+
const o = i[s], r = s === i.length - 1 ? 0 : s + 1, a = i[r];
|
|
1259
|
+
n.push(o.X * t, o.Y * t, e, a.X * t, a.Y * t, e);
|
|
1260
1260
|
}
|
|
1261
1261
|
}), new Float32Array(n);
|
|
1262
1262
|
}
|
|
@@ -1267,11 +1267,11 @@ class X extends j {
|
|
|
1267
1267
|
* @returns
|
|
1268
1268
|
*/
|
|
1269
1269
|
getArcAngleRange(t, e, n) {
|
|
1270
|
-
const i = e.x - t.x,
|
|
1271
|
-
let
|
|
1272
|
-
|
|
1270
|
+
const i = e.x - t.x, s = e.y - t.y, o = n.x - t.x, r = n.y - t.y;
|
|
1271
|
+
let a = Math.atan2(s, i), c = Math.atan2(r, o);
|
|
1272
|
+
a = a < 0 ? a + 2 * Math.PI : a, c = c < 0 ? c + 2 * Math.PI : c;
|
|
1273
1273
|
let h, l;
|
|
1274
|
-
return Math.abs(
|
|
1274
|
+
return Math.abs(c - a) <= Math.PI ? (h = Math.min(a, c), l = Math.max(a, c)) : (h = Math.max(a, c), l = Math.min(a, c) + 2 * Math.PI), [h / (Math.PI / 180), l / (Math.PI / 180)];
|
|
1275
1275
|
}
|
|
1276
1276
|
/**
|
|
1277
1277
|
* 转为绘制数据
|
|
@@ -1288,62 +1288,62 @@ class X extends j {
|
|
|
1288
1288
|
scale: e
|
|
1289
1289
|
};
|
|
1290
1290
|
let i = "white";
|
|
1291
|
-
function
|
|
1292
|
-
n.line.push([
|
|
1291
|
+
function s(c, h) {
|
|
1292
|
+
n.line.push([c.X * e, c.Y * e, h.X * e, h.Y * e, i]);
|
|
1293
1293
|
}
|
|
1294
|
-
function
|
|
1294
|
+
function o(c, h, l, d) {
|
|
1295
1295
|
n.arc.push([
|
|
1296
|
-
|
|
1297
|
-
|
|
1296
|
+
c.x * e,
|
|
1297
|
+
c.y * e,
|
|
1298
1298
|
h * e,
|
|
1299
1299
|
l,
|
|
1300
1300
|
d,
|
|
1301
1301
|
i
|
|
1302
1302
|
]);
|
|
1303
1303
|
}
|
|
1304
|
-
for (let
|
|
1305
|
-
const h = this.originalData[
|
|
1304
|
+
for (let c = 0; c < this.originalData.length; c++) {
|
|
1305
|
+
const h = this.originalData[c];
|
|
1306
1306
|
if (h.isVerticalReferenceLine) {
|
|
1307
1307
|
n.dimensionLine.push([h.start.x * e, h.start.y * e, h.end.x * e, h.end.y * e]);
|
|
1308
1308
|
break;
|
|
1309
1309
|
}
|
|
1310
1310
|
}
|
|
1311
|
-
this.wallsGroup.forEach((
|
|
1312
|
-
for (let h = 0; h <
|
|
1313
|
-
const l =
|
|
1314
|
-
|
|
1311
|
+
this.wallsGroup.forEach((c) => {
|
|
1312
|
+
for (let h = 0; h < c.length; h++) {
|
|
1313
|
+
const l = c[h], d = h === c.length - 1 ? 0 : h + 1, p = c[d];
|
|
1314
|
+
s(l, p);
|
|
1315
1315
|
}
|
|
1316
1316
|
});
|
|
1317
|
-
const r = this.width * 0.2,
|
|
1318
|
-
return this.doorLineSegment.forEach((
|
|
1319
|
-
if (
|
|
1320
|
-
const h =
|
|
1317
|
+
const r = this.width * 0.2, a = [];
|
|
1318
|
+
return this.doorLineSegment.forEach((c) => {
|
|
1319
|
+
if (c.length() < 0.4) return;
|
|
1320
|
+
const h = c.clone().expansion(-this.width * 0.5);
|
|
1321
1321
|
if (i = "cyan", h.length() < 1.2) {
|
|
1322
1322
|
h.expansion(-r * 0.5);
|
|
1323
|
-
const l =
|
|
1323
|
+
const l = c.normal();
|
|
1324
1324
|
let d = new L(
|
|
1325
1325
|
h.start.clone(),
|
|
1326
1326
|
h.start.clone().add(l.clone().multiplyScalar(h.length()))
|
|
1327
1327
|
);
|
|
1328
|
-
const
|
|
1329
|
-
for (let b = 0; b <
|
|
1330
|
-
if (
|
|
1328
|
+
const p = d.clone().directionMove(d.normal(), h.length() * -0.5).expandToRectangle(h.length(), "bothSides");
|
|
1329
|
+
for (let b = 0; b < a.length; b++)
|
|
1330
|
+
if (a[b].intersectRectangle(p)) {
|
|
1331
1331
|
d = new L(
|
|
1332
1332
|
h.start.clone(),
|
|
1333
1333
|
h.start.clone().add(l.clone().multiplyScalar(-h.length()))
|
|
1334
1334
|
);
|
|
1335
1335
|
break;
|
|
1336
1336
|
}
|
|
1337
|
-
d.expansion(-r * 0.5).expandToRectangle(this.width * 0.2, "bothSides").path2D((b, P) =>
|
|
1337
|
+
d.expansion(-r * 0.5).expandToRectangle(this.width * 0.2, "bothSides").path2D((b, P) => s(b, P));
|
|
1338
1338
|
const m = h.length(), g = d.length(), u = (m ** 2 + g ** 2) / (2 * g), x = d.end.clone().add(d.direction().multiplyScalar(-u)), [w, S] = this.getArcAngleRange(x, h.end, d.end);
|
|
1339
|
-
|
|
1339
|
+
o(x, u, Math.min(w, S), Math.max(w, S)), a.push(p);
|
|
1340
1340
|
} else
|
|
1341
|
-
h.clone().expansion(-this.width * 0.5).expandToRectangle(this.width).path2D((l, d) =>
|
|
1342
|
-
}), i = "yellow", this.lineSegments.forEach((
|
|
1343
|
-
if (!
|
|
1344
|
-
Array.isArray(
|
|
1345
|
-
const { p: l, width: d } = h,
|
|
1346
|
-
|
|
1341
|
+
h.clone().expansion(-this.width * 0.5).expandToRectangle(this.width).path2D((l, d) => s(l, d)), h.clone().directionMove(h.normal(), r * 0.5).directionMove(h.direction(), r * 0.5).expansion(-h.length() * 0.45, "end").forward(r * 0.5).expandToRectangle(r).path2D((l, d) => s(l, d)), h.clone().directionMove(h.normal(), -r * 0.5).directionMove(h.direction(), -r * 0.5).expansion(-h.length() * 0.45, "start").forward(-r * 0.5).expandToRectangle(r).path2D((l, d) => s(l, d));
|
|
1342
|
+
}), i = "yellow", this.lineSegments.forEach((c) => {
|
|
1343
|
+
if (!c.userData.isWindow) return !1;
|
|
1344
|
+
Array.isArray(c.userData.drawWindow) && c.userData.drawWindow.forEach((h) => {
|
|
1345
|
+
const { p: l, width: d } = h, p = f.from(l), m = p.clone().add(c.direction().multiplyScalar(d * 0.5)), g = p.clone().add(c.direction().multiplyScalar(-d * 0.5)), u = new L(m, g);
|
|
1346
|
+
s(u.start, u.end), u.expandToRectangle(this.width, "bothSides").path2D((x, w) => s(x, w));
|
|
1347
1347
|
});
|
|
1348
1348
|
}), n;
|
|
1349
1349
|
}
|
|
@@ -1351,36 +1351,36 @@ class X extends j {
|
|
|
1351
1351
|
*
|
|
1352
1352
|
* @param type
|
|
1353
1353
|
*/
|
|
1354
|
-
async toDxfImageBlob(t = "Centimeters", e = "image/jpeg") {
|
|
1355
|
-
const
|
|
1356
|
-
let
|
|
1354
|
+
async toDxfImageBlob(t = "Centimeters", e = "image/jpeg", n = "#000") {
|
|
1355
|
+
const i = this.toDrawDataJson(t);
|
|
1356
|
+
let s;
|
|
1357
1357
|
if (typeof window < "u")
|
|
1358
|
-
|
|
1358
|
+
s = document.createElement("canvas");
|
|
1359
1359
|
else if (typeof global < "u") {
|
|
1360
1360
|
const { createCanvas: c } = await G("canvas");
|
|
1361
|
-
|
|
1361
|
+
s = c();
|
|
1362
1362
|
} else
|
|
1363
1363
|
throw new Error("创建画布失败");
|
|
1364
|
-
const o = 2 *
|
|
1364
|
+
const o = 2 * i.scale, r = {
|
|
1365
1365
|
cyan: "cyan",
|
|
1366
1366
|
yellow: "yellow",
|
|
1367
1367
|
white: "white"
|
|
1368
1368
|
};
|
|
1369
|
-
|
|
1370
|
-
const
|
|
1371
|
-
return
|
|
1372
|
-
|
|
1373
|
-
}),
|
|
1374
|
-
|
|
1375
|
-
}),
|
|
1376
|
-
let [
|
|
1377
|
-
const
|
|
1378
|
-
|
|
1379
|
-
}),
|
|
1380
|
-
|
|
1381
|
-
c(
|
|
1369
|
+
s.width = i.width + o * 2, s.height = i.height + o * 2;
|
|
1370
|
+
const a = s.getContext("2d");
|
|
1371
|
+
return n && (a.fillStyle = n, a.fillRect(0, 0, s.width, s.height)), a.translate(i.width * 0.5 + o, i.height * 0.5 + o), i.line.forEach(([c, h, l, d, p]) => {
|
|
1372
|
+
a.strokeStyle = r[p], a.beginPath(), a.moveTo(c, h), a.lineTo(l, d), a.closePath(), a.stroke();
|
|
1373
|
+
}), i.arc.forEach(([c, h, l, d, p, m]) => {
|
|
1374
|
+
a.strokeStyle = r[m], a.beginPath(), a.arc(c, h, l, d * (Math.PI / 180), p * (Math.PI / 180)), a.stroke();
|
|
1375
|
+
}), a.beginPath(), i.dimensionLine.forEach((c) => {
|
|
1376
|
+
let [h, l, d, p] = c;
|
|
1377
|
+
const m = Math.min(l, p), g = Math.max(l, p), u = (s.width * 0.5 - 0.4 * i.scale) * (h < 0 ? -1 : 1), x = (g - m) * 0.45;
|
|
1378
|
+
a.fillStyle = "#fff", a.font = `${0.15 * i.scale}px Arial`, a.textAlign = "center", a.textBaseline = "middle", a.fillText((g - m).toFixed(2) + "cm", u, m + (g - m) * 0.5), a.moveTo(u - 0.1 * i.scale, m), a.lineTo(u + 0.1 * i.scale, m), a.moveTo(u, m), a.lineTo(u, x + m), a.moveTo(u, g), a.lineTo(u, g - x), a.moveTo(u - 0.1 * i.scale, g), a.lineTo(u + 0.1 * i.scale, g);
|
|
1379
|
+
}), a.closePath(), a.strokeStyle = "#fff", a.stroke(), "toBlob" in s ? new Promise((c) => {
|
|
1380
|
+
s.toBlob((h) => {
|
|
1381
|
+
c(h);
|
|
1382
1382
|
}, e, 1);
|
|
1383
|
-
}) :
|
|
1383
|
+
}) : s.toBuffer(e, { quality: 1 });
|
|
1384
1384
|
}
|
|
1385
1385
|
/**
|
|
1386
1386
|
* 将点json结构转换为Dxf string
|
|
@@ -1390,11 +1390,11 @@ class X extends j {
|
|
|
1390
1390
|
e.setUnits(t), e.addLayer("cyan", R.ACI.CYAN, "DOTTED"), e.addLayer("yellow", R.ACI.YELLOW, "DOTTED"), e.addLayer("white", R.ACI.WHITE, "DOTTED");
|
|
1391
1391
|
const n = this.toDrawDataJson();
|
|
1392
1392
|
return n.line.forEach((i) => {
|
|
1393
|
-
let [
|
|
1394
|
-
e.setActiveLayer(
|
|
1393
|
+
let [s, o, r, a, c] = i;
|
|
1394
|
+
e.setActiveLayer(c), e.drawLine(s, o, r, a);
|
|
1395
1395
|
}), n.arc.forEach((i) => {
|
|
1396
|
-
const [
|
|
1397
|
-
e.setActiveLayer(h), e.drawArc(
|
|
1396
|
+
const [s, o, r, a, c, h] = i;
|
|
1397
|
+
e.setActiveLayer(h), e.drawArc(s, o, r, a, c);
|
|
1398
1398
|
}), e.toDxfString();
|
|
1399
1399
|
}
|
|
1400
1400
|
/**
|
|
@@ -1422,8 +1422,8 @@ class X extends j {
|
|
|
1422
1422
|
const i = await this.toDxfImageBlob(e, n);
|
|
1423
1423
|
if (!i) return !1;
|
|
1424
1424
|
if (typeof window < "u") {
|
|
1425
|
-
const
|
|
1426
|
-
|
|
1425
|
+
const s = document.createElement("a");
|
|
1426
|
+
s.href = URL.createObjectURL(i), s.download = t, s.click();
|
|
1427
1427
|
} else typeof global < "u" ? (await G("fs", !1)).writeFileSync(t, i) : console.error("图片下载失败");
|
|
1428
1428
|
return !0;
|
|
1429
1429
|
}
|
|
@@ -1433,8 +1433,8 @@ class X extends j {
|
|
|
1433
1433
|
* @returns
|
|
1434
1434
|
*/
|
|
1435
1435
|
computedOriginalSize(t, e = new v(0, 0, 0, 0)) {
|
|
1436
|
-
const n = t.flatMap((
|
|
1437
|
-
return e.set(
|
|
1436
|
+
const n = t.flatMap((c) => [c.start.x, c.end.x]), i = t.flatMap((c) => [c.start.y, c.end.y]), s = Math.min(...n), o = Math.min(...i), r = Math.max(...n), a = Math.max(...i);
|
|
1437
|
+
return e.set(s, o, r, a), e;
|
|
1438
1438
|
}
|
|
1439
1439
|
/**
|
|
1440
1440
|
* 创建数据
|
|
@@ -1443,20 +1443,20 @@ class X extends j {
|
|
|
1443
1443
|
*/
|
|
1444
1444
|
static createData(t, e = !0) {
|
|
1445
1445
|
let n = 0;
|
|
1446
|
-
return t.flatMap((
|
|
1447
|
-
const
|
|
1448
|
-
const
|
|
1446
|
+
return t.flatMap((s) => {
|
|
1447
|
+
const o = s.map((r, a) => {
|
|
1448
|
+
const c = a === s.length - 1 ? 0 : a + 1, h = s[c];
|
|
1449
1449
|
return {
|
|
1450
1450
|
start: { x: r.x, y: r.y },
|
|
1451
1451
|
end: { x: h.x, y: h.y },
|
|
1452
1452
|
insetionArr: [
|
|
1453
1453
|
{
|
|
1454
|
-
index:
|
|
1454
|
+
index: c + n
|
|
1455
1455
|
}
|
|
1456
1456
|
]
|
|
1457
1457
|
};
|
|
1458
1458
|
});
|
|
1459
|
-
return n +=
|
|
1459
|
+
return n += s.length, e || (o.pop(), o[o.length - 1].insetionArr.length = 0, n--), o;
|
|
1460
1460
|
});
|
|
1461
1461
|
}
|
|
1462
1462
|
}
|
|
@@ -1464,43 +1464,44 @@ const I = new L();
|
|
|
1464
1464
|
class ot extends X {
|
|
1465
1465
|
static name = "AngleCorrectionDxf";
|
|
1466
1466
|
onAddFromParent(t) {
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
}
|
|
1479
|
-
if (o) {
|
|
1480
|
-
e.originalData[o.userData.index].isVerticalReferenceLine = !0;
|
|
1481
|
-
const [a, h] = o.start.y < o.end.y ? [o.start, o.end] : [o.end, o.start];
|
|
1482
|
-
i = -new L(a, h).direction().angleBetween(new p(0, 1), "angle", "360");
|
|
1467
|
+
t.findComponentByName("LineAnalysis").addEventListener("analysisCompleted", async () => this.update());
|
|
1468
|
+
}
|
|
1469
|
+
async update() {
|
|
1470
|
+
const t = this.parent, e = t.findComponentByName("Dxf"), n = t.findComponentByName("LineAnalysis");
|
|
1471
|
+
let i = 0, s = null;
|
|
1472
|
+
for (let c = 0; c < e.originalData.length; c++) {
|
|
1473
|
+
const h = e.originalData[c];
|
|
1474
|
+
if (I.start.copy(h.start), I.end.copy(h.end), h.isVerticalReferenceLine) {
|
|
1475
|
+
const [l, d] = h.start.y < h.end.y ? [I.start, I.end] : [I.end, I.start];
|
|
1476
|
+
i = -new L(l, d).direction().angleBetween(new f(0, 1), "angle", "360"), s = null;
|
|
1477
|
+
break;
|
|
1483
1478
|
}
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1479
|
+
(!s || I.length() > s.length()) && (s = I.clone(), s.userData.index = c);
|
|
1480
|
+
}
|
|
1481
|
+
if (s) {
|
|
1482
|
+
e.originalData[s.userData.index].isVerticalReferenceLine = !0;
|
|
1483
|
+
const [c, h] = s.start.y < s.end.y ? [s.start, s.end] : [s.end, s.start];
|
|
1484
|
+
i = -new L(c, h).direction().angleBetween(new f(0, 1), "angle", "360");
|
|
1485
|
+
}
|
|
1486
|
+
const o = e.originalBox.center, r = f.zero(), a = e.originalData.map((c) => {
|
|
1487
|
+
const h = r.copy(c.start).division(o).rotate(f.zero(), i * (Math.PI / 180)).toJson(c.start.z), l = r.copy(c.end).division(o).rotate(f.zero(), i * (Math.PI / 180)).toJson(c.end.z), d = Object.assign(V(c), { start: h, end: l });
|
|
1488
|
+
return d.drawWindow && d.drawWindow.forEach((p) => {
|
|
1489
|
+
p.p = r.copy(p.p).division(o).rotate(f.zero(), i * (Math.PI / 180)).toJson(p.p.z), p.p.y = -p.p.y;
|
|
1490
|
+
}), d;
|
|
1491
|
+
});
|
|
1492
|
+
n.appendLineSegmentList.forEach((c) => {
|
|
1493
|
+
const h = c.clone();
|
|
1494
|
+
h.start.division(o).rotate(f.zero(), i * (Math.PI / 180)), h.end.division(o).rotate(f.zero(), i * (Math.PI / 180)), a.push({
|
|
1495
|
+
start: h.start.toJson(e.originalZAverage),
|
|
1496
|
+
end: h.end.toJson(e.originalZAverage),
|
|
1497
|
+
insetionArr: [],
|
|
1498
|
+
length: h.length()
|
|
1503
1499
|
});
|
|
1500
|
+
}), a.forEach((c) => {
|
|
1501
|
+
c.start.y = -c.start.y, c.end.y = -c.end.y;
|
|
1502
|
+
}), await this.set(a, e.width, e.scale), this.lineOffset(), this.doorLineSegment = e.doorLineSegment.map((c) => {
|
|
1503
|
+
const h = c.clone();
|
|
1504
|
+
return h.start.division(o).rotate(f.zero(), i * (Math.PI / 180)), h.end.division(o).rotate(f.zero(), i * (Math.PI / 180)), h.start.y = -h.start.y, h.end.y = -h.end.y, h;
|
|
1504
1505
|
});
|
|
1505
1506
|
}
|
|
1506
1507
|
}
|
|
@@ -1586,9 +1587,9 @@ class q {
|
|
|
1586
1587
|
* @returns 象限索引(0:西北,1:东北,2:西南,3:东南)或-1(跨多个象限)
|
|
1587
1588
|
*/
|
|
1588
1589
|
getQuadrant(t) {
|
|
1589
|
-
const e = this.children[0].bounds.intersectLineSegment(t), n = this.children[1].bounds.intersectLineSegment(t), i = this.children[2].bounds.intersectLineSegment(t),
|
|
1590
|
-
let
|
|
1591
|
-
return e && (
|
|
1590
|
+
const e = this.children[0].bounds.intersectLineSegment(t), n = this.children[1].bounds.intersectLineSegment(t), i = this.children[2].bounds.intersectLineSegment(t), s = this.children[3].bounds.intersectLineSegment(t);
|
|
1591
|
+
let o = 0, r = -1;
|
|
1592
|
+
return e && (o++, r = 0), n && (o++, r = 1), i && (o++, r = 2), s && (o++, r = 3), o === 1 ? r : -1;
|
|
1592
1593
|
}
|
|
1593
1594
|
/**
|
|
1594
1595
|
* 细分当前节点为四个子节点
|
|
@@ -1650,17 +1651,17 @@ class q {
|
|
|
1650
1651
|
);
|
|
1651
1652
|
if (!this.bounds.intersectBox(i))
|
|
1652
1653
|
return n;
|
|
1653
|
-
for (const
|
|
1654
|
-
const [
|
|
1655
|
-
let l = ((t.x -
|
|
1654
|
+
for (const s of this.nodes) {
|
|
1655
|
+
const [o, r] = s.line.points, a = r.x - o.x, c = r.y - o.y, h = a * a + c * c;
|
|
1656
|
+
let l = ((t.x - o.x) * a + (t.y - o.y) * c) / h;
|
|
1656
1657
|
l = Math.max(0, Math.min(1, l));
|
|
1657
|
-
const d =
|
|
1658
|
-
t.distance(new
|
|
1658
|
+
const d = o.x + l * a, p = o.y + l * c;
|
|
1659
|
+
t.distance(new f(d, p)) <= e && n.push(s);
|
|
1659
1660
|
}
|
|
1660
1661
|
if (!this.isLeaf)
|
|
1661
|
-
for (const
|
|
1662
|
-
n.push(...
|
|
1663
|
-
return n;
|
|
1662
|
+
for (const s of this.children)
|
|
1663
|
+
n.push(...s.queryCircle(t, e));
|
|
1664
|
+
return n.sort((s) => s.line.length()), n;
|
|
1664
1665
|
}
|
|
1665
1666
|
/**
|
|
1666
1667
|
* 查询与矩形相交的线段节点
|
|
@@ -1701,8 +1702,8 @@ class q {
|
|
|
1701
1702
|
* @returns
|
|
1702
1703
|
*/
|
|
1703
1704
|
boundsToArray(t = [], e, n = !0) {
|
|
1704
|
-
return !this.isLeaf && n && this.children?.forEach((i) => i.boundsToArray(t, e)), t.push(...this.bounds.points.flatMap((i,
|
|
1705
|
-
const r =
|
|
1705
|
+
return !this.isLeaf && n && this.children?.forEach((i) => i.boundsToArray(t, e)), t.push(...this.bounds.points.flatMap((i, s, o) => {
|
|
1706
|
+
const r = o[(s + 1) % o.length];
|
|
1706
1707
|
return e?.push(...this.color), e?.push(...this.color), [i.x, i.y, 0, r.x, r.y, 0];
|
|
1707
1708
|
})), t;
|
|
1708
1709
|
}
|
|
@@ -1723,8 +1724,8 @@ class U {
|
|
|
1723
1724
|
throw new Error("无效的点坐标");
|
|
1724
1725
|
const n = this.getGridId(t);
|
|
1725
1726
|
this.map.has(n) || this.map.set(n, /* @__PURE__ */ new Set());
|
|
1726
|
-
const i = this.map.get(n),
|
|
1727
|
-
i.add(
|
|
1727
|
+
const i = this.map.get(n), s = { point: t, userData: e };
|
|
1728
|
+
i.add(s), t.userData.pointVirtualGrid = { set: i, target: s };
|
|
1728
1729
|
}
|
|
1729
1730
|
/**
|
|
1730
1731
|
* 批量加入
|
|
@@ -1757,7 +1758,7 @@ class U {
|
|
|
1757
1758
|
*/
|
|
1758
1759
|
decodeGridId(t) {
|
|
1759
1760
|
const [e, n] = t.split(".").map(Number);
|
|
1760
|
-
return new
|
|
1761
|
+
return new f(e, n);
|
|
1761
1762
|
}
|
|
1762
1763
|
/**
|
|
1763
1764
|
* 查询与矩形相交的点
|
|
@@ -1765,12 +1766,12 @@ class U {
|
|
|
1765
1766
|
* @returns 相交的节点数组
|
|
1766
1767
|
*/
|
|
1767
1768
|
queryRect(t) {
|
|
1768
|
-
const e = t.toBox(), n = Math.ceil(e.minX / this.gridSize), i = Math.ceil(e.maxX / this.gridSize),
|
|
1769
|
+
const e = t.toBox(), n = Math.ceil(e.minX / this.gridSize), i = Math.ceil(e.maxX / this.gridSize), s = Math.ceil(e.minY / this.gridSize), o = Math.ceil(e.maxY / this.gridSize);
|
|
1769
1770
|
for (let r = n; r <= i; r++)
|
|
1770
|
-
for (let
|
|
1771
|
-
const
|
|
1772
|
-
if (!this.map.has(
|
|
1773
|
-
this.map.get(
|
|
1771
|
+
for (let a = s; a <= o; a++) {
|
|
1772
|
+
const c = `${r}.${a}`;
|
|
1773
|
+
if (!this.map.has(c)) continue;
|
|
1774
|
+
this.map.get(c)?.forEach((l) => {
|
|
1774
1775
|
t.containsPoint(l.point);
|
|
1775
1776
|
});
|
|
1776
1777
|
}
|
|
@@ -1782,16 +1783,16 @@ class U {
|
|
|
1782
1783
|
* @returns 相交的节点数组
|
|
1783
1784
|
*/
|
|
1784
1785
|
queryCircle(t, e) {
|
|
1785
|
-
const n = new v(t.x - e, t.x + e, t.y - e, t.y + e), i = Math.ceil(n.minX / this.gridSize),
|
|
1786
|
-
for (let
|
|
1787
|
-
for (let h =
|
|
1788
|
-
const l = `${
|
|
1786
|
+
const n = new v(t.x - e, t.x + e, t.y - e, t.y + e), i = Math.ceil(n.minX / this.gridSize), s = Math.ceil(n.maxX / this.gridSize), o = Math.ceil(n.minY / this.gridSize), r = Math.ceil(n.maxY / this.gridSize), a = [];
|
|
1787
|
+
for (let c = i; c <= s; c++)
|
|
1788
|
+
for (let h = o; h <= r; h++) {
|
|
1789
|
+
const l = `${c}.${h}`;
|
|
1789
1790
|
if (!this.map.has(l)) continue;
|
|
1790
|
-
this.map.get(l)?.forEach((
|
|
1791
|
-
t.distance(
|
|
1791
|
+
this.map.get(l)?.forEach((p) => {
|
|
1792
|
+
t.distance(p.point) <= e && a.push(p);
|
|
1792
1793
|
});
|
|
1793
1794
|
}
|
|
1794
|
-
return
|
|
1795
|
+
return a;
|
|
1795
1796
|
}
|
|
1796
1797
|
/**
|
|
1797
1798
|
* 查询与包围盒相交的点
|
|
@@ -1799,16 +1800,16 @@ class U {
|
|
|
1799
1800
|
* @returns 相交的节点数组
|
|
1800
1801
|
*/
|
|
1801
1802
|
queryBox(t) {
|
|
1802
|
-
const e = Math.ceil(t.minX / this.gridSize), n = Math.ceil(t.maxX / this.gridSize), i = Math.ceil(t.minY / this.gridSize),
|
|
1803
|
+
const e = Math.ceil(t.minX / this.gridSize), n = Math.ceil(t.maxX / this.gridSize), i = Math.ceil(t.minY / this.gridSize), s = Math.ceil(t.maxY / this.gridSize), o = [];
|
|
1803
1804
|
for (let r = e; r <= n; r++)
|
|
1804
|
-
for (let
|
|
1805
|
-
const
|
|
1806
|
-
if (!this.map.has(
|
|
1807
|
-
this.map.get(
|
|
1808
|
-
t.containsPoint(l.point) &&
|
|
1805
|
+
for (let a = i; a <= s; a++) {
|
|
1806
|
+
const c = `${r}.${a}`;
|
|
1807
|
+
if (!this.map.has(c)) continue;
|
|
1808
|
+
this.map.get(c)?.forEach((l) => {
|
|
1809
|
+
t.containsPoint(l.point) && o.push(l);
|
|
1809
1810
|
});
|
|
1810
1811
|
}
|
|
1811
|
-
return
|
|
1812
|
+
return o;
|
|
1812
1813
|
}
|
|
1813
1814
|
/**
|
|
1814
1815
|
* 查找相同点
|
|
@@ -1816,10 +1817,17 @@ class U {
|
|
|
1816
1817
|
*/
|
|
1817
1818
|
queryPoint(t) {
|
|
1818
1819
|
const e = this.getGridId(t), n = [];
|
|
1819
|
-
return this.map.has(e) && this.map.get(e)?.forEach((
|
|
1820
|
-
t.equal(
|
|
1820
|
+
return this.map.has(e) && this.map.get(e)?.forEach((s) => {
|
|
1821
|
+
t.equal(s.point) && n.push(s);
|
|
1821
1822
|
}), n;
|
|
1822
1823
|
}
|
|
1824
|
+
/**
|
|
1825
|
+
* 查找点自己
|
|
1826
|
+
* @param point
|
|
1827
|
+
*/
|
|
1828
|
+
queryPointSelf(t) {
|
|
1829
|
+
return t.userData.pointVirtualGrid && t.userData.pointVirtualGrid.target ? t.userData.pointVirtualGrid.target : null;
|
|
1830
|
+
}
|
|
1823
1831
|
}
|
|
1824
1832
|
class rt {
|
|
1825
1833
|
// 所有可查找的点位
|
|
@@ -1844,44 +1852,44 @@ class rt {
|
|
|
1844
1852
|
this.pointVirtualGrid.insert(n.start, n), this.pointVirtualGrid.insert(n.end, n);
|
|
1845
1853
|
}), this.doorPoint = this.getDoorPoint(), !this.continueFind) return;
|
|
1846
1854
|
const e = this.searchDoubleLinePoint();
|
|
1847
|
-
this.addPointsExcludeRule((n, i,
|
|
1848
|
-
const
|
|
1849
|
-
return typeof r == "number" ? r === -1 || r ===
|
|
1850
|
-
}), this.addPointsExcludeRule((n, i) => !!this.doorPoint.find((
|
|
1855
|
+
this.addPointsExcludeRule((n, i, s) => {
|
|
1856
|
+
const o = this.lineSegments.indexOf(n), r = e.get(o);
|
|
1857
|
+
return typeof r == "number" ? r === -1 || r === s : !1;
|
|
1858
|
+
}), this.addPointsExcludeRule((n, i) => !!this.doorPoint.find((s) => s.point.equal(i))), this.possibleDoorPoints = this.getPossiblePoints(), this.possibleDoorPoints.forEach((n) => this.findPointVirtualGrid.insert(n.point, n.line)), this.handle();
|
|
1851
1859
|
}
|
|
1852
1860
|
handle() {
|
|
1853
1861
|
this.dxf.doorLineSegment.push(...this.search(this.doorPoint, this.possibleDoorPoints, 0.5)), this.doorPoint.length < 2 && this.dxf.doorLineSegment.push(...this.search(this.possibleDoorPoints, this.possibleDoorPoints, 0.6));
|
|
1854
1862
|
}
|
|
1855
|
-
search(t, e = [], n = 0.6, i = this.doorSearchDistance,
|
|
1856
|
-
const
|
|
1863
|
+
search(t, e = [], n = 0.6, i = this.doorSearchDistance, s = this.doorSearchNearAngle) {
|
|
1864
|
+
const o = this.dxf, r = this.searchNearby(t, e, i, s);
|
|
1857
1865
|
r.push(
|
|
1858
|
-
...t.map((
|
|
1859
|
-
const h = this.searchAlongDirection(
|
|
1866
|
+
...t.map((c) => {
|
|
1867
|
+
const h = this.searchAlongDirection(c, i);
|
|
1860
1868
|
if (h) return {
|
|
1861
|
-
start:
|
|
1869
|
+
start: c.point,
|
|
1862
1870
|
end: h.point
|
|
1863
1871
|
};
|
|
1864
|
-
const l = this.searchAlongNormalDirection(
|
|
1872
|
+
const l = this.searchAlongNormalDirection(c, i);
|
|
1865
1873
|
if (l) return {
|
|
1866
|
-
start:
|
|
1874
|
+
start: c.point,
|
|
1867
1875
|
end: l.point
|
|
1868
1876
|
};
|
|
1869
|
-
}).filter((
|
|
1877
|
+
}).filter((c) => !!c && c.start.distance(c.end) < i)
|
|
1870
1878
|
);
|
|
1871
|
-
const
|
|
1872
|
-
return r.forEach((
|
|
1873
|
-
const h = new L(
|
|
1879
|
+
const a = [];
|
|
1880
|
+
return r.forEach((c) => {
|
|
1881
|
+
const h = new L(c?.start, c?.end), l = h.length();
|
|
1874
1882
|
if (l < n) return;
|
|
1875
|
-
const d = h.normal(),
|
|
1883
|
+
const d = h.normal(), p = h.direction(), m = (l - o.width * 2) / 2;
|
|
1876
1884
|
for (let g = 0; g < 3; g++) {
|
|
1877
|
-
const u = h.start.clone().add(
|
|
1885
|
+
const u = h.start.clone().add(p.clone().multiplyScalar(o.width + m * g)), x = new L(
|
|
1878
1886
|
u,
|
|
1879
1887
|
u.clone().add(d.clone().multiplyScalar(1))
|
|
1880
1888
|
);
|
|
1881
1889
|
if (x.directionMove(d, -0.5), this.quadtree.queryLineSegment(x).length) return;
|
|
1882
1890
|
}
|
|
1883
|
-
|
|
1884
|
-
}),
|
|
1891
|
+
a.push(h);
|
|
1892
|
+
}), a;
|
|
1885
1893
|
}
|
|
1886
1894
|
/** 添加可查找点的过滤规则
|
|
1887
1895
|
* @param rule
|
|
@@ -1897,8 +1905,8 @@ class rt {
|
|
|
1897
1905
|
const t = [];
|
|
1898
1906
|
return this.lineSegments.forEach((e) => {
|
|
1899
1907
|
e.points.forEach((n, i) => {
|
|
1900
|
-
for (let
|
|
1901
|
-
this.pointVirtualGrid.queryPoint(n).filter((
|
|
1908
|
+
for (let o = 0; o < this._pointsExcludeRule.length; o++) if (this._pointsExcludeRule[o](e, n, i)) return;
|
|
1909
|
+
this.pointVirtualGrid.queryPoint(n).filter((o) => o.userData !== e).length === 0 && t.push({ line: e, point: n, uuid: N() });
|
|
1902
1910
|
});
|
|
1903
1911
|
}), t;
|
|
1904
1912
|
}
|
|
@@ -1908,23 +1916,23 @@ class rt {
|
|
|
1908
1916
|
getDoorPoint() {
|
|
1909
1917
|
const t = [], e = this.dxf, n = this.pointVirtualGrid;
|
|
1910
1918
|
return e.doors.forEach((i) => {
|
|
1911
|
-
const
|
|
1912
|
-
if (
|
|
1913
|
-
const r =
|
|
1914
|
-
if (h.userData ===
|
|
1919
|
+
const s = e.lineSegments[i[4]], o = e.originalData[i[4]];
|
|
1920
|
+
if (o.drawDoorData) {
|
|
1921
|
+
const r = f.from(o.drawDoorData.start), a = f.from(o.drawDoorData.n), c = n.queryPoint(r).filter((h) => {
|
|
1922
|
+
if (h.userData === s) return !1;
|
|
1915
1923
|
const l = h.userData, d = l.direction();
|
|
1916
1924
|
l.start.equal(r) && d.multiplyScalar(-1);
|
|
1917
|
-
const
|
|
1918
|
-
return
|
|
1925
|
+
const p = a.angleBetween(d, "angle");
|
|
1926
|
+
return p > 80 || p < 10;
|
|
1919
1927
|
});
|
|
1920
|
-
|
|
1921
|
-
line:
|
|
1928
|
+
c.length && t.push({
|
|
1929
|
+
line: c[0].userData,
|
|
1922
1930
|
point: r,
|
|
1923
|
-
uuid:
|
|
1931
|
+
uuid: N()
|
|
1924
1932
|
});
|
|
1925
|
-
} else if (
|
|
1933
|
+
} else if (o.doorDirectConnection) {
|
|
1926
1934
|
this.continueFind = !1;
|
|
1927
|
-
const r = new L(
|
|
1935
|
+
const r = new L(f.from(o.start), f.from(o.end));
|
|
1928
1936
|
r.userData = {
|
|
1929
1937
|
doorDirectConnection: !0,
|
|
1930
1938
|
isDoor: !0
|
|
@@ -1940,8 +1948,8 @@ class rt {
|
|
|
1940
1948
|
searchDoubleLinePoint() {
|
|
1941
1949
|
const t = /* @__PURE__ */ new Map();
|
|
1942
1950
|
return this.resultList.flatMap((e) => {
|
|
1943
|
-
const n = this.lineSegments[e.sourceIndex], i = this.lineSegments[e.targetIndex],
|
|
1944
|
-
t.has(e.sourceIndex) ? t.get(e.sourceIndex) !=
|
|
1951
|
+
const n = this.lineSegments[e.sourceIndex], i = this.lineSegments[e.targetIndex], s = i.projectPoint(n.start), o = i.projectPoint(n.end), r = n.projectPoint(i.start), a = n.projectPoint(i.end), c = s && o ? -1 : s ? 0 : o ? 1 : -1, h = r && a ? -1 : r ? 0 : a ? 1 : -1;
|
|
1952
|
+
t.has(e.sourceIndex) ? t.get(e.sourceIndex) != c && t.set(e.sourceIndex, -1) : t.set(e.sourceIndex, c), t.has(e.targetIndex) ? t.get(e.targetIndex) != h && t.set(e.targetIndex, -1) : t.set(e.targetIndex, h);
|
|
1945
1953
|
}), t;
|
|
1946
1954
|
}
|
|
1947
1955
|
/** 查找方案一:最近点查找
|
|
@@ -1953,11 +1961,11 @@ class rt {
|
|
|
1953
1961
|
* @returns
|
|
1954
1962
|
*/
|
|
1955
1963
|
searchNearby(t, e = [], n = this.doorSearchDistance, i = this.doorSearchNearAngle) {
|
|
1956
|
-
const
|
|
1964
|
+
const s = this.findPointVirtualGrid, o = this.quadtree;
|
|
1957
1965
|
function r({ point: u, line: x }, w, S) {
|
|
1958
1966
|
const b = x.direction();
|
|
1959
1967
|
x.start === u && b.multiplyScalar(-1);
|
|
1960
|
-
const P =
|
|
1968
|
+
const P = s.queryCircle(u, n).filter((D) => D.userData !== x).sort((D, E) => D.point.distance(u) - E.point.distance(u)), A = [];
|
|
1961
1969
|
for (let D = 0; D < P.length; D++) {
|
|
1962
1970
|
const E = e.findIndex((T) => T.point === P[D].point), B = t[w].uuid, Y = e[E].uuid;
|
|
1963
1971
|
if (S.has(`${B}.${Y}`)) continue;
|
|
@@ -1965,7 +1973,7 @@ class rt {
|
|
|
1965
1973
|
const Q = P[D].point, C = new L(u.clone(), Q.clone());
|
|
1966
1974
|
if (C.direction().angleBetween(b, "angle") < i) {
|
|
1967
1975
|
const T = t[E].line.direction();
|
|
1968
|
-
P[D].userData.start.equal(P[D].point) && T.multiplyScalar(-1), C.direction().multiplyScalar(-1).angleBetween(T, "angle") < i && (
|
|
1976
|
+
P[D].userData.start.equal(P[D].point) && T.multiplyScalar(-1), C.direction().multiplyScalar(-1).angleBetween(T, "angle") < i && (o.queryLineSegment(C).length || A.push({
|
|
1969
1977
|
findData: P[D],
|
|
1970
1978
|
findUuid: Y,
|
|
1971
1979
|
doorLine: C,
|
|
@@ -1975,7 +1983,7 @@ class rt {
|
|
|
1975
1983
|
}
|
|
1976
1984
|
return A;
|
|
1977
1985
|
}
|
|
1978
|
-
function
|
|
1986
|
+
function a(u, x, w, S, b) {
|
|
1979
1987
|
S.add(u);
|
|
1980
1988
|
const P = [];
|
|
1981
1989
|
b && P.push(b);
|
|
@@ -1983,19 +1991,19 @@ class rt {
|
|
|
1983
1991
|
const D = w[A];
|
|
1984
1992
|
if (x.has(D.findUuid)) {
|
|
1985
1993
|
const E = x.get(D.findUuid);
|
|
1986
|
-
|
|
1994
|
+
a(D.findUuid, x, E, S, D) && P.push(D);
|
|
1987
1995
|
} else P.push(D);
|
|
1988
1996
|
}
|
|
1989
1997
|
return P.sort((A, D) => A.doorLine.length() - D.doorLine.length()), b && P[0] === b ? (w.splice(0), !0) : (w.splice(1), !1);
|
|
1990
1998
|
}
|
|
1991
|
-
const
|
|
1999
|
+
const c = /* @__PURE__ */ new Set(), h = /* @__PURE__ */ new Map();
|
|
1992
2000
|
t.map((u, x) => {
|
|
1993
|
-
const w = r(u, x,
|
|
2001
|
+
const w = r(u, x, c);
|
|
1994
2002
|
w.length && h.set(u.uuid, w);
|
|
1995
|
-
}),
|
|
2003
|
+
}), c.clear();
|
|
1996
2004
|
const l = /* @__PURE__ */ new Map();
|
|
1997
2005
|
h.forEach((u, x) => {
|
|
1998
|
-
if (!
|
|
2006
|
+
if (!c.has(x) && u.length && a(x, h, u, c), u.length) {
|
|
1999
2007
|
const w = u[0];
|
|
2000
2008
|
l.has(w.doorUuid) || l.set(w.doorUuid, []), l.get(w.doorUuid)?.push(w), l.has(w.findUuid) || l.set(w.findUuid, []), l.get(w.findUuid)?.push(w);
|
|
2001
2009
|
}
|
|
@@ -2007,15 +2015,15 @@ class rt {
|
|
|
2007
2015
|
for (let x = 1; x < u.length; x++) d.add(u[x]);
|
|
2008
2016
|
}
|
|
2009
2017
|
});
|
|
2010
|
-
const
|
|
2018
|
+
const p = [], m = [];
|
|
2011
2019
|
h.forEach((u) => {
|
|
2012
2020
|
if (u.length) {
|
|
2013
2021
|
const x = u[0];
|
|
2014
|
-
d.has(x) || (
|
|
2022
|
+
d.has(x) || (p.push(x), m.push(x.doorUuid, x.findUuid));
|
|
2015
2023
|
}
|
|
2016
2024
|
});
|
|
2017
2025
|
const g = [];
|
|
2018
|
-
return
|
|
2026
|
+
return p.forEach((u) => {
|
|
2019
2027
|
const x = t.findIndex((E) => E.uuid === u.doorUuid), w = e.findIndex((E) => E.uuid === u.findUuid), S = t[x].point.clone(), b = e[w].point.clone(), P = this.findLongLineSegment(t[x].line), A = this.findLongLineSegment(e[w].line), D = P.projectPoint(b);
|
|
2020
2028
|
if (D) {
|
|
2021
2029
|
S.copy(D);
|
|
@@ -2049,16 +2057,16 @@ class rt {
|
|
|
2049
2057
|
* @returns
|
|
2050
2058
|
*/
|
|
2051
2059
|
searchAlongDirection({ point: t, line: e }, n = this.doorSearchDistance) {
|
|
2052
|
-
const i = this.quadtree,
|
|
2053
|
-
e.start === t &&
|
|
2054
|
-
const
|
|
2055
|
-
point:
|
|
2056
|
-
line:
|
|
2057
|
-
})).filter((
|
|
2058
|
-
if (
|
|
2059
|
-
const
|
|
2060
|
-
if (Math.abs(90 -
|
|
2061
|
-
return
|
|
2060
|
+
const i = this.quadtree, s = e.direction();
|
|
2061
|
+
e.start === t && s.multiplyScalar(-1);
|
|
2062
|
+
const o = t.clone().add(s.clone().multiplyScalar(n)), r = new L(t.clone(), o), a = i.queryLineSegment(r).map((c) => ({
|
|
2063
|
+
point: c.line.getIntersection(r),
|
|
2064
|
+
line: c.line
|
|
2065
|
+
})).filter((c) => c.point).sort((c, h) => t.distance(c.point) - t.distance(h.point));
|
|
2066
|
+
if (a.length) {
|
|
2067
|
+
const c = a[0];
|
|
2068
|
+
if (Math.abs(90 - c.line.direction().angleBetween(s, "angle")) < 5)
|
|
2069
|
+
return c;
|
|
2062
2070
|
}
|
|
2063
2071
|
}
|
|
2064
2072
|
/** 方案三: 沿法线方向查找
|
|
@@ -2068,20 +2076,20 @@ class rt {
|
|
|
2068
2076
|
* @returns
|
|
2069
2077
|
*/
|
|
2070
2078
|
searchAlongNormalDirection({ point: t, line: e }, n = this.doorSearchDistance) {
|
|
2071
|
-
const i = this.pointVirtualGrid,
|
|
2072
|
-
e.start === t &&
|
|
2073
|
-
const
|
|
2074
|
-
for (let d = 0; d <
|
|
2075
|
-
const
|
|
2076
|
-
if (m.start ===
|
|
2079
|
+
const i = this.pointVirtualGrid, s = this.quadtree, o = e.direction(), r = e.start.normal(e.end), a = e.start.clone();
|
|
2080
|
+
e.start === t && o.multiplyScalar(-1), e.start === t && a.copy(e.end);
|
|
2081
|
+
const c = i.queryPoint(a).filter((d) => d.userData !== e);
|
|
2082
|
+
for (let d = 0; d < c.length; d++) {
|
|
2083
|
+
const p = c[d], m = p.userData, g = m.direction();
|
|
2084
|
+
if (m.start === p.point && o.multiplyScalar(-1), g.angleBetween(r) / (Math.PI / 180) > 90) {
|
|
2077
2085
|
r.multiplyScalar(-1);
|
|
2078
2086
|
break;
|
|
2079
2087
|
}
|
|
2080
2088
|
}
|
|
2081
|
-
const h = new L(t.clone(), t.clone().add(r.multiplyScalar(n))), l =
|
|
2089
|
+
const h = new L(t.clone(), t.clone().add(r.multiplyScalar(n))), l = s.queryLineSegment(h).map((d) => ({
|
|
2082
2090
|
point: d.line.getIntersection(h),
|
|
2083
2091
|
line: d.line
|
|
2084
|
-
})).filter((d) => d.point).sort((d,
|
|
2092
|
+
})).filter((d) => d.point).sort((d, p) => t.distance(d.point) - t.distance(p.point));
|
|
2085
2093
|
if (l.length) {
|
|
2086
2094
|
const d = l[0];
|
|
2087
2095
|
if (Math.abs(90 - d.line.direction().angleBetween(r, "angle")) < 5)
|
|
@@ -2095,17 +2103,17 @@ class rt {
|
|
|
2095
2103
|
*/
|
|
2096
2104
|
findLongLineSegment(t) {
|
|
2097
2105
|
const e = t.clone(), n = this.pointVirtualGrid.queryPoint(t.start), i = this.pointVirtualGrid.queryPoint(t.end);
|
|
2098
|
-
for (let
|
|
2099
|
-
const { userData:
|
|
2100
|
-
if (
|
|
2101
|
-
|
|
2106
|
+
for (let s = 0; s < n.length; s++) {
|
|
2107
|
+
const { userData: o } = n[s];
|
|
2108
|
+
if (o !== t && o && o.directionEqual(t)) {
|
|
2109
|
+
o.start.equal(t.start) ? e.start.copy(o.end) : e.start.copy(o.start);
|
|
2102
2110
|
break;
|
|
2103
2111
|
}
|
|
2104
2112
|
}
|
|
2105
|
-
for (let
|
|
2106
|
-
const { userData:
|
|
2107
|
-
if (
|
|
2108
|
-
|
|
2113
|
+
for (let s = 0; s < i.length; s++) {
|
|
2114
|
+
const { userData: o } = i[s];
|
|
2115
|
+
if (o !== t && o && o.directionEqual(t)) {
|
|
2116
|
+
o.end.equal(t.end) ? e.end.copy(o.start) : e.end.copy(o.end);
|
|
2109
2117
|
break;
|
|
2110
2118
|
}
|
|
2111
2119
|
}
|
|
@@ -2136,15 +2144,15 @@ class at extends j {
|
|
|
2136
2144
|
* @returns
|
|
2137
2145
|
*/
|
|
2138
2146
|
expandLineSegment(t, e, n = 0.1) {
|
|
2139
|
-
const i = e.normal(t),
|
|
2147
|
+
const i = e.normal(t), s = e.direction(t).mutiplyScalar(n * 0.5), o = t.direction(e).mutiplyScalar(n * 0.5), r = i.x * n * 0.5, a = i.y * n * 0.5;
|
|
2140
2148
|
return {
|
|
2141
2149
|
points: [
|
|
2142
2150
|
// 第一条线
|
|
2143
|
-
new
|
|
2144
|
-
new
|
|
2151
|
+
new f(t.x + r, t.y + a).add(o),
|
|
2152
|
+
new f(e.x + r, e.y + a).add(s),
|
|
2145
2153
|
// 第二条线
|
|
2146
|
-
new
|
|
2147
|
-
new
|
|
2154
|
+
new f(t.x - r, t.y - a).add(o),
|
|
2155
|
+
new f(e.x - r, e.y - a).add(s)
|
|
2148
2156
|
],
|
|
2149
2157
|
indices: [0, 1, 1, 3, 3, 2, 2, 0],
|
|
2150
2158
|
rectIndices: [0, 1, 3, 2, 0]
|
|
@@ -2166,13 +2174,13 @@ class at extends j {
|
|
|
2166
2174
|
createRectangle(t) {
|
|
2167
2175
|
const e = this.Dxf, n = t.project, i = t.project2;
|
|
2168
2176
|
n.includedAngle(i) > 135 && (i.points = [i.points[1], i.points[0]]), this.addData(n.points[0], i.points[0]), this.addData(n.points[1], i.points[1]);
|
|
2169
|
-
const
|
|
2177
|
+
const s = n.points[0].distance(i.points[0]), o = n.points[1].distance(i.points[1]), r = Math.ceil(Math.max(s, o) / e.width), a = s / r, c = o / r, h = i.points[0].direction(n.points[0]), l = i.points[1].direction(n.points[1]), d = n.points[0].clone(), p = n.points[1].clone(), m = p.direction(d);
|
|
2170
2178
|
m.multiplyScalar(e.width * 0.5);
|
|
2171
|
-
const g = d.clone().add(m), u =
|
|
2179
|
+
const g = d.clone().add(m), u = p.clone().add(m.multiplyScalar(-1)), x = d.direction(p), w = g.direction(u);
|
|
2172
2180
|
if (!(x.x > 0 && w.x < 0 || x.x < 0 && w.x > 0 || x.y > 0 && w.y < 0 || x.y < 0 && w.y > 0)) {
|
|
2173
|
-
d.set(g.x, g.y),
|
|
2181
|
+
d.set(g.x, g.y), p.set(u.x, u.y);
|
|
2174
2182
|
for (let S = 1; S < r; S++) {
|
|
2175
|
-
const b = h.clone().multiplyScalar(
|
|
2183
|
+
const b = h.clone().multiplyScalar(a * S), P = l.clone().multiplyScalar(c * S), A = d.clone().add(b), D = p.clone().add(P);
|
|
2176
2184
|
this.addData(A, D);
|
|
2177
2185
|
}
|
|
2178
2186
|
}
|
|
@@ -2199,13 +2207,13 @@ class at extends j {
|
|
|
2199
2207
|
lineAnalysis() {
|
|
2200
2208
|
this.buildQuadtree();
|
|
2201
2209
|
const t = this.quadtree, e = this.lineSegmentList, n = /* @__PURE__ */ new Set(), i = [];
|
|
2202
|
-
e.forEach((
|
|
2203
|
-
const r = e[
|
|
2204
|
-
t.queryRect(
|
|
2210
|
+
e.forEach((s, o) => {
|
|
2211
|
+
const r = e[o], a = O.fromByLineSegment(r, this.width * 2, !1, -0.01);
|
|
2212
|
+
t.queryRect(a).map((h) => h.userData).filter((h) => h !== o).forEach((h) => {
|
|
2205
2213
|
try {
|
|
2206
|
-
if (n.has(`${
|
|
2207
|
-
const l = this.projectionAnalysis(h,
|
|
2208
|
-
l && i.push(l), n.add(`${
|
|
2214
|
+
if (n.has(`${o}-${h}`) || n.has(`${h}-${o}`)) return;
|
|
2215
|
+
const l = this.projectionAnalysis(h, o, r, e);
|
|
2216
|
+
l && i.push(l), n.add(`${o}-${h}`);
|
|
2209
2217
|
} catch {
|
|
2210
2218
|
}
|
|
2211
2219
|
});
|
|
@@ -2218,25 +2226,25 @@ class at extends j {
|
|
|
2218
2226
|
* @returns
|
|
2219
2227
|
*/
|
|
2220
2228
|
projectionAnalysis(t, e, n, i) {
|
|
2221
|
-
const
|
|
2222
|
-
if (
|
|
2223
|
-
let
|
|
2224
|
-
const h =
|
|
2225
|
-
return h.getLength() > l.getLength() ?
|
|
2226
|
-
target:
|
|
2229
|
+
const s = i[t], o = n.direction(), r = s.direction(), a = o.angleBetween(r) / (Math.PI / 180);
|
|
2230
|
+
if (a < this.errorAngle || a > 180 - this.errorAngle) {
|
|
2231
|
+
let c;
|
|
2232
|
+
const h = s.projectLineSegment(n), l = n.projectLineSegment(s);
|
|
2233
|
+
return h.getLength() > l.getLength() ? c = {
|
|
2234
|
+
target: s,
|
|
2227
2235
|
targetIndex: t,
|
|
2228
2236
|
source: n,
|
|
2229
2237
|
sourceIndex: e,
|
|
2230
2238
|
project: h,
|
|
2231
2239
|
project2: l
|
|
2232
|
-
} :
|
|
2240
|
+
} : c = {
|
|
2233
2241
|
target: n,
|
|
2234
2242
|
targetIndex: e,
|
|
2235
|
-
source:
|
|
2243
|
+
source: s,
|
|
2236
2244
|
sourceIndex: t,
|
|
2237
2245
|
project: l,
|
|
2238
2246
|
project2: h
|
|
2239
|
-
}, !
|
|
2247
|
+
}, !c || c.project.getLength() < 0.2 || c.project2.getLength() < 0.2 ? void 0 : c;
|
|
2240
2248
|
}
|
|
2241
2249
|
}
|
|
2242
2250
|
doorSearchNearAngle = 110;
|
|
@@ -2274,15 +2282,15 @@ class ct extends it {
|
|
|
2274
2282
|
}
|
|
2275
2283
|
const ht = new et(), lt = new nt();
|
|
2276
2284
|
function dt(y, t, e = 0.1) {
|
|
2277
|
-
const n = t.normal(y), i = t.direction(y).mutiplyScalar(e * 0.5),
|
|
2285
|
+
const n = t.normal(y), i = t.direction(y).mutiplyScalar(e * 0.5), s = y.direction(t).mutiplyScalar(e * 0.5), o = n.x * e * 0.5, r = n.y * e * 0.5;
|
|
2278
2286
|
return {
|
|
2279
2287
|
points: [
|
|
2280
2288
|
// 第一条线
|
|
2281
|
-
new
|
|
2282
|
-
new
|
|
2289
|
+
new f(y.x + o, y.y + r).add(s),
|
|
2290
|
+
new f(t.x + o, t.y + r).add(i),
|
|
2283
2291
|
// 第二条线
|
|
2284
|
-
new
|
|
2285
|
-
new
|
|
2292
|
+
new f(y.x - o, y.y - r).add(s),
|
|
2293
|
+
new f(t.x - o, t.y - r).add(i)
|
|
2286
2294
|
],
|
|
2287
2295
|
indices: [0, 1, 1, 3, 3, 2, 2, 0],
|
|
2288
2296
|
rectIndices: [0, 1, 3, 2, 0]
|
|
@@ -2309,35 +2317,35 @@ class H extends j {
|
|
|
2309
2317
|
const t = this.Dxf;
|
|
2310
2318
|
this.originalWhiteMode.clear(), this.whiteModelGroup.clear(), this.whiteModelLineGroup.clear(), this.whiteModelGroup.add(this.whiteModelLineGroup), this.whiteModelGroup.position.z = t.originalZAverage, this.originalWhiteMode.position.z = t.originalZAverage, t.wallsGroup.forEach((n) => {
|
|
2311
2319
|
const i = new M.Shape();
|
|
2312
|
-
n.forEach((r,
|
|
2313
|
-
const
|
|
2320
|
+
n.forEach((r, a) => a === 0 ? i.moveTo(r.x / t.scale, r.y / t.scale) : i.lineTo(r.x / t.scale, r.y / t.scale));
|
|
2321
|
+
const s = new M.ExtrudeGeometry(i, {
|
|
2314
2322
|
depth: 2.8,
|
|
2315
2323
|
bevelSize: 0
|
|
2316
|
-
}),
|
|
2317
|
-
this.whiteModelGroup.add(
|
|
2318
|
-
new M.LineSegments(new M.EdgesGeometry(
|
|
2324
|
+
}), o = new M.Mesh(s, this.material);
|
|
2325
|
+
this.whiteModelGroup.add(o), this.whiteModelLineGroup.add(
|
|
2326
|
+
new M.LineSegments(new M.EdgesGeometry(s), new M.LineBasicMaterial({ color: 0 }))
|
|
2319
2327
|
);
|
|
2320
|
-
}), t.originalData.map(({ start: n, end: i, insetionArr:
|
|
2321
|
-
const
|
|
2328
|
+
}), t.originalData.map(({ start: n, end: i, insetionArr: s }) => {
|
|
2329
|
+
const o = new f(n.x, n.y).mutiplyScalar(t.scale), r = new f(i.x, i.y).mutiplyScalar(t.scale), { points: a, indices: c, rectIndices: h } = dt(o, r, t.width);
|
|
2322
2330
|
return {
|
|
2323
|
-
points:
|
|
2324
|
-
indices:
|
|
2331
|
+
points: a,
|
|
2332
|
+
indices: c,
|
|
2325
2333
|
rectIndices: h,
|
|
2326
|
-
insetions: (
|
|
2334
|
+
insetions: (s ?? []).map((l) => l.index)
|
|
2327
2335
|
};
|
|
2328
2336
|
}).forEach((n) => {
|
|
2329
2337
|
const i = new M.Shape();
|
|
2330
|
-
n.rectIndices.forEach((r,
|
|
2331
|
-
const
|
|
2332
|
-
|
|
2338
|
+
n.rectIndices.forEach((r, a) => {
|
|
2339
|
+
const c = n.points[r];
|
|
2340
|
+
a === 0 ? i.moveTo(c.x, c.y) : i.lineTo(c.x, c.y);
|
|
2333
2341
|
});
|
|
2334
|
-
const
|
|
2342
|
+
const s = new M.ExtrudeGeometry(i, {
|
|
2335
2343
|
depth: 2.8,
|
|
2336
2344
|
bevelSize: 0
|
|
2337
2345
|
});
|
|
2338
|
-
if (
|
|
2339
|
-
const
|
|
2340
|
-
this.originalWhiteMode?.add(
|
|
2346
|
+
if (s.attributes.position.array.filter((r) => Number.isNaN(r)).length) return;
|
|
2347
|
+
const o = new M.Mesh(s);
|
|
2348
|
+
this.originalWhiteMode?.add(o);
|
|
2341
2349
|
}), this.dispatchEvent({
|
|
2342
2350
|
type: "updateModel",
|
|
2343
2351
|
originalWhiteMode: this.originalWhiteMode,
|
|
@@ -2373,12 +2381,12 @@ class H extends j {
|
|
|
2373
2381
|
});
|
|
2374
2382
|
else if (typeof global != "function")
|
|
2375
2383
|
try {
|
|
2376
|
-
const n = await G("obj2gltf", !0), i = await G("fs", !1),
|
|
2377
|
-
i.writeFileSync(this.uuid,
|
|
2378
|
-
const
|
|
2384
|
+
const n = await G("obj2gltf", !0), i = await G("fs", !1), s = await this.toOBJ();
|
|
2385
|
+
i.writeFileSync(this.uuid, s);
|
|
2386
|
+
const o = await n(this.uuid, {
|
|
2379
2387
|
binary: t
|
|
2380
2388
|
});
|
|
2381
|
-
i.unlinkSync(this.uuid), e(t ?
|
|
2389
|
+
i.unlinkSync(this.uuid), e(t ? o : JSON.stringify(o));
|
|
2382
2390
|
} catch (n) {
|
|
2383
2391
|
e(void 0), console.log(n);
|
|
2384
2392
|
}
|
|
@@ -2459,8 +2467,8 @@ class Z extends j {
|
|
|
2459
2467
|
const { default: n } = await import(
|
|
2460
2468
|
/* @vite-ignore */
|
|
2461
2469
|
"fs"
|
|
2462
|
-
), i = n.readFileSync(t),
|
|
2463
|
-
this.set(
|
|
2470
|
+
), i = n.readFileSync(t), s = JSON.parse(i.toString("utf-8"));
|
|
2471
|
+
this.set(s);
|
|
2464
2472
|
return;
|
|
2465
2473
|
} else
|
|
2466
2474
|
throw new Error("非node环境不允许使用路径");
|
|
@@ -2495,15 +2503,15 @@ class Z extends j {
|
|
|
2495
2503
|
e.direction.x,
|
|
2496
2504
|
e.direction.y,
|
|
2497
2505
|
e.direction.z
|
|
2498
|
-
),
|
|
2499
|
-
this.racasterHelper(n, i,
|
|
2500
|
-
const r = new M.Raycaster(n, i, 0,
|
|
2506
|
+
), s = 100;
|
|
2507
|
+
this.racasterHelper(n, i, s), i.z = 0;
|
|
2508
|
+
const r = new M.Raycaster(n, i, 0, s).intersectObject(t.originalWhiteMode);
|
|
2501
2509
|
if (r.length) {
|
|
2502
|
-
const { point:
|
|
2510
|
+
const { point: a } = r[0];
|
|
2503
2511
|
this.desPoints.push({
|
|
2504
2512
|
message: e.desc,
|
|
2505
2513
|
position: n,
|
|
2506
|
-
intersection:
|
|
2514
|
+
intersection: a
|
|
2507
2515
|
});
|
|
2508
2516
|
}
|
|
2509
2517
|
}), this.dispatchEvent({
|
|
@@ -2528,8 +2536,8 @@ class K extends j {
|
|
|
2528
2536
|
const e = t.to3DArray(1 / t.scale, 0);
|
|
2529
2537
|
this.dxfLineModel.geometry = new M.BufferGeometry().setAttribute("position", new M.BufferAttribute(e, 3, !0));
|
|
2530
2538
|
const n = new Float32Array(
|
|
2531
|
-
t.doorLineSegment.flatMap(({ start:
|
|
2532
|
-
).map((
|
|
2539
|
+
t.doorLineSegment.flatMap(({ start: s, end: o }) => [s.x, s.y, 0, o.x, o.y, 0])
|
|
2540
|
+
).map((s) => s / t.scale), i = new Float32Array(t.doorLineSegment.flatMap(() => [1, 0, 0, 0, 1, 0]));
|
|
2533
2541
|
this.dxfDoorsLineModel.geometry = new M.BufferGeometry().setAttribute("position", new M.BufferAttribute(n, 3, !0)).setAttribute("color", new M.BufferAttribute(i, 3)), this.dxfModelGroup.position.z = t.originalZAverage, this.dispatchEvent({
|
|
2534
2542
|
type: "modelUpdate",
|
|
2535
2543
|
model: this.dxfModelGroup
|
|
@@ -2565,36 +2573,37 @@ function mt() {
|
|
|
2565
2573
|
function xt() {
|
|
2566
2574
|
return import("./index3.js");
|
|
2567
2575
|
}
|
|
2568
|
-
let
|
|
2576
|
+
let z = null;
|
|
2569
2577
|
async function Et(y, t, e = !1, n) {
|
|
2570
|
-
const i = await Promise.resolve().then(() => pt),
|
|
2578
|
+
const i = await Promise.resolve().then(() => pt), s = await mt(), o = await xt(), r = new ct().usePlugin(i.ModelDataPlugin.create({
|
|
2571
2579
|
detailsPoint: !1,
|
|
2572
2580
|
whiteModel: !0
|
|
2573
|
-
})).usePlugin(
|
|
2581
|
+
})).usePlugin(s.RenderPlugin.create({
|
|
2574
2582
|
originalLine: !1,
|
|
2575
2583
|
modelData: !1,
|
|
2576
2584
|
detailsPoint: !1,
|
|
2577
2585
|
orbitControls: e,
|
|
2578
2586
|
camera: t
|
|
2579
|
-
})).usePlugin(
|
|
2580
|
-
return
|
|
2587
|
+
})).usePlugin(o.Editor.create({ viewPermission: n })), a = r.findComponentByType(s.components.DomContainer);
|
|
2588
|
+
return a && y.appendChild(a.domElement), z = r, {
|
|
2581
2589
|
dxfSystem: r,
|
|
2582
2590
|
getFileAll: () => yt(r)
|
|
2583
2591
|
};
|
|
2584
2592
|
}
|
|
2585
|
-
async function yt(y =
|
|
2586
|
-
const t = y.findComponentByName("WhiteModel"), e = new File([await y.AngleCorrectionDxf.toDxfImageBlob()], "img.jpg", { type: "image/jpeg" }), n = new File([y.Dxf.toDxfBlob()], "dxf.dxf", { type: "application/dxf" }), i = new File([await t.toOBJBlob()], "model.obj", { type: "application/octet-stream" }), o = new File([await t.toGltfBlob(!0)], "model.glb", { type: "application/octet-stream" }),
|
|
2593
|
+
async function yt(y = z) {
|
|
2594
|
+
const t = y.findComponentByName("WhiteModel"), e = new File([await y.AngleCorrectionDxf.toDxfImageBlob()], "img.jpg", { type: "image/jpeg" }), n = new File([y.Dxf.toDxfBlob()], "dxf.dxf", { type: "application/dxf" }), i = new File([y.AngleCorrectionDxf.toDxfBlob()], "dxf.dxf", { type: "application/dxf" }), s = new File([await t.toOBJBlob()], "model.obj", { type: "application/octet-stream" }), o = new File([await t.toGltfBlob(!0)], "model.glb", { type: "application/octet-stream" }), r = new File([await t.toGltfBlob(!1)], "model.gltf", { type: "application/json" }), a = new File([JSON.stringify(y.Dxf.originalData)], "json.json", { type: "application/json" });
|
|
2587
2595
|
return {
|
|
2588
2596
|
dxf: n,
|
|
2589
|
-
obj:
|
|
2597
|
+
obj: s,
|
|
2590
2598
|
glb: o,
|
|
2591
|
-
gltf:
|
|
2592
|
-
json:
|
|
2593
|
-
jpg: e
|
|
2599
|
+
gltf: r,
|
|
2600
|
+
json: a,
|
|
2601
|
+
jpg: e,
|
|
2602
|
+
correctionDxf: i
|
|
2594
2603
|
};
|
|
2595
2604
|
}
|
|
2596
2605
|
function At() {
|
|
2597
|
-
return
|
|
2606
|
+
return z;
|
|
2598
2607
|
}
|
|
2599
2608
|
export {
|
|
2600
2609
|
v as B,
|
|
@@ -2603,7 +2612,7 @@ export {
|
|
|
2603
2612
|
$ as E,
|
|
2604
2613
|
L,
|
|
2605
2614
|
ft as M,
|
|
2606
|
-
|
|
2615
|
+
f as P,
|
|
2607
2616
|
q as Q,
|
|
2608
2617
|
_ as V,
|
|
2609
2618
|
H as W,
|
|
@@ -2612,5 +2621,6 @@ export {
|
|
|
2612
2621
|
Et as c,
|
|
2613
2622
|
At as d,
|
|
2614
2623
|
yt as g,
|
|
2615
|
-
ut as i
|
|
2624
|
+
ut as i,
|
|
2625
|
+
N as u
|
|
2616
2626
|
};
|