build-dxf 0.0.20-15 → 0.0.20-16
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 +588 -434
- package/src/index.css +1 -1
- package/src/index3.js +785 -705
- package/src/utils/DxfSystem/components/AngleCorrectionDxf.d.ts +9 -0
- package/src/utils/DxfSystem/components/Dxf.d.ts +35 -5
- package/src/utils/DxfSystem/components/LineAnalysis.d.ts +3 -1
- package/src/utils/DxfSystem/index.d.ts +2 -0
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/VerticalCorrection.d.ts +20 -14
- package/src/utils/DxfSystem/plugin/Editor/components/CommandFlow/VerticalReferenceLine.d.ts +21 -0
- package/src/utils/DxfSystem/plugin/Editor/components/RenderManager.d.ts +4 -1
- package/src/utils/Quadtree/LineSegment.d.ts +1 -1
- package/src/utils/Quadtree/Point.d.ts +7 -1
- package/src/utils/deepClone.d.ts +6 -0
package/src/build.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import * as M from "three";
|
|
2
|
-
import { EventDispatcher as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { OBJExporter as
|
|
6
|
-
import { GLTFExporter as
|
|
7
|
-
function
|
|
8
|
-
return "xxxx-xxxx-4xxx-yxxx-xxxx".replace(/[xy]/g, function(
|
|
9
|
-
var t = Math.random() * 16 | 0, e =
|
|
2
|
+
import { EventDispatcher as tt } from "three";
|
|
3
|
+
import F from "clipper-lib";
|
|
4
|
+
import R from "dxf-writer";
|
|
5
|
+
import { OBJExporter as et } from "three/examples/jsm/exporters/OBJExporter.js";
|
|
6
|
+
import { GLTFExporter as nt } from "three/examples/jsm/exporters/GLTFExporter.js";
|
|
7
|
+
function z() {
|
|
8
|
+
return "xxxx-xxxx-4xxx-yxxx-xxxx".replace(/[xy]/g, function(y) {
|
|
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
|
-
class $ extends
|
|
14
|
-
uuid =
|
|
13
|
+
class $ extends tt {
|
|
14
|
+
uuid = z();
|
|
15
15
|
addEventListener(t, e, n) {
|
|
16
16
|
const { once: i = !1 } = n ?? {}, o = (r) => {
|
|
17
17
|
e(r), i && s();
|
|
@@ -31,7 +31,7 @@ class $ extends K {
|
|
|
31
31
|
e && (e.forEach((n) => n()), this.eventRecordStack.delete(t));
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
class
|
|
34
|
+
class j extends $ {
|
|
35
35
|
parent;
|
|
36
36
|
destroyed = !1;
|
|
37
37
|
constructor(...t) {
|
|
@@ -49,7 +49,7 @@ class X extends $ {
|
|
|
49
49
|
this.destroyed = !0;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
class
|
|
52
|
+
class it extends $ {
|
|
53
53
|
static EventType = {
|
|
54
54
|
ADD_COMPONENT: "addComponent"
|
|
55
55
|
};
|
|
@@ -72,7 +72,7 @@ class et extends $ {
|
|
|
72
72
|
* @param component
|
|
73
73
|
*/
|
|
74
74
|
removeComponent(t) {
|
|
75
|
-
if (t instanceof
|
|
75
|
+
if (t instanceof j) {
|
|
76
76
|
const e = this.components.indexOf(t);
|
|
77
77
|
e > -1 && (this.components.splice(e, 1), this.dispatchEvent({
|
|
78
78
|
type: "removeComponent",
|
|
@@ -117,7 +117,7 @@ class et extends $ {
|
|
|
117
117
|
return e || null;
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
class
|
|
120
|
+
class p {
|
|
121
121
|
x;
|
|
122
122
|
y;
|
|
123
123
|
get X() {
|
|
@@ -201,6 +201,15 @@ class f {
|
|
|
201
201
|
add(t) {
|
|
202
202
|
return this.x += t.x, this.y += t.y, this;
|
|
203
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* 绕point旋转angle
|
|
206
|
+
* @param point
|
|
207
|
+
* @param angle 旋转角度,单位为弧度
|
|
208
|
+
*/
|
|
209
|
+
rotate(t, e) {
|
|
210
|
+
const n = this.x - t.x, i = this.y - t.y, o = Math.cos(e), s = Math.sin(e), r = n * o - i * s, c = n * s + i * o;
|
|
211
|
+
return this.x = r + t.x, this.y = c + t.y, this;
|
|
212
|
+
}
|
|
204
213
|
/**
|
|
205
214
|
* 保留小数位数
|
|
206
215
|
* @param count
|
|
@@ -225,7 +234,7 @@ class f {
|
|
|
225
234
|
*/
|
|
226
235
|
normal(t) {
|
|
227
236
|
const e = this.x - t.x, n = this.y - t.y, i = Math.sqrt(e * e + n * n), o = -n / i, s = e / i;
|
|
228
|
-
return new
|
|
237
|
+
return new p(o, s);
|
|
229
238
|
}
|
|
230
239
|
/**
|
|
231
240
|
* 获取由传入的点到该点的单位方向向量
|
|
@@ -235,7 +244,7 @@ class f {
|
|
|
235
244
|
*/
|
|
236
245
|
direction(t) {
|
|
237
246
|
const e = this.x - t.x, n = this.y - t.y, i = Math.sqrt(e * e + n * n);
|
|
238
|
-
return i === 0 ? new
|
|
247
|
+
return i === 0 ? new p(0, 0) : new p(e / i, n / i);
|
|
239
248
|
}
|
|
240
249
|
/**
|
|
241
250
|
* 计算模长
|
|
@@ -270,8 +279,8 @@ class f {
|
|
|
270
279
|
angleBetween(t, e = "radian", n = "180") {
|
|
271
280
|
const i = this.dot(t), o = this.magnitude(), s = t.magnitude();
|
|
272
281
|
if (o === 0 || s === 0) return 0;
|
|
273
|
-
const r = i / (o * s),
|
|
274
|
-
return e === "radian" ? Math.acos(
|
|
282
|
+
const r = i / (o * s), c = Math.max(-1, Math.min(1, r));
|
|
283
|
+
return e === "radian" ? Math.acos(c) : e === "cos" ? c : n === "180" || this.cross(t) < 0 ? Math.acos(c) / (Math.PI / 180) : 360 - Math.acos(c) / (Math.PI / 180);
|
|
275
284
|
}
|
|
276
285
|
/** 获取向量长度
|
|
277
286
|
*/
|
|
@@ -293,14 +302,14 @@ class f {
|
|
|
293
302
|
* @returns
|
|
294
303
|
*/
|
|
295
304
|
clone() {
|
|
296
|
-
return new
|
|
305
|
+
return new p(this.x, this.y);
|
|
297
306
|
}
|
|
298
307
|
/**
|
|
299
308
|
* 克隆
|
|
300
309
|
* @returns
|
|
301
310
|
*/
|
|
302
311
|
copy(t) {
|
|
303
|
-
this.x = t.x ?? 0, this.y = t.y ?? 0;
|
|
312
|
+
return this.x = t.x ?? 0, this.y = t.y ?? 0, this;
|
|
304
313
|
}
|
|
305
314
|
toJson(t = 0) {
|
|
306
315
|
return {
|
|
@@ -310,23 +319,23 @@ class f {
|
|
|
310
319
|
};
|
|
311
320
|
}
|
|
312
321
|
static from(t) {
|
|
313
|
-
return Array.isArray(t) ? new
|
|
322
|
+
return Array.isArray(t) ? new p(t[0], t[1]) : "x" in t && "y" in t ? new p(t.x, t.y) : "X" in t && "Y" in t ? new p(t.X, t.Y) : this.zero();
|
|
314
323
|
}
|
|
315
324
|
static zero() {
|
|
316
|
-
return new
|
|
325
|
+
return new p(0, 0);
|
|
317
326
|
}
|
|
318
327
|
}
|
|
319
|
-
class
|
|
328
|
+
class v {
|
|
320
329
|
minX = 0;
|
|
321
330
|
maxX = 0;
|
|
322
331
|
minY = 0;
|
|
323
332
|
maxY = 0;
|
|
324
333
|
get points() {
|
|
325
334
|
return [
|
|
326
|
-
new
|
|
327
|
-
new
|
|
328
|
-
new
|
|
329
|
-
new
|
|
335
|
+
new p(this.minX, this.minY),
|
|
336
|
+
new p(this.maxX, this.minY),
|
|
337
|
+
new p(this.maxX, this.maxY),
|
|
338
|
+
new p(this.minX, this.maxY)
|
|
330
339
|
];
|
|
331
340
|
}
|
|
332
341
|
get width() {
|
|
@@ -336,7 +345,7 @@ class A {
|
|
|
336
345
|
return this.maxY - this.minY;
|
|
337
346
|
}
|
|
338
347
|
get center() {
|
|
339
|
-
return new
|
|
348
|
+
return new p(
|
|
340
349
|
this.minX + (this.maxX - this.minX) * 0.5,
|
|
341
350
|
this.minY + (this.maxY - this.minY) * 0.5
|
|
342
351
|
);
|
|
@@ -367,13 +376,13 @@ class A {
|
|
|
367
376
|
return this.minX <= e.x && e.x <= this.maxX && this.minY <= e.y && e.y <= this.maxY;
|
|
368
377
|
let s = Number.NEGATIVE_INFINITY, r = Number.POSITIVE_INFINITY;
|
|
369
378
|
if (i !== 0) {
|
|
370
|
-
const
|
|
371
|
-
s = Math.max(s, Math.min(
|
|
379
|
+
const c = (this.minX - e.x) / i, a = (this.maxX - e.x) / i;
|
|
380
|
+
s = Math.max(s, Math.min(c, a)), r = Math.min(r, Math.max(c, a));
|
|
372
381
|
} else if (e.x < this.minX || e.x > this.maxX)
|
|
373
382
|
return !1;
|
|
374
383
|
if (o !== 0) {
|
|
375
|
-
const
|
|
376
|
-
s = Math.max(s, Math.min(
|
|
384
|
+
const c = (this.minY - e.y) / o, a = (this.maxY - e.y) / o;
|
|
385
|
+
s = Math.max(s, Math.min(c, a)), r = Math.min(r, Math.max(c, a));
|
|
377
386
|
} else if (e.y < this.minY || e.y > this.maxY)
|
|
378
387
|
return !1;
|
|
379
388
|
return s <= r && s <= 1 && r >= 0;
|
|
@@ -393,29 +402,29 @@ class A {
|
|
|
393
402
|
intersectRectangle(t) {
|
|
394
403
|
const e = (s) => this.minX <= s.x && s.x <= this.maxX && this.minY <= s.y && s.y <= this.maxY, n = (s) => {
|
|
395
404
|
let r = 0;
|
|
396
|
-
for (let
|
|
397
|
-
const
|
|
398
|
-
if (
|
|
399
|
-
const
|
|
400
|
-
if (
|
|
405
|
+
for (let c = 0; c < 4; c++) {
|
|
406
|
+
const a = t.points[c], h = t.points[(c + 1) % 4], l = { x: h.x - a.x, y: h.y - a.y }, d = { x: s.x - a.x, y: s.y - a.y }, f = l.x * d.y - l.y * d.x;
|
|
407
|
+
if (f === 0) {
|
|
408
|
+
const m = l.x !== 0 ? (s.x - a.x) / l.x : (s.y - a.y) / l.y;
|
|
409
|
+
if (m >= 0 && m <= 1) return !0;
|
|
401
410
|
} else {
|
|
402
|
-
const
|
|
403
|
-
if (r === 0 && (r =
|
|
411
|
+
const m = f > 0 ? 1 : -1;
|
|
412
|
+
if (r === 0 && (r = m), r !== m) return !1;
|
|
404
413
|
}
|
|
405
414
|
}
|
|
406
415
|
return !0;
|
|
407
|
-
}, i = (s, r,
|
|
408
|
-
const h = (u,
|
|
409
|
-
const S = (
|
|
416
|
+
}, i = (s, r, c, a) => {
|
|
417
|
+
const h = (u, x, w) => {
|
|
418
|
+
const S = (x.y - u.y) * (w.x - x.x) - (x.x - u.x) * (w.y - x.y);
|
|
410
419
|
return S === 0 ? 0 : S > 0 ? 1 : 2;
|
|
411
|
-
}, l = (u,
|
|
412
|
-
return !!(d !==
|
|
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(s, r, c), f = h(s, r, a), m = h(c, a, s), g = h(c, a, r);
|
|
421
|
+
return !!(d !== f && m !== g || d === 0 && l(s, c, r) || f === 0 && l(s, a, r) || m === 0 && l(c, s, a) || g === 0 && l(c, r, a));
|
|
413
422
|
}, o = this.points;
|
|
414
423
|
for (let s = 0; s < 4; s++) {
|
|
415
|
-
const r = o[s],
|
|
416
|
-
for (let
|
|
417
|
-
const h = t.points[
|
|
418
|
-
if (i(r,
|
|
424
|
+
const r = o[s], c = o[(s + 1) % 4];
|
|
425
|
+
for (let a = 0; a < 4; a++) {
|
|
426
|
+
const h = t.points[a], l = t.points[(a + 1) % 4];
|
|
427
|
+
if (i(r, c, h, l)) return !0;
|
|
419
428
|
}
|
|
420
429
|
}
|
|
421
430
|
for (let s of t.points)
|
|
@@ -491,7 +500,7 @@ class A {
|
|
|
491
500
|
* @returns
|
|
492
501
|
*/
|
|
493
502
|
clone() {
|
|
494
|
-
return new
|
|
503
|
+
return new v(this.minX, this.maxX, this.minY, this.maxY);
|
|
495
504
|
}
|
|
496
505
|
/**
|
|
497
506
|
*
|
|
@@ -502,7 +511,7 @@ class A {
|
|
|
502
511
|
const e = [], n = [];
|
|
503
512
|
return t.forEach((i) => {
|
|
504
513
|
e.push(i.x), n.push(i.y);
|
|
505
|
-
}), new
|
|
514
|
+
}), new v(
|
|
506
515
|
Math.min(...e),
|
|
507
516
|
Math.max(...e),
|
|
508
517
|
Math.min(...n),
|
|
@@ -510,7 +519,16 @@ class A {
|
|
|
510
519
|
);
|
|
511
520
|
}
|
|
512
521
|
}
|
|
513
|
-
|
|
522
|
+
function O(y) {
|
|
523
|
+
if (y === null || typeof y != "object") return y;
|
|
524
|
+
if (y instanceof Date) return new Date(y.getTime());
|
|
525
|
+
if (Array.isArray(y)) return y.map(O);
|
|
526
|
+
const t = {};
|
|
527
|
+
for (const e in y)
|
|
528
|
+
Object.prototype.hasOwnProperty.call(y, e) && (t[e] = O(y[e]));
|
|
529
|
+
return t;
|
|
530
|
+
}
|
|
531
|
+
class N {
|
|
514
532
|
points;
|
|
515
533
|
get p0() {
|
|
516
534
|
return this.points[0];
|
|
@@ -533,7 +551,7 @@ class C {
|
|
|
533
551
|
path2D(t) {
|
|
534
552
|
return this.points.flatMap((e, n) => {
|
|
535
553
|
const i = this.points[(n + 1) % this.points.length];
|
|
536
|
-
return t && t(new
|
|
554
|
+
return t && t(new p(e.x, e.y), new p(i.x, i.y)), [e.x, e.y, i.x, i.y];
|
|
537
555
|
});
|
|
538
556
|
}
|
|
539
557
|
createGeometry() {
|
|
@@ -559,12 +577,12 @@ class C {
|
|
|
559
577
|
intersectLineSegment(t) {
|
|
560
578
|
if (t.points.length !== 2)
|
|
561
579
|
throw new Error("LineSegment must have exactly 2 points");
|
|
562
|
-
const [e, n] = t.points, i = (o, s, r,
|
|
563
|
-
const
|
|
564
|
-
const
|
|
565
|
-
return
|
|
566
|
-
}, h = (
|
|
567
|
-
return !!(l !== d &&
|
|
580
|
+
const [e, n] = t.points, i = (o, s, r, c) => {
|
|
581
|
+
const a = (g, u, x) => {
|
|
582
|
+
const w = (u.y - g.y) * (x.x - u.x) - (u.x - g.x) * (x.y - u.y);
|
|
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 = a(o, s, r), d = a(o, s, c), f = a(r, c, o), m = a(r, c, s);
|
|
585
|
+
return !!(l !== d && f !== m || l === 0 && h(o, r, s) || d === 0 && h(o, c, s) || f === 0 && h(r, o, c) || m === 0 && h(r, s, c));
|
|
568
586
|
};
|
|
569
587
|
for (let o = 0; o < 4; o++) {
|
|
570
588
|
const s = this.points[o], r = this.points[(o + 1) % 4];
|
|
@@ -584,9 +602,9 @@ class C {
|
|
|
584
602
|
const e = (n) => {
|
|
585
603
|
let i = 0;
|
|
586
604
|
for (let o = 0; o < 4; o++) {
|
|
587
|
-
const s = this.points[o], r = this.points[(o + 1) % 4],
|
|
605
|
+
const s = this.points[o], r = this.points[(o + 1) % 4], c = { x: r.x - s.x, y: r.y - s.y }, a = { x: n.x - s.x, y: n.y - s.y }, h = c.x * a.y - c.y * a.x;
|
|
588
606
|
if (h === 0) {
|
|
589
|
-
const l =
|
|
607
|
+
const l = c.x !== 0 ? (n.x - s.x) / c.x : (n.y - s.y) / c.y;
|
|
590
608
|
if (l >= 0 && l <= 1) return !0;
|
|
591
609
|
} else {
|
|
592
610
|
const l = h > 0 ? 1 : -1;
|
|
@@ -614,7 +632,7 @@ class C {
|
|
|
614
632
|
e.push(s.normal(r));
|
|
615
633
|
}
|
|
616
634
|
function n(o, s) {
|
|
617
|
-
const r = o.points.map((
|
|
635
|
+
const r = o.points.map((c) => c.dot(s));
|
|
618
636
|
return [Math.min(...r), Math.max(...r)];
|
|
619
637
|
}
|
|
620
638
|
function i(o, s) {
|
|
@@ -649,7 +667,7 @@ class C {
|
|
|
649
667
|
let t = 1 / 0, e = -1 / 0, n = 1 / 0, i = -1 / 0;
|
|
650
668
|
return this.points.forEach((o) => {
|
|
651
669
|
e = Math.max(o.x, e), t = Math.min(o.x, t), i = Math.max(o.x, i), n = Math.min(o.x, n);
|
|
652
|
-
}), new
|
|
670
|
+
}), new v(t, e, n, i);
|
|
653
671
|
}
|
|
654
672
|
/**
|
|
655
673
|
*
|
|
@@ -658,21 +676,21 @@ class C {
|
|
|
658
676
|
* @returns
|
|
659
677
|
*/
|
|
660
678
|
static fromByLineSegment(t, e = 0.1, n = !1, i = 0.5) {
|
|
661
|
-
const o = t.points[0], s = t.points[1], r = s.normal(o),
|
|
662
|
-
return new
|
|
663
|
-
new
|
|
664
|
-
new
|
|
665
|
-
new
|
|
666
|
-
new
|
|
679
|
+
const o = t.points[0], s = t.points[1], r = s.normal(o), c = n ? s.direction(o).mutiplyScalar(e * i) : p.zero(), a = n ? o.direction(s).mutiplyScalar(e * i) : p.zero(), h = r.x * e * 0.5, l = r.y * e * 0.5;
|
|
680
|
+
return new N([
|
|
681
|
+
new p(o.x + h, o.y + l).add(a),
|
|
682
|
+
new p(s.x + h, s.y + l).add(c),
|
|
683
|
+
new p(s.x - h, s.y - l).add(c),
|
|
684
|
+
new p(o.x - h, o.y - l).add(a)
|
|
667
685
|
]);
|
|
668
686
|
}
|
|
669
687
|
}
|
|
670
688
|
class b {
|
|
671
|
-
points = [new
|
|
689
|
+
points = [new p(), new p()];
|
|
672
690
|
userData = {};
|
|
673
691
|
line;
|
|
674
692
|
get center() {
|
|
675
|
-
return new
|
|
693
|
+
return new p(
|
|
676
694
|
this.points[0].x + (this.points[1].x - this.points[0].x) * 0.5,
|
|
677
695
|
this.points[0].y + (this.points[1].y - this.points[0].y) * 0.5
|
|
678
696
|
);
|
|
@@ -683,11 +701,11 @@ class b {
|
|
|
683
701
|
get end() {
|
|
684
702
|
return this.points[1];
|
|
685
703
|
}
|
|
686
|
-
constructor(t = new
|
|
704
|
+
constructor(t = new p(), e = new p()) {
|
|
687
705
|
this.points = [t, e];
|
|
688
706
|
}
|
|
689
707
|
set(t, e) {
|
|
690
|
-
this.start.copy(t), this.end.copy(e);
|
|
708
|
+
return this.start.copy(t), this.end.copy(e), this;
|
|
691
709
|
}
|
|
692
710
|
/**
|
|
693
711
|
* 是否有相同端点
|
|
@@ -752,15 +770,15 @@ class b {
|
|
|
752
770
|
* @returns {Rectangle}
|
|
753
771
|
*/
|
|
754
772
|
expandToRectangle(t = 0.1, e = "all") {
|
|
755
|
-
const n = this.start, i = this.end, o = i.normal(n), s = e === "bothSides" ?
|
|
773
|
+
const n = this.start, i = this.end, o = i.normal(n), s = e === "bothSides" ? p.zero() : i.direction(n).mutiplyScalar(t * 0.5), r = e === "bothSides" ? p.zero() : n.direction(i).mutiplyScalar(t * 0.5), c = o.x * t * 0.5, a = o.y * t * 0.5, h = [
|
|
756
774
|
// 第一条线
|
|
757
|
-
new
|
|
758
|
-
new
|
|
775
|
+
new p(n.x + c, n.y + a).add(r),
|
|
776
|
+
new p(i.x + c, i.y + a).add(s),
|
|
759
777
|
// 第二条线
|
|
760
|
-
new
|
|
761
|
-
new
|
|
778
|
+
new p(n.x - c, n.y - a).add(r),
|
|
779
|
+
new p(i.x - c, i.y - a).add(s)
|
|
762
780
|
];
|
|
763
|
-
return new
|
|
781
|
+
return new N([0, 1, 3, 2].map((l) => h[l]));
|
|
764
782
|
}
|
|
765
783
|
/**
|
|
766
784
|
* 计算线段的长度
|
|
@@ -797,24 +815,24 @@ class b {
|
|
|
797
815
|
projectLineSegment(t) {
|
|
798
816
|
if (t.points.length !== 2 || this.points.length !== 2)
|
|
799
817
|
throw new Error("每条线段必须由两个点定义");
|
|
800
|
-
const [e, n] = t.points, [i, o] = this.points, s = new
|
|
818
|
+
const [e, n] = t.points, [i, o] = this.points, s = new p(o.x - i.x, o.y - i.y);
|
|
801
819
|
if (s.x === 0 && s.y === 0)
|
|
802
820
|
throw new Error("投影目标线段的两个点不能重合");
|
|
803
|
-
const r = (
|
|
804
|
-
const
|
|
805
|
-
return new
|
|
821
|
+
const r = (m) => {
|
|
822
|
+
const g = new p(m.x - i.x, m.y - i.y), u = s.x * s.x + s.y * s.y, w = (g.x * s.x + g.y * s.y) / u, S = i.x + w * s.x, L = i.y + w * s.y;
|
|
823
|
+
return new p(S, L);
|
|
806
824
|
};
|
|
807
|
-
let
|
|
808
|
-
const h = (
|
|
809
|
-
const
|
|
810
|
-
return (
|
|
825
|
+
let c = r(e), a = r(n);
|
|
826
|
+
const h = (m) => {
|
|
827
|
+
const g = new p(m.x - i.x, m.y - i.y), u = s.x * s.x + s.y * s.y;
|
|
828
|
+
return (g.x * s.x + g.y * s.y) / u;
|
|
811
829
|
};
|
|
812
|
-
let l = h(
|
|
813
|
-
const
|
|
814
|
-
const
|
|
815
|
-
return new
|
|
830
|
+
let l = h(c), d = h(a);
|
|
831
|
+
const f = (m) => {
|
|
832
|
+
const g = Math.max(0, Math.min(1, m)), u = i.x + g * s.x, x = i.y + g * s.y;
|
|
833
|
+
return new p(u, x);
|
|
816
834
|
};
|
|
817
|
-
return (l < 0 || l > 1) && (
|
|
835
|
+
return (l < 0 || l > 1) && (c = f(l)), (d < 0 || d > 1) && (a = f(d)), c.x === a.x && c.y === a.y ? new b(c, c) : new b(c, a);
|
|
818
836
|
}
|
|
819
837
|
/**
|
|
820
838
|
* 计算一条线段在另一条直线上的投影
|
|
@@ -823,19 +841,19 @@ class b {
|
|
|
823
841
|
* @returns 投影并裁剪后的线段
|
|
824
842
|
*/
|
|
825
843
|
projectPoint(t, e = !0) {
|
|
826
|
-
const [n, i] = this.points, o = new
|
|
844
|
+
const [n, i] = this.points, o = new p(i.x - n.x, i.y - n.y);
|
|
827
845
|
if (o.x === 0 && o.y === 0)
|
|
828
846
|
throw new Error("投影目标线段的两个点不能重合");
|
|
829
847
|
let r = ((h) => {
|
|
830
|
-
const l = new
|
|
831
|
-
return new
|
|
848
|
+
const l = new p(h.x - n.x, h.y - n.y), d = o.x * o.x + o.y * o.y, m = (l.x * o.x + l.y * o.y) / d, g = n.x + m * o.x, u = n.y + m * o.y;
|
|
849
|
+
return new p(g, u);
|
|
832
850
|
})(t);
|
|
833
851
|
if (!e) return r;
|
|
834
|
-
let
|
|
835
|
-
const l = new
|
|
852
|
+
let a = ((h) => {
|
|
853
|
+
const l = new p(h.x - n.x, h.y - n.y), d = o.x * o.x + o.y * o.y;
|
|
836
854
|
return (l.x * o.x + l.y * o.y) / d;
|
|
837
855
|
})(r);
|
|
838
|
-
return
|
|
856
|
+
return a < 0 || a > 1 ? null : r;
|
|
839
857
|
}
|
|
840
858
|
/**
|
|
841
859
|
* 判断线段是否与另一条线段相交(包含共用端点或部分重合的情况)
|
|
@@ -843,14 +861,14 @@ class b {
|
|
|
843
861
|
*/
|
|
844
862
|
intersectLineSegment(t) {
|
|
845
863
|
const e = this.start, n = this.end, i = t.start, o = t.end;
|
|
846
|
-
function s(d,
|
|
847
|
-
return (
|
|
864
|
+
function s(d, f, m) {
|
|
865
|
+
return (f.x - d.x) * (m.y - d.y) - (f.y - d.y) * (m.x - d.x);
|
|
848
866
|
}
|
|
849
|
-
function r(d,
|
|
850
|
-
return Math.min(
|
|
867
|
+
function r(d, f, m) {
|
|
868
|
+
return Math.min(f.x, m.x) - 1e-10 <= d.x && d.x <= Math.max(f.x, m.x) + 1e-10 && Math.min(f.y, m.y) - 1e-10 <= d.y && d.y <= Math.max(f.y, m.y) + 1e-10;
|
|
851
869
|
}
|
|
852
|
-
const
|
|
853
|
-
return !!(
|
|
870
|
+
const c = s(e, n, i), a = s(e, n, o), h = s(i, o, e), l = s(i, o, n);
|
|
871
|
+
return !!(c * a < 0 && h * l < 0 || Math.abs(c) < 1e-10 && r(i, e, n) || Math.abs(a) < 1e-10 && r(o, e, n) || Math.abs(h) < 1e-10 && r(e, i, o) || Math.abs(l) < 1e-10 && r(n, i, o));
|
|
854
872
|
}
|
|
855
873
|
/**
|
|
856
874
|
* 获取交点
|
|
@@ -861,8 +879,8 @@ class b {
|
|
|
861
879
|
const e = this.start, n = this.end, i = t.start, o = t.end, s = (e.x - n.x) * (i.y - o.y) - (e.y - n.y) * (i.x - o.x);
|
|
862
880
|
if (Math.abs(s) < 1e-10)
|
|
863
881
|
return null;
|
|
864
|
-
const r = ((e.x - i.x) * (i.y - o.y) - (e.y - i.y) * (i.x - o.x)) / s,
|
|
865
|
-
return new
|
|
882
|
+
const r = ((e.x - i.x) * (i.y - o.y) - (e.y - i.y) * (i.x - o.x)) / s, c = e.x + r * (n.x - e.x), a = e.y + r * (n.y - e.y);
|
|
883
|
+
return new p(c, a);
|
|
866
884
|
}
|
|
867
885
|
/**
|
|
868
886
|
* 获取两条线段夹角
|
|
@@ -900,28 +918,29 @@ class b {
|
|
|
900
918
|
* @returns
|
|
901
919
|
*/
|
|
902
920
|
areLinesCoincident(t) {
|
|
903
|
-
const e = this.start, n = this.end, i = t.start, o = t.end, s = (n.y - e.y) / (n.x - e.x), r = e.y - s * e.x,
|
|
904
|
-
return !isFinite(s) && !isFinite(
|
|
921
|
+
const e = this.start, n = this.end, i = t.start, o = t.end, s = (n.y - e.y) / (n.x - e.x), r = e.y - s * e.x, c = (o.y - i.y) / (o.x - i.x), a = i.y - c * i.x;
|
|
922
|
+
return !isFinite(s) && !isFinite(c) ? e.x === i.x && n.x === i.x : Math.abs(s - c) < 1e-3 && Math.abs(r - a) < 1e-3;
|
|
905
923
|
}
|
|
906
924
|
clone() {
|
|
907
|
-
|
|
925
|
+
const t = new b(
|
|
908
926
|
this.points[0].clone(),
|
|
909
927
|
this.points[1].clone()
|
|
910
928
|
);
|
|
929
|
+
return t.userData = O(this.userData), t;
|
|
911
930
|
}
|
|
912
931
|
}
|
|
913
|
-
async function
|
|
932
|
+
async function G(y, t = !0) {
|
|
914
933
|
if (typeof global < "u" && typeof require < "u")
|
|
915
|
-
return require(
|
|
934
|
+
return require(y);
|
|
916
935
|
{
|
|
917
936
|
let e = await import(
|
|
918
937
|
/* @vite-ignore */
|
|
919
|
-
|
|
938
|
+
y
|
|
920
939
|
);
|
|
921
940
|
return t && (e = e.default), e;
|
|
922
941
|
}
|
|
923
942
|
}
|
|
924
|
-
const
|
|
943
|
+
const st = {
|
|
925
944
|
Unitless: 1,
|
|
926
945
|
// 无单位,1米 = 1(无单位)
|
|
927
946
|
Inches: 39.37007874015748,
|
|
@@ -965,27 +984,27 @@ const nt = {
|
|
|
965
984
|
Parsecs: 3240779289666404e-32
|
|
966
985
|
// 秒差距,1米 ≈ 0.00000000000000003240779289666404秒差距
|
|
967
986
|
};
|
|
968
|
-
function
|
|
987
|
+
function k(y) {
|
|
969
988
|
const t = [];
|
|
970
|
-
for (let e = 0; e <
|
|
989
|
+
for (let e = 0; e < y.length; e++)
|
|
971
990
|
t.push(new b(
|
|
972
|
-
|
|
973
|
-
|
|
991
|
+
y[e].clone(),
|
|
992
|
+
y[(e + 1) % y.length].clone()
|
|
974
993
|
));
|
|
975
994
|
return t;
|
|
976
995
|
}
|
|
977
|
-
function
|
|
978
|
-
return
|
|
996
|
+
function J(y) {
|
|
997
|
+
return y.flatMap((t, e) => (e === y.length - 1 && [...t.points, y[0].points[0]], [t.points[0]]));
|
|
979
998
|
}
|
|
980
|
-
class
|
|
999
|
+
class X extends j {
|
|
981
1000
|
static name = "Dxf";
|
|
982
1001
|
shortLine = 0.04;
|
|
983
1002
|
width = 0.04;
|
|
984
1003
|
scale = 1;
|
|
985
1004
|
originalData = [];
|
|
986
1005
|
data = [];
|
|
987
|
-
originalBox = new
|
|
988
|
-
box = new
|
|
1006
|
+
originalBox = new v(0, 0, 0, 0);
|
|
1007
|
+
box = new v(0, 0, 0, 0);
|
|
989
1008
|
pointsGroups = [];
|
|
990
1009
|
wallsGroup = [];
|
|
991
1010
|
doors = [];
|
|
@@ -1029,24 +1048,24 @@ class I extends X {
|
|
|
1029
1048
|
const { default: s } = await import(
|
|
1030
1049
|
/* @vite-ignore */
|
|
1031
1050
|
"fs"
|
|
1032
|
-
), r = s.readFileSync(t),
|
|
1033
|
-
return this.set(
|
|
1051
|
+
), r = s.readFileSync(t), c = JSON.parse(r.toString("utf-8"));
|
|
1052
|
+
return this.set(c, e, n);
|
|
1034
1053
|
} else
|
|
1035
1054
|
throw new Error("非node环境不允许使用路径");
|
|
1036
1055
|
this.scale = n, this.width = e, this.originalData = t, this.lineSegments.length = 0;
|
|
1037
1056
|
const i = [];
|
|
1038
|
-
this.data = t.map(({ start: o, end: s, insetionArr: r, isDoor:
|
|
1057
|
+
this.data = t.map(({ start: o, end: s, insetionArr: r, isDoor: c = !1, ...a }, h) => {
|
|
1039
1058
|
i.push(o.z ?? 0, s.z ?? 0);
|
|
1040
|
-
const
|
|
1041
|
-
|
|
1042
|
-
|
|
1059
|
+
const l = new b(
|
|
1060
|
+
p.from(o).mutiplyScalar(n),
|
|
1061
|
+
p.from(s).mutiplyScalar(n)
|
|
1043
1062
|
);
|
|
1044
|
-
return
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
(r ?? []).map((
|
|
1048
|
-
|
|
1049
|
-
|
|
1063
|
+
return l.userData = { isDoor: c, ...a }, this.lineSegments.push(l), [
|
|
1064
|
+
l.points[0],
|
|
1065
|
+
l.points[1],
|
|
1066
|
+
(r ?? []).map((d) => d.index),
|
|
1067
|
+
c,
|
|
1068
|
+
h
|
|
1050
1069
|
];
|
|
1051
1070
|
}), this.originalZAverage = i.reduce((o, s) => o + s, 0) / i.length, this.computedOriginalSize(t, this.originalBox), this.dispatchEvent({
|
|
1052
1071
|
type: "setDta",
|
|
@@ -1062,18 +1081,18 @@ class I extends X {
|
|
|
1062
1081
|
* @returns
|
|
1063
1082
|
*/
|
|
1064
1083
|
createGroups() {
|
|
1065
|
-
const t = [], e = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Map(), o = (s, r,
|
|
1066
|
-
const [
|
|
1084
|
+
const t = [], e = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Map(), o = (s, r, c = -1) => {
|
|
1085
|
+
const [a, h, l, d] = this.data[s];
|
|
1067
1086
|
if (e.add(s), d)
|
|
1068
|
-
return i.has(s) || i.set(s, []), i.get(s)?.push(
|
|
1069
|
-
r.push([
|
|
1070
|
-
e.has(
|
|
1087
|
+
return i.has(s) || i.set(s, []), i.get(s)?.push(c), n.add(this.data[s]);
|
|
1088
|
+
r.push([a, h]), l.forEach((f) => {
|
|
1089
|
+
e.has(f) || o(f, r, s);
|
|
1071
1090
|
});
|
|
1072
1091
|
};
|
|
1073
1092
|
return this.data.forEach((s, r) => {
|
|
1074
1093
|
if (!e.has(r)) {
|
|
1075
|
-
const
|
|
1076
|
-
o(r,
|
|
1094
|
+
const c = [];
|
|
1095
|
+
o(r, c), t.push(c);
|
|
1077
1096
|
}
|
|
1078
1097
|
}), this.doors = [...n], this.pointsGroups = t, t;
|
|
1079
1098
|
}
|
|
@@ -1083,7 +1102,7 @@ class I extends X {
|
|
|
1083
1102
|
* @returns
|
|
1084
1103
|
*/
|
|
1085
1104
|
computedSize() {
|
|
1086
|
-
const t = this.pointsGroups.flatMap((r) => r.flatMap((
|
|
1105
|
+
const t = this.pointsGroups.flatMap((r) => r.flatMap((c) => [c[0].x, c[1].x])), e = this.pointsGroups.flatMap((r) => r.flatMap((c) => [c[0].y, c[1].y])), n = Math.min(...t), i = Math.min(...e), o = Math.max(...t), s = Math.max(...e);
|
|
1087
1106
|
return this.box.set(n, i, o, s), this.box;
|
|
1088
1107
|
}
|
|
1089
1108
|
/** 线路拓扑
|
|
@@ -1093,12 +1112,12 @@ class I extends X {
|
|
|
1093
1112
|
lineTopology(t) {
|
|
1094
1113
|
const e = [];
|
|
1095
1114
|
function n(o, s) {
|
|
1096
|
-
const [r,
|
|
1097
|
-
e[o] = !0, s.push(
|
|
1098
|
-
for (let
|
|
1099
|
-
const [h, l] = t[
|
|
1100
|
-
if (!e[
|
|
1101
|
-
return n(
|
|
1115
|
+
const [r, c] = t[o];
|
|
1116
|
+
e[o] = !0, s.push(c);
|
|
1117
|
+
for (let a = 0; a < t.length; a++) {
|
|
1118
|
+
const [h, l] = t[a];
|
|
1119
|
+
if (!e[a] && Math.abs(c.x - h.x) < 1e-6 && Math.abs(c.y - h.y) < 1e-6)
|
|
1120
|
+
return n(a, s);
|
|
1102
1121
|
}
|
|
1103
1122
|
}
|
|
1104
1123
|
const i = [];
|
|
@@ -1135,9 +1154,9 @@ class I extends X {
|
|
|
1135
1154
|
const i = t[n - 1], o = t[n];
|
|
1136
1155
|
if (i.distance(o) < this.width * 0.5) {
|
|
1137
1156
|
let r = 0;
|
|
1138
|
-
for (let
|
|
1139
|
-
const
|
|
1140
|
-
if (
|
|
1157
|
+
for (let c = n + 1; c < t.length; c++) {
|
|
1158
|
+
const a = t[c - 1], h = t[c];
|
|
1159
|
+
if (a.distance(h) < this.width * 0.8) r++;
|
|
1141
1160
|
else break;
|
|
1142
1161
|
}
|
|
1143
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(o));
|
|
@@ -1159,7 +1178,7 @@ class I extends X {
|
|
|
1159
1178
|
break;
|
|
1160
1179
|
}
|
|
1161
1180
|
}
|
|
1162
|
-
const e = this.mergeSameDirectionLine(
|
|
1181
|
+
const e = this.mergeSameDirectionLine(k(t)), n = [e[0]];
|
|
1163
1182
|
for (let i = 1; i < e.length; i++) {
|
|
1164
1183
|
const o = e[i], s = e[(e.length + i - 1) % e.length];
|
|
1165
1184
|
if (o.length() > this.width * 0.9) {
|
|
@@ -1171,10 +1190,10 @@ class I extends X {
|
|
|
1171
1190
|
n.push(o), n.push(r), i = i + 1;
|
|
1172
1191
|
continue;
|
|
1173
1192
|
}
|
|
1174
|
-
const
|
|
1175
|
-
|
|
1193
|
+
const c = e[i + 2];
|
|
1194
|
+
c && s.includedAngle(c) < 2 ? (i = i + 2, n.push(c)) : n.push(o);
|
|
1176
1195
|
}
|
|
1177
|
-
return n.length > 3 ?
|
|
1196
|
+
return n.length > 3 ? J(this.mergeSameDirectionLine(n)) : [];
|
|
1178
1197
|
}
|
|
1179
1198
|
/**
|
|
1180
1199
|
* 移除短线段
|
|
@@ -1182,48 +1201,48 @@ class I extends X {
|
|
|
1182
1201
|
* @param path
|
|
1183
1202
|
*/
|
|
1184
1203
|
removeShortLine(t, e = this.shortLine) {
|
|
1185
|
-
const n =
|
|
1204
|
+
const n = k(t), i = [], o = Math.PI / 180;
|
|
1186
1205
|
for (let s = 0; s < n.length; s++) {
|
|
1187
|
-
const r = n[s],
|
|
1188
|
-
if (
|
|
1206
|
+
const r = n[s], c = r.length(), a = s;
|
|
1207
|
+
if (c > e || i.length === 0) {
|
|
1189
1208
|
i.push(r);
|
|
1190
1209
|
continue;
|
|
1191
1210
|
}
|
|
1192
1211
|
let h = n[++s];
|
|
1193
1212
|
const l = i[i.length - 1], d = l.direction();
|
|
1194
1213
|
for (; s < n.length; ) {
|
|
1195
|
-
const
|
|
1196
|
-
if (h.length() <= e ||
|
|
1214
|
+
const m = d.angleBetween(h.direction()) / o;
|
|
1215
|
+
if (h.length() <= e || m < 4 || m > 176)
|
|
1197
1216
|
h = n[++s];
|
|
1198
1217
|
else break;
|
|
1199
1218
|
}
|
|
1200
1219
|
if (!h) continue;
|
|
1201
|
-
const
|
|
1202
|
-
if (l.length() >
|
|
1203
|
-
const
|
|
1204
|
-
if (
|
|
1205
|
-
const
|
|
1206
|
-
l.points[1].copy(
|
|
1220
|
+
const f = n[s - 1];
|
|
1221
|
+
if (l.length() > f.length()) {
|
|
1222
|
+
const m = l.getIntersection(h);
|
|
1223
|
+
if (m) {
|
|
1224
|
+
const g = l.points[1].clone(), u = h.points[0].clone();
|
|
1225
|
+
l.points[1].copy(m), h.points[0].copy(m), l.length() < this.width ? (l.points[1].copy(g), h.points[0].copy(g)) : h.length() < this.width && (l.points[1].copy(u), h.points[0].copy(u));
|
|
1207
1226
|
} else
|
|
1208
1227
|
l.points[1].copy(h.points[0]);
|
|
1209
1228
|
i.push(h);
|
|
1210
1229
|
} else
|
|
1211
|
-
s =
|
|
1230
|
+
s = a;
|
|
1212
1231
|
}
|
|
1213
|
-
return i.length > 3 ?
|
|
1232
|
+
return i.length > 3 ? J(i) : [];
|
|
1214
1233
|
}
|
|
1215
1234
|
/** 线偏移
|
|
1216
1235
|
* @description 使用 ClipperLib 对每个点组进行线偏移处理,生成具有指定宽度的墙体路径
|
|
1217
1236
|
*/
|
|
1218
|
-
lineOffset(t =
|
|
1219
|
-
let i = new
|
|
1220
|
-
const o = new
|
|
1237
|
+
lineOffset(t = X.EndType.etOpenSquare, e = X.JoinType.jtMiter, n = 1e4) {
|
|
1238
|
+
let i = new F.Paths();
|
|
1239
|
+
const o = new F.ClipperOffset(20, 0.25);
|
|
1221
1240
|
return this.pointsGroups.forEach((s) => {
|
|
1222
|
-
const r = this.lineTopology(s).map((
|
|
1241
|
+
const r = this.lineTopology(s).map((c) => c.map((a) => a.clone().mutiplyScalar(n)));
|
|
1223
1242
|
o.AddPaths(r, e, t);
|
|
1224
1243
|
}), o.Execute(i, this.width / 2 * n), this.wallsGroup = i.map((s) => {
|
|
1225
|
-
let r = s.map((
|
|
1226
|
-
return r = this.lineSegmentStraightening(r), t ==
|
|
1244
|
+
let r = s.map((c) => p.from(c).divisionScalar(n));
|
|
1245
|
+
return r = this.lineSegmentStraightening(r), t == X.EndType.etOpenSquare && (r = this.squareRemoveBurr(r)), r = this.removeShortLine(r), r;
|
|
1227
1246
|
}), this.dispatchEvent({
|
|
1228
1247
|
type: "lineOffset",
|
|
1229
1248
|
wallsGroup: this.wallsGroup
|
|
@@ -1236,8 +1255,8 @@ class I extends X {
|
|
|
1236
1255
|
const n = [];
|
|
1237
1256
|
return this.wallsGroup.forEach((i) => {
|
|
1238
1257
|
for (let o = 0; o < i.length; o++) {
|
|
1239
|
-
const s = i[o], r = o === i.length - 1 ? 0 : o + 1,
|
|
1240
|
-
n.push(s.X * t, s.Y * t, e,
|
|
1258
|
+
const s = i[o], r = o === i.length - 1 ? 0 : o + 1, c = i[r];
|
|
1259
|
+
n.push(s.X * t, s.Y * t, e, c.X * t, c.Y * t, e);
|
|
1241
1260
|
}
|
|
1242
1261
|
}), new Float32Array(n);
|
|
1243
1262
|
}
|
|
@@ -1249,58 +1268,133 @@ class I extends X {
|
|
|
1249
1268
|
*/
|
|
1250
1269
|
getArcAngleRange(t, e, n) {
|
|
1251
1270
|
const i = e.x - t.x, o = e.y - t.y, s = n.x - t.x, r = n.y - t.y;
|
|
1252
|
-
let
|
|
1253
|
-
|
|
1271
|
+
let c = Math.atan2(o, i), a = Math.atan2(r, s);
|
|
1272
|
+
c = c < 0 ? c + 2 * Math.PI : c, a = a < 0 ? a + 2 * Math.PI : a;
|
|
1254
1273
|
let h, l;
|
|
1255
|
-
return Math.abs(
|
|
1274
|
+
return Math.abs(a - c) <= Math.PI ? (h = Math.min(c, a), l = Math.max(c, a)) : (h = Math.max(c, a), l = Math.min(c, a) + 2 * Math.PI), [h / (Math.PI / 180), l / (Math.PI / 180)];
|
|
1256
1275
|
}
|
|
1257
1276
|
/**
|
|
1258
|
-
*
|
|
1277
|
+
* 转为绘制数据
|
|
1259
1278
|
*/
|
|
1260
|
-
|
|
1261
|
-
const e =
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1279
|
+
toDrawDataJson(t = "Millimeters") {
|
|
1280
|
+
const e = st[t], n = {
|
|
1281
|
+
unit: t,
|
|
1282
|
+
line: [],
|
|
1283
|
+
arc: [],
|
|
1284
|
+
dimensionLine: [],
|
|
1285
|
+
center: this.box.center.toJson(),
|
|
1286
|
+
width: this.box.width * e,
|
|
1287
|
+
height: this.box.height * e,
|
|
1288
|
+
scale: e
|
|
1289
|
+
};
|
|
1290
|
+
let i = "white";
|
|
1291
|
+
function o(a, h) {
|
|
1292
|
+
n.line.push([a.X * e, a.Y * e, h.X * e, h.Y * e, i]);
|
|
1293
|
+
}
|
|
1294
|
+
function s(a, h, l, d) {
|
|
1295
|
+
n.arc.push([
|
|
1296
|
+
a.x * e,
|
|
1297
|
+
a.y * e,
|
|
1298
|
+
h * e,
|
|
1299
|
+
l,
|
|
1300
|
+
d,
|
|
1301
|
+
i
|
|
1302
|
+
]);
|
|
1303
|
+
}
|
|
1304
|
+
for (let a = 0; a < this.originalData.length; a++) {
|
|
1305
|
+
const h = this.originalData[a];
|
|
1306
|
+
if (h.isVerticalReferenceLine) {
|
|
1307
|
+
n.dimensionLine.push([h.start.x * e, h.start.y * e, h.end.x * e, h.end.y * e]);
|
|
1308
|
+
break;
|
|
1309
|
+
}
|
|
1266
1310
|
}
|
|
1267
|
-
this.wallsGroup.forEach((
|
|
1268
|
-
for (let
|
|
1269
|
-
const
|
|
1270
|
-
|
|
1311
|
+
this.wallsGroup.forEach((a) => {
|
|
1312
|
+
for (let h = 0; h < a.length; h++) {
|
|
1313
|
+
const l = a[h], d = h === a.length - 1 ? 0 : h + 1, f = a[d];
|
|
1314
|
+
o(l, f);
|
|
1271
1315
|
}
|
|
1272
1316
|
});
|
|
1273
|
-
const
|
|
1274
|
-
return
|
|
1275
|
-
if (
|
|
1276
|
-
const
|
|
1277
|
-
if (
|
|
1278
|
-
|
|
1279
|
-
const
|
|
1280
|
-
let
|
|
1281
|
-
|
|
1282
|
-
|
|
1317
|
+
const r = this.width * 0.2, c = [];
|
|
1318
|
+
return this.doorLineSegment.forEach((a) => {
|
|
1319
|
+
if (a.length() < 0.4) return;
|
|
1320
|
+
const h = a.clone().expansion(-this.width * 0.5);
|
|
1321
|
+
if (i = "cyan", h.length() < 1.2) {
|
|
1322
|
+
h.expansion(-r * 0.5);
|
|
1323
|
+
const l = a.normal();
|
|
1324
|
+
let d = new b(
|
|
1325
|
+
h.start.clone(),
|
|
1326
|
+
h.start.clone().add(l.clone().multiplyScalar(h.length()))
|
|
1283
1327
|
);
|
|
1284
|
-
const
|
|
1285
|
-
for (let
|
|
1286
|
-
if (
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1328
|
+
const f = d.clone().directionMove(d.normal(), h.length() * -0.5).expandToRectangle(h.length(), "bothSides");
|
|
1329
|
+
for (let L = 0; L < c.length; L++)
|
|
1330
|
+
if (c[L].intersectRectangle(f)) {
|
|
1331
|
+
d = new b(
|
|
1332
|
+
h.start.clone(),
|
|
1333
|
+
h.start.clone().add(l.clone().multiplyScalar(-h.length()))
|
|
1290
1334
|
);
|
|
1291
1335
|
break;
|
|
1292
1336
|
}
|
|
1293
|
-
|
|
1294
|
-
const
|
|
1295
|
-
|
|
1337
|
+
d.expansion(-r * 0.5).expandToRectangle(this.width * 0.2, "bothSides").path2D((L, P) => o(L, P));
|
|
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
|
+
s(x, u, Math.min(w, S), Math.max(w, S)), c.push(f);
|
|
1296
1340
|
} else
|
|
1297
|
-
|
|
1298
|
-
}),
|
|
1299
|
-
if (!
|
|
1300
|
-
Array.isArray(
|
|
1301
|
-
const { p:
|
|
1302
|
-
|
|
1341
|
+
h.clone().expansion(-this.width * 0.5).expandToRectangle(this.width).path2D((l, d) => o(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) => o(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) => o(l, d));
|
|
1342
|
+
}), i = "yellow", this.lineSegments.forEach((a) => {
|
|
1343
|
+
if (!a.userData.isWindow) return !1;
|
|
1344
|
+
Array.isArray(a.userData.drawWindow) && a.userData.drawWindow.forEach((h) => {
|
|
1345
|
+
const { p: l, width: d } = h, f = p.from(l), m = f.clone().add(a.direction().multiplyScalar(d * 0.5)), g = f.clone().add(a.direction().multiplyScalar(-d * 0.5)), u = new b(m, g);
|
|
1346
|
+
o(u.start, u.end), u.expandToRectangle(this.width, "bothSides").path2D((x, w) => o(x, w));
|
|
1303
1347
|
});
|
|
1348
|
+
}), n;
|
|
1349
|
+
}
|
|
1350
|
+
/**
|
|
1351
|
+
*
|
|
1352
|
+
* @param type
|
|
1353
|
+
*/
|
|
1354
|
+
async toDxfImageBlob(t = "Centimeters", e = "image/jpeg") {
|
|
1355
|
+
const n = this.toDrawDataJson(t);
|
|
1356
|
+
let i;
|
|
1357
|
+
if (typeof window < "u")
|
|
1358
|
+
i = document.createElement("canvas");
|
|
1359
|
+
else if (typeof global < "u") {
|
|
1360
|
+
const { createCanvas: c } = await G("canvas");
|
|
1361
|
+
i = c();
|
|
1362
|
+
} else
|
|
1363
|
+
throw new Error("创建画布失败");
|
|
1364
|
+
const o = 2 * n.scale, s = {
|
|
1365
|
+
cyan: "cyan",
|
|
1366
|
+
yellow: "yellow",
|
|
1367
|
+
white: "white"
|
|
1368
|
+
};
|
|
1369
|
+
i.width = n.width + o * 2, i.height = n.height + o * 2;
|
|
1370
|
+
const r = i.getContext("2d");
|
|
1371
|
+
return r.fillRect(0, 0, i.width, i.height), r.translate(n.width * 0.5 + o, n.height * 0.5 + o), n.line.forEach(([c, a, h, l, d]) => {
|
|
1372
|
+
r.strokeStyle = s[d], r.beginPath(), r.moveTo(c, a), r.lineTo(h, l), r.closePath(), r.stroke();
|
|
1373
|
+
}), n.arc.forEach(([c, a, h, l, d, f]) => {
|
|
1374
|
+
r.strokeStyle = s[f], r.beginPath(), r.arc(c, a, h, l * (Math.PI / 180), d * (Math.PI / 180)), r.stroke();
|
|
1375
|
+
}), r.beginPath(), n.dimensionLine.forEach((c) => {
|
|
1376
|
+
let [a, h, l, d] = c;
|
|
1377
|
+
const f = Math.min(h, d), m = Math.max(h, d), g = (i.width * 0.5 - 0.4 * n.scale) * (a < 0 ? -1 : 1), u = (m - f) * 0.45;
|
|
1378
|
+
r.fillStyle = "#fff", r.font = `${0.15 * n.scale}px Arial`, r.textAlign = "center", r.textBaseline = "middle", r.fillText((m - f).toFixed(2) + "cm", g, f + (m - f) * 0.5), r.moveTo(g - 0.1 * n.scale, f), r.lineTo(g + 0.1 * n.scale, f), r.moveTo(g, f), r.lineTo(g, u + f), r.moveTo(g, m), r.lineTo(g, m - u), r.moveTo(g - 0.1 * n.scale, m), r.lineTo(g + 0.1 * n.scale, m);
|
|
1379
|
+
}), r.closePath(), r.strokeStyle = "#fff", r.stroke(), i instanceof HTMLCanvasElement ? new Promise((c) => {
|
|
1380
|
+
i.toBlob((a) => {
|
|
1381
|
+
c(a);
|
|
1382
|
+
}, e, 1);
|
|
1383
|
+
}) : i.toBuffer(e);
|
|
1384
|
+
}
|
|
1385
|
+
/**
|
|
1386
|
+
* 将点json结构转换为Dxf string
|
|
1387
|
+
*/
|
|
1388
|
+
toDxfString(t = "Millimeters") {
|
|
1389
|
+
const e = new R();
|
|
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
|
+
const n = this.toDrawDataJson();
|
|
1392
|
+
return n.line.forEach((i) => {
|
|
1393
|
+
let [o, s, r, c, a] = i;
|
|
1394
|
+
e.setActiveLayer(a), e.drawLine(o, s, r, c);
|
|
1395
|
+
}), n.arc.forEach((i) => {
|
|
1396
|
+
const [o, s, r, c, a, h] = i;
|
|
1397
|
+
e.setActiveLayer(h), e.drawArc(o, s, r, c, a);
|
|
1304
1398
|
}), e.toDxfString();
|
|
1305
1399
|
}
|
|
1306
1400
|
/**
|
|
@@ -1318,16 +1412,29 @@ class I extends X {
|
|
|
1318
1412
|
if (typeof window < "u") {
|
|
1319
1413
|
const n = this.toDxfBlob(e), i = document.createElement("a");
|
|
1320
1414
|
i.href = URL.createObjectURL(n), i.download = t + ".dxf", i.click();
|
|
1321
|
-
} else typeof global < "u" && (await
|
|
1415
|
+
} else typeof global < "u" && (await G("fs", !1)).writeFileSync(t, this.toDxfString(e));
|
|
1416
|
+
}
|
|
1417
|
+
/**
|
|
1418
|
+
* 下载
|
|
1419
|
+
* @param filename
|
|
1420
|
+
*/
|
|
1421
|
+
async downloadImage(t, e = "Centimeters", n = "image/jpg") {
|
|
1422
|
+
const i = await this.toDxfImageBlob(e, n);
|
|
1423
|
+
if (!i) return !1;
|
|
1424
|
+
if (typeof window < "u") {
|
|
1425
|
+
const o = document.createElement("a");
|
|
1426
|
+
o.href = URL.createObjectURL(i), o.download = t, o.click();
|
|
1427
|
+
} else typeof global < "u" && (await G("fs", !1)).writeFileSync(t, i);
|
|
1428
|
+
return !0;
|
|
1322
1429
|
}
|
|
1323
1430
|
/**
|
|
1324
1431
|
* 计算原始数据的边界框
|
|
1325
1432
|
* @description 计算所有线段的起点和终点的最小最大值,形成一个边界框
|
|
1326
1433
|
* @returns
|
|
1327
1434
|
*/
|
|
1328
|
-
computedOriginalSize(t, e = new
|
|
1329
|
-
const n = t.flatMap((
|
|
1330
|
-
return e.set(o, s, r,
|
|
1435
|
+
computedOriginalSize(t, e = new v(0, 0, 0, 0)) {
|
|
1436
|
+
const n = t.flatMap((a) => [a.start.x, a.end.x]), i = t.flatMap((a) => [a.start.y, a.end.y]), o = Math.min(...n), s = Math.min(...i), r = Math.max(...n), c = Math.max(...i);
|
|
1437
|
+
return e.set(o, s, r, c), e;
|
|
1331
1438
|
}
|
|
1332
1439
|
/**
|
|
1333
1440
|
* 创建数据
|
|
@@ -1337,14 +1444,14 @@ class I extends X {
|
|
|
1337
1444
|
static createData(t, e = !0) {
|
|
1338
1445
|
let n = 0;
|
|
1339
1446
|
return t.flatMap((o) => {
|
|
1340
|
-
const s = o.map((r,
|
|
1341
|
-
const
|
|
1447
|
+
const s = o.map((r, c) => {
|
|
1448
|
+
const a = c === o.length - 1 ? 0 : c + 1, h = o[a];
|
|
1342
1449
|
return {
|
|
1343
1450
|
start: { x: r.x, y: r.y },
|
|
1344
1451
|
end: { x: h.x, y: h.y },
|
|
1345
1452
|
insetionArr: [
|
|
1346
1453
|
{
|
|
1347
|
-
index:
|
|
1454
|
+
index: a + n
|
|
1348
1455
|
}
|
|
1349
1456
|
]
|
|
1350
1457
|
};
|
|
@@ -1353,7 +1460,51 @@ class I extends X {
|
|
|
1353
1460
|
});
|
|
1354
1461
|
}
|
|
1355
1462
|
}
|
|
1356
|
-
|
|
1463
|
+
const I = new b();
|
|
1464
|
+
class ot extends X {
|
|
1465
|
+
static name = "AngleCorrectionDxf";
|
|
1466
|
+
onAddFromParent(t) {
|
|
1467
|
+
const e = t.findComponentByName("Dxf"), n = t.findComponentByName("LineAnalysis");
|
|
1468
|
+
n.addEventListener("analysisCompleted", async () => {
|
|
1469
|
+
let i = 0, o = null;
|
|
1470
|
+
for (let a = 0; a < e.originalData.length; a++) {
|
|
1471
|
+
const h = e.originalData[a];
|
|
1472
|
+
if (I.start.copy(h.start), I.end.copy(h.end), h.isVerticalReferenceLine) {
|
|
1473
|
+
const [l, d] = h.start.y < h.end.y ? [I.start, I.end] : [I.end, I.start];
|
|
1474
|
+
i = -new b(l, d).direction().angleBetween(new p(0, 1), "angle", "360"), o = null;
|
|
1475
|
+
break;
|
|
1476
|
+
}
|
|
1477
|
+
(!o || I.length() > o.length()) && (o = I.clone(), o.userData.index = a);
|
|
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 b(a, h).direction().angleBetween(new p(0, 1), "angle", "360");
|
|
1483
|
+
}
|
|
1484
|
+
const s = e.originalBox.center, r = p.zero(), c = e.originalData.map((a) => {
|
|
1485
|
+
const h = r.copy(a.start).division(s).rotate(p.zero(), i * (Math.PI / 180)).toJson(a.start.z), l = r.copy(a.end).division(s).rotate(p.zero(), i * (Math.PI / 180)).toJson(a.end.z), d = Object.assign(O(a), { start: h, end: l });
|
|
1486
|
+
return d.drawWindow && d.drawWindow.forEach((f) => {
|
|
1487
|
+
f.p = r.copy(f.p).division(s).rotate(p.zero(), i * (Math.PI / 180)).toJson(f.p.z), f.p.y = -f.p.y;
|
|
1488
|
+
}), d;
|
|
1489
|
+
});
|
|
1490
|
+
n.appendLineSegmentList.forEach((a) => {
|
|
1491
|
+
const h = a.clone();
|
|
1492
|
+
h.start.division(s).rotate(p.zero(), i * (Math.PI / 180)), h.end.division(s).rotate(p.zero(), i * (Math.PI / 180)), c.push({
|
|
1493
|
+
start: h.start.toJson(e.originalZAverage),
|
|
1494
|
+
end: h.end.toJson(e.originalZAverage),
|
|
1495
|
+
insetionArr: [],
|
|
1496
|
+
length: h.length()
|
|
1497
|
+
});
|
|
1498
|
+
}), c.forEach((a) => {
|
|
1499
|
+
a.start.y = -a.start.y, a.end.y = -a.end.y;
|
|
1500
|
+
}), await this.set(c, e.width, e.scale), this.lineOffset(), this.doorLineSegment = e.doorLineSegment.map((a) => {
|
|
1501
|
+
const h = a.clone();
|
|
1502
|
+
return h.start.division(s).rotate(p.zero(), i * (Math.PI / 180)), h.end.division(s).rotate(p.zero(), i * (Math.PI / 180)), h.start.y = -h.start.y, h.end.y = -h.end.y, h;
|
|
1503
|
+
});
|
|
1504
|
+
});
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
class _ extends j {
|
|
1357
1508
|
static name = "Variable";
|
|
1358
1509
|
originalLineVisible = !0;
|
|
1359
1510
|
dxfVisible = !0;
|
|
@@ -1380,7 +1531,7 @@ class k extends X {
|
|
|
1380
1531
|
if (t in this) return this[t];
|
|
1381
1532
|
}
|
|
1382
1533
|
}
|
|
1383
|
-
class
|
|
1534
|
+
class q {
|
|
1384
1535
|
bounds;
|
|
1385
1536
|
// 包围盒
|
|
1386
1537
|
capacity;
|
|
@@ -1446,23 +1597,23 @@ class B {
|
|
|
1446
1597
|
if (!this.isLeaf) return;
|
|
1447
1598
|
this.isLeaf = !1, this.children = [];
|
|
1448
1599
|
const t = (this.bounds.minX + this.bounds.maxX) / 2, e = (this.bounds.minY + this.bounds.maxY) / 2;
|
|
1449
|
-
this.children[0] = new
|
|
1450
|
-
new
|
|
1600
|
+
this.children[0] = new q(
|
|
1601
|
+
new v(this.bounds.minX, t, this.bounds.minY, e),
|
|
1451
1602
|
this.capacity,
|
|
1452
1603
|
this.maxDepth,
|
|
1453
1604
|
this.depth + 1
|
|
1454
|
-
), this.children[1] = new
|
|
1455
|
-
new
|
|
1605
|
+
), this.children[1] = new q(
|
|
1606
|
+
new v(t, this.bounds.maxX, this.bounds.minY, e),
|
|
1456
1607
|
this.capacity,
|
|
1457
1608
|
this.maxDepth,
|
|
1458
1609
|
this.depth + 1
|
|
1459
|
-
), this.children[2] = new
|
|
1460
|
-
new
|
|
1610
|
+
), this.children[2] = new q(
|
|
1611
|
+
new v(this.bounds.minX, t, e, this.bounds.maxY),
|
|
1461
1612
|
this.capacity,
|
|
1462
1613
|
this.maxDepth,
|
|
1463
1614
|
this.depth + 1
|
|
1464
|
-
), this.children[3] = new
|
|
1465
|
-
new
|
|
1615
|
+
), this.children[3] = new q(
|
|
1616
|
+
new v(t, this.bounds.maxX, e, this.bounds.maxY),
|
|
1466
1617
|
this.capacity,
|
|
1467
1618
|
this.maxDepth,
|
|
1468
1619
|
this.depth + 1
|
|
@@ -1491,7 +1642,7 @@ class B {
|
|
|
1491
1642
|
* @returns 相交的节点数组
|
|
1492
1643
|
*/
|
|
1493
1644
|
queryCircle(t, e) {
|
|
1494
|
-
const n = [], i = new
|
|
1645
|
+
const n = [], i = new v(
|
|
1495
1646
|
t.x - e,
|
|
1496
1647
|
t.x + e,
|
|
1497
1648
|
t.y - e,
|
|
@@ -1500,11 +1651,11 @@ class B {
|
|
|
1500
1651
|
if (!this.bounds.intersectBox(i))
|
|
1501
1652
|
return n;
|
|
1502
1653
|
for (const o of this.nodes) {
|
|
1503
|
-
const [s, r] = o.line.points,
|
|
1504
|
-
let l = ((t.x - s.x) *
|
|
1654
|
+
const [s, r] = o.line.points, c = r.x - s.x, a = r.y - s.y, h = c * c + a * a;
|
|
1655
|
+
let l = ((t.x - s.x) * c + (t.y - s.y) * a) / h;
|
|
1505
1656
|
l = Math.max(0, Math.min(1, l));
|
|
1506
|
-
const d = s.x + l *
|
|
1507
|
-
t.distance(new
|
|
1657
|
+
const d = s.x + l * c, f = s.y + l * a;
|
|
1658
|
+
t.distance(new p(d, f)) <= e && n.push(o);
|
|
1508
1659
|
}
|
|
1509
1660
|
if (!this.isLeaf)
|
|
1510
1661
|
for (const o of this.children)
|
|
@@ -1606,7 +1757,7 @@ class U {
|
|
|
1606
1757
|
*/
|
|
1607
1758
|
decodeGridId(t) {
|
|
1608
1759
|
const [e, n] = t.split(".").map(Number);
|
|
1609
|
-
return new
|
|
1760
|
+
return new p(e, n);
|
|
1610
1761
|
}
|
|
1611
1762
|
/**
|
|
1612
1763
|
* 查询与矩形相交的点
|
|
@@ -1616,10 +1767,10 @@ class U {
|
|
|
1616
1767
|
queryRect(t) {
|
|
1617
1768
|
const e = t.toBox(), n = Math.ceil(e.minX / this.gridSize), i = Math.ceil(e.maxX / this.gridSize), o = Math.ceil(e.minY / this.gridSize), s = Math.ceil(e.maxY / this.gridSize);
|
|
1618
1769
|
for (let r = n; r <= i; r++)
|
|
1619
|
-
for (let
|
|
1620
|
-
const
|
|
1621
|
-
if (!this.map.has(
|
|
1622
|
-
this.map.get(
|
|
1770
|
+
for (let c = o; c <= s; c++) {
|
|
1771
|
+
const a = `${r}.${c}`;
|
|
1772
|
+
if (!this.map.has(a)) continue;
|
|
1773
|
+
this.map.get(a)?.forEach((l) => {
|
|
1623
1774
|
t.containsPoint(l.point);
|
|
1624
1775
|
});
|
|
1625
1776
|
}
|
|
@@ -1631,16 +1782,16 @@ class U {
|
|
|
1631
1782
|
* @returns 相交的节点数组
|
|
1632
1783
|
*/
|
|
1633
1784
|
queryCircle(t, e) {
|
|
1634
|
-
const n = new
|
|
1635
|
-
for (let
|
|
1785
|
+
const n = new v(t.x - e, t.x + e, t.y - e, t.y + e), i = Math.ceil(n.minX / this.gridSize), o = Math.ceil(n.maxX / this.gridSize), s = Math.ceil(n.minY / this.gridSize), r = Math.ceil(n.maxY / this.gridSize), c = [];
|
|
1786
|
+
for (let a = i; a <= o; a++)
|
|
1636
1787
|
for (let h = s; h <= r; h++) {
|
|
1637
|
-
const l = `${
|
|
1788
|
+
const l = `${a}.${h}`;
|
|
1638
1789
|
if (!this.map.has(l)) continue;
|
|
1639
|
-
this.map.get(l)?.forEach((
|
|
1640
|
-
t.distance(
|
|
1790
|
+
this.map.get(l)?.forEach((f) => {
|
|
1791
|
+
t.distance(f.point) <= e && c.push(f);
|
|
1641
1792
|
});
|
|
1642
1793
|
}
|
|
1643
|
-
return
|
|
1794
|
+
return c;
|
|
1644
1795
|
}
|
|
1645
1796
|
/**
|
|
1646
1797
|
* 查询与包围盒相交的点
|
|
@@ -1650,10 +1801,10 @@ class U {
|
|
|
1650
1801
|
queryBox(t) {
|
|
1651
1802
|
const e = Math.ceil(t.minX / this.gridSize), n = Math.ceil(t.maxX / this.gridSize), i = Math.ceil(t.minY / this.gridSize), o = Math.ceil(t.maxY / this.gridSize), s = [];
|
|
1652
1803
|
for (let r = e; r <= n; r++)
|
|
1653
|
-
for (let
|
|
1654
|
-
const
|
|
1655
|
-
if (!this.map.has(
|
|
1656
|
-
this.map.get(
|
|
1804
|
+
for (let c = i; c <= o; c++) {
|
|
1805
|
+
const a = `${r}.${c}`;
|
|
1806
|
+
if (!this.map.has(a)) continue;
|
|
1807
|
+
this.map.get(a)?.forEach((l) => {
|
|
1657
1808
|
t.containsPoint(l.point) && s.push(l);
|
|
1658
1809
|
});
|
|
1659
1810
|
}
|
|
@@ -1670,7 +1821,7 @@ class U {
|
|
|
1670
1821
|
}), n;
|
|
1671
1822
|
}
|
|
1672
1823
|
}
|
|
1673
|
-
class
|
|
1824
|
+
class rt {
|
|
1674
1825
|
// 所有可查找的点位
|
|
1675
1826
|
possibleDoorPoints = [];
|
|
1676
1827
|
doorPoint = [];
|
|
@@ -1704,33 +1855,33 @@ class it {
|
|
|
1704
1855
|
search(t, e = [], n = 0.6, i = this.doorSearchDistance, o = this.doorSearchNearAngle) {
|
|
1705
1856
|
const s = this.dxf, r = this.searchNearby(t, e, i, o);
|
|
1706
1857
|
r.push(
|
|
1707
|
-
...t.map((
|
|
1708
|
-
const h = this.searchAlongDirection(
|
|
1858
|
+
...t.map((a) => {
|
|
1859
|
+
const h = this.searchAlongDirection(a, i);
|
|
1709
1860
|
if (h) return {
|
|
1710
|
-
start:
|
|
1861
|
+
start: a.point,
|
|
1711
1862
|
end: h.point
|
|
1712
1863
|
};
|
|
1713
|
-
const l = this.searchAlongNormalDirection(
|
|
1864
|
+
const l = this.searchAlongNormalDirection(a, i);
|
|
1714
1865
|
if (l) return {
|
|
1715
|
-
start:
|
|
1866
|
+
start: a.point,
|
|
1716
1867
|
end: l.point
|
|
1717
1868
|
};
|
|
1718
|
-
}).filter((
|
|
1869
|
+
}).filter((a) => !!a && a.start.distance(a.end) < i)
|
|
1719
1870
|
);
|
|
1720
|
-
const
|
|
1721
|
-
return r.forEach((
|
|
1722
|
-
const h = new b(
|
|
1871
|
+
const c = [];
|
|
1872
|
+
return r.forEach((a) => {
|
|
1873
|
+
const h = new b(a?.start, a?.end), l = h.length();
|
|
1723
1874
|
if (l < n) return;
|
|
1724
|
-
const d = h.normal(),
|
|
1725
|
-
for (let
|
|
1726
|
-
const u = h.start.clone().add(
|
|
1875
|
+
const d = h.normal(), f = h.direction(), m = (l - s.width * 2) / 2;
|
|
1876
|
+
for (let g = 0; g < 3; g++) {
|
|
1877
|
+
const u = h.start.clone().add(f.clone().multiplyScalar(s.width + m * g)), x = new b(
|
|
1727
1878
|
u,
|
|
1728
1879
|
u.clone().add(d.clone().multiplyScalar(1))
|
|
1729
1880
|
);
|
|
1730
|
-
if (
|
|
1881
|
+
if (x.directionMove(d, -0.5), this.quadtree.queryLineSegment(x).length) return;
|
|
1731
1882
|
}
|
|
1732
|
-
|
|
1733
|
-
}),
|
|
1883
|
+
c.push(h);
|
|
1884
|
+
}), c;
|
|
1734
1885
|
}
|
|
1735
1886
|
/** 添加可查找点的过滤规则
|
|
1736
1887
|
* @param rule
|
|
@@ -1747,7 +1898,7 @@ class it {
|
|
|
1747
1898
|
return this.lineSegments.forEach((e) => {
|
|
1748
1899
|
e.points.forEach((n, i) => {
|
|
1749
1900
|
for (let s = 0; s < this._pointsExcludeRule.length; s++) if (this._pointsExcludeRule[s](e, n, i)) return;
|
|
1750
|
-
this.pointVirtualGrid.queryPoint(n).filter((s) => s.userData !== e).length === 0 && t.push({ line: e, point: n, uuid:
|
|
1901
|
+
this.pointVirtualGrid.queryPoint(n).filter((s) => s.userData !== e).length === 0 && t.push({ line: e, point: n, uuid: z() });
|
|
1751
1902
|
});
|
|
1752
1903
|
}), t;
|
|
1753
1904
|
}
|
|
@@ -1759,21 +1910,21 @@ class it {
|
|
|
1759
1910
|
return e.doors.forEach((i) => {
|
|
1760
1911
|
const o = e.lineSegments[i[4]], s = e.originalData[i[4]];
|
|
1761
1912
|
if (s.drawDoorData) {
|
|
1762
|
-
const r =
|
|
1913
|
+
const r = p.from(s.drawDoorData.start), c = p.from(s.drawDoorData.n), a = n.queryPoint(r).filter((h) => {
|
|
1763
1914
|
if (h.userData === o) return !1;
|
|
1764
1915
|
const l = h.userData, d = l.direction();
|
|
1765
1916
|
l.start.equal(r) && d.multiplyScalar(-1);
|
|
1766
|
-
const
|
|
1767
|
-
return
|
|
1917
|
+
const f = c.angleBetween(d, "angle");
|
|
1918
|
+
return f > 80 || f < 10;
|
|
1768
1919
|
});
|
|
1769
|
-
|
|
1770
|
-
line:
|
|
1920
|
+
a.length && t.push({
|
|
1921
|
+
line: a[0].userData,
|
|
1771
1922
|
point: r,
|
|
1772
|
-
uuid:
|
|
1923
|
+
uuid: z()
|
|
1773
1924
|
});
|
|
1774
1925
|
} else if (s.doorDirectConnection) {
|
|
1775
1926
|
this.continueFind = !1;
|
|
1776
|
-
const r = new b(
|
|
1927
|
+
const r = new b(p.from(s.start), p.from(s.end));
|
|
1777
1928
|
r.userData = {
|
|
1778
1929
|
doorDirectConnection: !0,
|
|
1779
1930
|
isDoor: !0
|
|
@@ -1789,8 +1940,8 @@ class it {
|
|
|
1789
1940
|
searchDoubleLinePoint() {
|
|
1790
1941
|
const t = /* @__PURE__ */ new Map();
|
|
1791
1942
|
return this.resultList.flatMap((e) => {
|
|
1792
|
-
const n = this.lineSegments[e.sourceIndex], i = this.lineSegments[e.targetIndex], o = i.projectPoint(n.start), s = i.projectPoint(n.end), r = n.projectPoint(i.start),
|
|
1793
|
-
t.has(e.sourceIndex) ? t.get(e.sourceIndex) !=
|
|
1943
|
+
const n = this.lineSegments[e.sourceIndex], i = this.lineSegments[e.targetIndex], o = i.projectPoint(n.start), s = i.projectPoint(n.end), r = n.projectPoint(i.start), c = n.projectPoint(i.end), a = o && s ? -1 : o ? 0 : s ? 1 : -1, h = r && c ? -1 : r ? 0 : c ? 1 : -1;
|
|
1944
|
+
t.has(e.sourceIndex) ? t.get(e.sourceIndex) != a && t.set(e.sourceIndex, -1) : t.set(e.sourceIndex, a), t.has(e.targetIndex) ? t.get(e.targetIndex) != h && t.set(e.targetIndex, -1) : t.set(e.targetIndex, h);
|
|
1794
1945
|
}), t;
|
|
1795
1946
|
}
|
|
1796
1947
|
/** 查找方案一:最近点查找
|
|
@@ -1803,94 +1954,94 @@ class it {
|
|
|
1803
1954
|
*/
|
|
1804
1955
|
searchNearby(t, e = [], n = this.doorSearchDistance, i = this.doorSearchNearAngle) {
|
|
1805
1956
|
const o = this.findPointVirtualGrid, s = this.quadtree;
|
|
1806
|
-
function r({ point: u, line:
|
|
1807
|
-
const
|
|
1808
|
-
|
|
1809
|
-
const P = o.queryCircle(u, n).filter((
|
|
1810
|
-
for (let
|
|
1811
|
-
const E = e.findIndex((
|
|
1812
|
-
if (S.has(`${Y}.${
|
|
1813
|
-
S.add(`${Y}.${
|
|
1814
|
-
const
|
|
1815
|
-
if (
|
|
1816
|
-
const
|
|
1817
|
-
P[
|
|
1818
|
-
findData: P[
|
|
1819
|
-
findUuid:
|
|
1820
|
-
doorLine:
|
|
1957
|
+
function r({ point: u, line: x }, w, S) {
|
|
1958
|
+
const L = x.direction();
|
|
1959
|
+
x.start === u && L.multiplyScalar(-1);
|
|
1960
|
+
const P = o.queryCircle(u, n).filter((D) => D.userData !== x).sort((D, E) => D.point.distance(u) - E.point.distance(u)), A = [];
|
|
1961
|
+
for (let D = 0; D < P.length; D++) {
|
|
1962
|
+
const E = e.findIndex((T) => T.point === P[D].point), Y = t[w].uuid, B = e[E].uuid;
|
|
1963
|
+
if (S.has(`${Y}.${B}`)) continue;
|
|
1964
|
+
S.add(`${Y}.${B}`), S.add(`${B}.${Y}`);
|
|
1965
|
+
const Q = P[D].point, C = new b(u.clone(), Q.clone());
|
|
1966
|
+
if (C.direction().angleBetween(L, "angle") < i) {
|
|
1967
|
+
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 && (s.queryLineSegment(C).length || A.push({
|
|
1969
|
+
findData: P[D],
|
|
1970
|
+
findUuid: B,
|
|
1971
|
+
doorLine: C,
|
|
1821
1972
|
doorUuid: Y
|
|
1822
1973
|
}));
|
|
1823
1974
|
}
|
|
1824
1975
|
}
|
|
1825
|
-
return
|
|
1976
|
+
return A;
|
|
1826
1977
|
}
|
|
1827
|
-
function
|
|
1978
|
+
function c(u, x, w, S, L) {
|
|
1828
1979
|
S.add(u);
|
|
1829
1980
|
const P = [];
|
|
1830
|
-
|
|
1831
|
-
for (let
|
|
1832
|
-
const
|
|
1833
|
-
if (
|
|
1834
|
-
const E =
|
|
1835
|
-
|
|
1836
|
-
} else P.push(
|
|
1981
|
+
L && P.push(L);
|
|
1982
|
+
for (let A = 0; A < w.length; A++) {
|
|
1983
|
+
const D = w[A];
|
|
1984
|
+
if (x.has(D.findUuid)) {
|
|
1985
|
+
const E = x.get(D.findUuid);
|
|
1986
|
+
c(D.findUuid, x, E, S, D) && P.push(D);
|
|
1987
|
+
} else P.push(D);
|
|
1837
1988
|
}
|
|
1838
|
-
return P.sort((
|
|
1989
|
+
return P.sort((A, D) => A.doorLine.length() - D.doorLine.length()), L && P[0] === L ? (w.splice(0), !0) : (w.splice(1), !1);
|
|
1839
1990
|
}
|
|
1840
|
-
const
|
|
1841
|
-
t.map((u,
|
|
1842
|
-
const
|
|
1843
|
-
|
|
1844
|
-
}),
|
|
1991
|
+
const a = /* @__PURE__ */ new Set(), h = /* @__PURE__ */ new Map();
|
|
1992
|
+
t.map((u, x) => {
|
|
1993
|
+
const w = r(u, x, a);
|
|
1994
|
+
w.length && h.set(u.uuid, w);
|
|
1995
|
+
}), a.clear();
|
|
1845
1996
|
const l = /* @__PURE__ */ new Map();
|
|
1846
|
-
h.forEach((u,
|
|
1847
|
-
if (!
|
|
1848
|
-
const
|
|
1849
|
-
l.has(
|
|
1997
|
+
h.forEach((u, x) => {
|
|
1998
|
+
if (!a.has(x) && u.length && c(x, h, u, a), u.length) {
|
|
1999
|
+
const w = u[0];
|
|
2000
|
+
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);
|
|
1850
2001
|
}
|
|
1851
2002
|
});
|
|
1852
2003
|
const d = /* @__PURE__ */ new Set();
|
|
1853
2004
|
l.forEach((u) => {
|
|
1854
2005
|
if (u.length > 1) {
|
|
1855
|
-
u.sort((
|
|
1856
|
-
for (let
|
|
2006
|
+
u.sort((x, w) => x.doorLine.length() - w.doorLine.length());
|
|
2007
|
+
for (let x = 1; x < u.length; x++) d.add(u[x]);
|
|
1857
2008
|
}
|
|
1858
2009
|
});
|
|
1859
|
-
const
|
|
2010
|
+
const f = [], m = [];
|
|
1860
2011
|
h.forEach((u) => {
|
|
1861
2012
|
if (u.length) {
|
|
1862
|
-
const
|
|
1863
|
-
d.has(
|
|
2013
|
+
const x = u[0];
|
|
2014
|
+
d.has(x) || (f.push(x), m.push(x.doorUuid, x.findUuid));
|
|
1864
2015
|
}
|
|
1865
2016
|
});
|
|
1866
|
-
const
|
|
1867
|
-
return
|
|
1868
|
-
const
|
|
1869
|
-
if (
|
|
1870
|
-
S.copy(
|
|
1871
|
-
const E = new b(S,
|
|
1872
|
-
(Y < 10 || Y > 170 || Math.abs(90 - Y) < 10) &&
|
|
2017
|
+
const g = [];
|
|
2018
|
+
return f.forEach((u) => {
|
|
2019
|
+
const x = t.findIndex((E) => E.uuid === u.doorUuid), w = e.findIndex((E) => E.uuid === u.findUuid), S = t[x].point.clone(), L = e[w].point.clone(), P = this.findLongLineSegment(t[x].line), A = this.findLongLineSegment(e[w].line), D = P.projectPoint(L);
|
|
2020
|
+
if (D) {
|
|
2021
|
+
S.copy(D);
|
|
2022
|
+
const E = new b(S, L), Y = A.includedAngle(E);
|
|
2023
|
+
(Y < 10 || Y > 170 || Math.abs(90 - Y) < 10) && g.push({
|
|
1873
2024
|
start: S,
|
|
1874
|
-
end:
|
|
2025
|
+
end: L
|
|
1875
2026
|
});
|
|
1876
2027
|
} else {
|
|
1877
|
-
const E =
|
|
1878
|
-
E &&
|
|
1879
|
-
const Y = new b(S,
|
|
1880
|
-
(
|
|
2028
|
+
const E = A.projectPoint(S);
|
|
2029
|
+
E && L.copy(E);
|
|
2030
|
+
const Y = new b(S, L), B = P.includedAngle(Y);
|
|
2031
|
+
(B < 10 || B > 170 || Math.abs(90 - B) < 10) && g.push({
|
|
1881
2032
|
start: S,
|
|
1882
|
-
end:
|
|
2033
|
+
end: L
|
|
1883
2034
|
});
|
|
1884
2035
|
}
|
|
1885
2036
|
}), e.splice(
|
|
1886
2037
|
0,
|
|
1887
2038
|
e.length,
|
|
1888
|
-
...e.filter((u) =>
|
|
2039
|
+
...e.filter((u) => m.indexOf(u.uuid) === -1)
|
|
1889
2040
|
), t.splice(
|
|
1890
2041
|
0,
|
|
1891
2042
|
t.length,
|
|
1892
|
-
...t.filter((u) =>
|
|
1893
|
-
),
|
|
2043
|
+
...t.filter((u) => m.indexOf(u.uuid) === -1)
|
|
2044
|
+
), g;
|
|
1894
2045
|
}
|
|
1895
2046
|
/** 方案二: 沿方向查找
|
|
1896
2047
|
* @description
|
|
@@ -1900,14 +2051,14 @@ class it {
|
|
|
1900
2051
|
searchAlongDirection({ point: t, line: e }, n = this.doorSearchDistance) {
|
|
1901
2052
|
const i = this.quadtree, o = e.direction();
|
|
1902
2053
|
e.start === t && o.multiplyScalar(-1);
|
|
1903
|
-
const s = t.clone().add(o.clone().multiplyScalar(n)), r = new b(t.clone(), s),
|
|
1904
|
-
point:
|
|
1905
|
-
line:
|
|
1906
|
-
})).filter((
|
|
1907
|
-
if (
|
|
1908
|
-
const
|
|
1909
|
-
if (Math.abs(90 -
|
|
1910
|
-
return
|
|
2054
|
+
const s = t.clone().add(o.clone().multiplyScalar(n)), r = new b(t.clone(), s), c = i.queryLineSegment(r).map((a) => ({
|
|
2055
|
+
point: a.line.getIntersection(r),
|
|
2056
|
+
line: a.line
|
|
2057
|
+
})).filter((a) => a.point).sort((a, h) => t.distance(a.point) - t.distance(h.point));
|
|
2058
|
+
if (c.length) {
|
|
2059
|
+
const a = c[0];
|
|
2060
|
+
if (Math.abs(90 - a.line.direction().angleBetween(o, "angle")) < 5)
|
|
2061
|
+
return a;
|
|
1911
2062
|
}
|
|
1912
2063
|
}
|
|
1913
2064
|
/** 方案三: 沿法线方向查找
|
|
@@ -1917,12 +2068,12 @@ class it {
|
|
|
1917
2068
|
* @returns
|
|
1918
2069
|
*/
|
|
1919
2070
|
searchAlongNormalDirection({ point: t, line: e }, n = this.doorSearchDistance) {
|
|
1920
|
-
const i = this.pointVirtualGrid, o = this.quadtree, s = e.direction(), r = e.start.normal(e.end),
|
|
1921
|
-
e.start === t && s.multiplyScalar(-1), e.start === t &&
|
|
1922
|
-
const
|
|
1923
|
-
for (let d = 0; d <
|
|
1924
|
-
const
|
|
1925
|
-
if (
|
|
2071
|
+
const i = this.pointVirtualGrid, o = this.quadtree, s = e.direction(), r = e.start.normal(e.end), c = e.start.clone();
|
|
2072
|
+
e.start === t && s.multiplyScalar(-1), e.start === t && c.copy(e.end);
|
|
2073
|
+
const a = i.queryPoint(c).filter((d) => d.userData !== e);
|
|
2074
|
+
for (let d = 0; d < a.length; d++) {
|
|
2075
|
+
const f = a[d], m = f.userData, g = m.direction();
|
|
2076
|
+
if (m.start === f.point && s.multiplyScalar(-1), g.angleBetween(r) / (Math.PI / 180) > 90) {
|
|
1926
2077
|
r.multiplyScalar(-1);
|
|
1927
2078
|
break;
|
|
1928
2079
|
}
|
|
@@ -1930,7 +2081,7 @@ class it {
|
|
|
1930
2081
|
const h = new b(t.clone(), t.clone().add(r.multiplyScalar(n))), l = o.queryLineSegment(h).map((d) => ({
|
|
1931
2082
|
point: d.line.getIntersection(h),
|
|
1932
2083
|
line: d.line
|
|
1933
|
-
})).filter((d) => d.point).sort((d,
|
|
2084
|
+
})).filter((d) => d.point).sort((d, f) => t.distance(d.point) - t.distance(f.point));
|
|
1934
2085
|
if (l.length) {
|
|
1935
2086
|
const d = l[0];
|
|
1936
2087
|
if (Math.abs(90 - d.line.direction().angleBetween(r, "angle")) < 5)
|
|
@@ -1961,7 +2112,7 @@ class it {
|
|
|
1961
2112
|
return e;
|
|
1962
2113
|
}
|
|
1963
2114
|
}
|
|
1964
|
-
class
|
|
2115
|
+
class at extends j {
|
|
1965
2116
|
static name = "LineAnalysis";
|
|
1966
2117
|
Dxf = null;
|
|
1967
2118
|
Variable = null;
|
|
@@ -1975,7 +2126,7 @@ class st extends X {
|
|
|
1975
2126
|
* @param parent
|
|
1976
2127
|
*/
|
|
1977
2128
|
onAddFromParent(t) {
|
|
1978
|
-
this.Dxf = t.findComponentByType(
|
|
2129
|
+
this.Dxf = t.findComponentByType(X), this.Variable = this.parent?.findComponentByType(_), this.Dxf.addEventListener("setDta", this.lineAnalysis.bind(this)), this.Dxf.addEventListener("createGroup", this.doorsAnalysis.bind(this));
|
|
1979
2130
|
}
|
|
1980
2131
|
/**
|
|
1981
2132
|
*
|
|
@@ -1985,15 +2136,15 @@ class st extends X {
|
|
|
1985
2136
|
* @returns
|
|
1986
2137
|
*/
|
|
1987
2138
|
expandLineSegment(t, e, n = 0.1) {
|
|
1988
|
-
const i = e.normal(t), o = e.direction(t).mutiplyScalar(n * 0.5), s = t.direction(e).mutiplyScalar(n * 0.5), r = i.x * n * 0.5,
|
|
2139
|
+
const i = e.normal(t), o = e.direction(t).mutiplyScalar(n * 0.5), s = t.direction(e).mutiplyScalar(n * 0.5), r = i.x * n * 0.5, c = i.y * n * 0.5;
|
|
1989
2140
|
return {
|
|
1990
2141
|
points: [
|
|
1991
2142
|
// 第一条线
|
|
1992
|
-
new
|
|
1993
|
-
new
|
|
2143
|
+
new p(t.x + r, t.y + c).add(s),
|
|
2144
|
+
new p(e.x + r, e.y + c).add(o),
|
|
1994
2145
|
// 第二条线
|
|
1995
|
-
new
|
|
1996
|
-
new
|
|
2146
|
+
new p(t.x - r, t.y - c).add(s),
|
|
2147
|
+
new p(e.x - r, e.y - c).add(o)
|
|
1997
2148
|
],
|
|
1998
2149
|
indices: [0, 1, 1, 3, 3, 2, 2, 0],
|
|
1999
2150
|
rectIndices: [0, 1, 3, 2, 0]
|
|
@@ -2015,14 +2166,14 @@ class st extends X {
|
|
|
2015
2166
|
createRectangle(t) {
|
|
2016
2167
|
const e = this.Dxf, n = t.project, i = t.project2;
|
|
2017
2168
|
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]);
|
|
2018
|
-
const o = n.points[0].distance(i.points[0]), s = n.points[1].distance(i.points[1]), r = Math.ceil(Math.max(o, s) / e.width),
|
|
2019
|
-
|
|
2020
|
-
const
|
|
2021
|
-
if (!(
|
|
2022
|
-
d.set(
|
|
2169
|
+
const o = n.points[0].distance(i.points[0]), s = n.points[1].distance(i.points[1]), r = Math.ceil(Math.max(o, s) / e.width), c = o / r, a = s / r, h = i.points[0].direction(n.points[0]), l = i.points[1].direction(n.points[1]), d = n.points[0].clone(), f = n.points[1].clone(), m = f.direction(d);
|
|
2170
|
+
m.multiplyScalar(e.width * 0.5);
|
|
2171
|
+
const g = d.clone().add(m), u = f.clone().add(m.multiplyScalar(-1)), x = d.direction(f), w = g.direction(u);
|
|
2172
|
+
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), f.set(u.x, u.y);
|
|
2023
2174
|
for (let S = 1; S < r; S++) {
|
|
2024
|
-
const
|
|
2025
|
-
this.addData(
|
|
2175
|
+
const L = h.clone().multiplyScalar(c * S), P = l.clone().multiplyScalar(a * S), A = d.clone().add(L), D = f.clone().add(P);
|
|
2176
|
+
this.addData(A, D);
|
|
2026
2177
|
}
|
|
2027
2178
|
}
|
|
2028
2179
|
}
|
|
@@ -2032,7 +2183,7 @@ class st extends X {
|
|
|
2032
2183
|
*/
|
|
2033
2184
|
buildQuadtree() {
|
|
2034
2185
|
const t = this.Dxf, e = [];
|
|
2035
|
-
this.quadtree = new
|
|
2186
|
+
this.quadtree = new q(t.originalBox, 2), t.lineSegments.forEach((n) => {
|
|
2036
2187
|
n.userData?.isDoor || (this.quadtree?.insert({
|
|
2037
2188
|
line: n,
|
|
2038
2189
|
userData: e.length
|
|
@@ -2049,8 +2200,8 @@ class st extends X {
|
|
|
2049
2200
|
this.buildQuadtree();
|
|
2050
2201
|
const t = this.quadtree, e = this.lineSegmentList, n = /* @__PURE__ */ new Set(), i = [];
|
|
2051
2202
|
e.forEach((o, s) => {
|
|
2052
|
-
const r = e[s],
|
|
2053
|
-
t.queryRect(
|
|
2203
|
+
const r = e[s], c = N.fromByLineSegment(r, this.width * 2, !1, -0.01);
|
|
2204
|
+
t.queryRect(c).map((h) => h.userData).filter((h) => h !== s).forEach((h) => {
|
|
2054
2205
|
try {
|
|
2055
2206
|
if (n.has(`${s}-${h}`) || n.has(`${h}-${s}`)) return;
|
|
2056
2207
|
const l = this.projectionAnalysis(h, s, r, e);
|
|
@@ -2067,36 +2218,39 @@ class st extends X {
|
|
|
2067
2218
|
* @returns
|
|
2068
2219
|
*/
|
|
2069
2220
|
projectionAnalysis(t, e, n, i) {
|
|
2070
|
-
const o = i[t], s = n.direction(), r = o.direction(),
|
|
2071
|
-
if (
|
|
2072
|
-
let
|
|
2221
|
+
const o = i[t], s = n.direction(), r = o.direction(), c = s.angleBetween(r) / (Math.PI / 180);
|
|
2222
|
+
if (c < this.errorAngle || c > 180 - this.errorAngle) {
|
|
2223
|
+
let a;
|
|
2073
2224
|
const h = o.projectLineSegment(n), l = n.projectLineSegment(o);
|
|
2074
|
-
return h.getLength() > l.getLength() ?
|
|
2225
|
+
return h.getLength() > l.getLength() ? a = {
|
|
2075
2226
|
target: o,
|
|
2076
2227
|
targetIndex: t,
|
|
2077
2228
|
source: n,
|
|
2078
2229
|
sourceIndex: e,
|
|
2079
2230
|
project: h,
|
|
2080
2231
|
project2: l
|
|
2081
|
-
} :
|
|
2232
|
+
} : a = {
|
|
2082
2233
|
target: n,
|
|
2083
2234
|
targetIndex: e,
|
|
2084
2235
|
source: o,
|
|
2085
2236
|
sourceIndex: t,
|
|
2086
2237
|
project: l,
|
|
2087
2238
|
project2: h
|
|
2088
|
-
}, !
|
|
2239
|
+
}, !a || a.project.getLength() < 0.2 || a.project2.getLength() < 0.2 ? void 0 : a;
|
|
2089
2240
|
}
|
|
2090
2241
|
}
|
|
2091
2242
|
doorSearchNearAngle = 110;
|
|
2092
2243
|
doorSearchDistance = 2;
|
|
2093
2244
|
doors = [];
|
|
2094
2245
|
doorsAnalysis() {
|
|
2095
|
-
new
|
|
2246
|
+
new rt(this), this.dispatchEvent({
|
|
2247
|
+
type: "analysisCompleted"
|
|
2248
|
+
});
|
|
2096
2249
|
}
|
|
2097
2250
|
}
|
|
2098
|
-
class
|
|
2251
|
+
class ct extends it {
|
|
2099
2252
|
Dxf;
|
|
2253
|
+
AngleCorrectionDxf;
|
|
2100
2254
|
Variable;
|
|
2101
2255
|
wallWidth;
|
|
2102
2256
|
environment;
|
|
@@ -2105,7 +2259,7 @@ class ot extends et {
|
|
|
2105
2259
|
* @param scale 原始数据缩放比例
|
|
2106
2260
|
*/
|
|
2107
2261
|
constructor(t = 0.1, e = 1) {
|
|
2108
|
-
super(), this.environment = typeof window < "u" ? "browser" : typeof global < "u" ? "node" : "unknown", this.wallWidth = t, this.Dxf = new
|
|
2262
|
+
super(), this.environment = typeof window < "u" ? "browser" : typeof global < "u" ? "node" : "unknown", this.wallWidth = t, this.Dxf = new X(this.wallWidth, e), this.AngleCorrectionDxf = new ot(), this.Variable = new _(), this.addComponent(this.Variable), this.addComponent(this.Dxf), this.addComponent(new at()), this.addComponent(this.AngleCorrectionDxf);
|
|
2109
2263
|
}
|
|
2110
2264
|
usePlugin(t) {
|
|
2111
2265
|
return typeof t == "function" && t.call(this, this), this;
|
|
@@ -2118,23 +2272,23 @@ class ot extends et {
|
|
|
2118
2272
|
});
|
|
2119
2273
|
}
|
|
2120
2274
|
}
|
|
2121
|
-
const
|
|
2122
|
-
function
|
|
2123
|
-
const n = t.normal(
|
|
2275
|
+
const ht = new et(), lt = new nt();
|
|
2276
|
+
function dt(y, t, e = 0.1) {
|
|
2277
|
+
const n = t.normal(y), i = t.direction(y).mutiplyScalar(e * 0.5), o = y.direction(t).mutiplyScalar(e * 0.5), s = n.x * e * 0.5, r = n.y * e * 0.5;
|
|
2124
2278
|
return {
|
|
2125
2279
|
points: [
|
|
2126
2280
|
// 第一条线
|
|
2127
|
-
new
|
|
2128
|
-
new
|
|
2281
|
+
new p(y.x + s, y.y + r).add(o),
|
|
2282
|
+
new p(t.x + s, t.y + r).add(i),
|
|
2129
2283
|
// 第二条线
|
|
2130
|
-
new
|
|
2131
|
-
new
|
|
2284
|
+
new p(y.x - s, y.y - r).add(o),
|
|
2285
|
+
new p(t.x - s, t.y - r).add(i)
|
|
2132
2286
|
],
|
|
2133
2287
|
indices: [0, 1, 1, 3, 3, 2, 2, 0],
|
|
2134
2288
|
rectIndices: [0, 1, 3, 2, 0]
|
|
2135
2289
|
};
|
|
2136
2290
|
}
|
|
2137
|
-
class
|
|
2291
|
+
class H extends j {
|
|
2138
2292
|
static name = "WhiteModel";
|
|
2139
2293
|
Dxf = null;
|
|
2140
2294
|
Variable = null;
|
|
@@ -2155,7 +2309,7 @@ class J extends X {
|
|
|
2155
2309
|
const t = this.Dxf;
|
|
2156
2310
|
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) => {
|
|
2157
2311
|
const i = new M.Shape();
|
|
2158
|
-
n.forEach((r,
|
|
2312
|
+
n.forEach((r, c) => c === 0 ? i.moveTo(r.x / t.scale, r.y / t.scale) : i.lineTo(r.x / t.scale, r.y / t.scale));
|
|
2159
2313
|
const o = new M.ExtrudeGeometry(i, {
|
|
2160
2314
|
depth: 2.8,
|
|
2161
2315
|
bevelSize: 0
|
|
@@ -2164,18 +2318,18 @@ class J extends X {
|
|
|
2164
2318
|
new M.LineSegments(new M.EdgesGeometry(o), new M.LineBasicMaterial({ color: 0 }))
|
|
2165
2319
|
);
|
|
2166
2320
|
}), t.originalData.map(({ start: n, end: i, insetionArr: o }) => {
|
|
2167
|
-
const s = new
|
|
2321
|
+
const s = new p(n.x, n.y).mutiplyScalar(t.scale), r = new p(i.x, i.y).mutiplyScalar(t.scale), { points: c, indices: a, rectIndices: h } = dt(s, r, t.width);
|
|
2168
2322
|
return {
|
|
2169
|
-
points:
|
|
2170
|
-
indices:
|
|
2323
|
+
points: c,
|
|
2324
|
+
indices: a,
|
|
2171
2325
|
rectIndices: h,
|
|
2172
2326
|
insetions: (o ?? []).map((l) => l.index)
|
|
2173
2327
|
};
|
|
2174
2328
|
}).forEach((n) => {
|
|
2175
2329
|
const i = new M.Shape();
|
|
2176
|
-
n.rectIndices.forEach((r,
|
|
2177
|
-
const
|
|
2178
|
-
|
|
2330
|
+
n.rectIndices.forEach((r, c) => {
|
|
2331
|
+
const a = n.points[r];
|
|
2332
|
+
c === 0 ? i.moveTo(a.x, a.y) : i.lineTo(a.x, a.y);
|
|
2179
2333
|
});
|
|
2180
2334
|
const o = new M.ExtrudeGeometry(i, {
|
|
2181
2335
|
depth: 2.8,
|
|
@@ -2197,7 +2351,7 @@ class J extends X {
|
|
|
2197
2351
|
toOBJ() {
|
|
2198
2352
|
return new Promise((t) => {
|
|
2199
2353
|
this.material.opacity = 1, this.material.needsUpdate = !0, setTimeout(() => {
|
|
2200
|
-
t(
|
|
2354
|
+
t(ht.parse(this.whiteModelGroup)), this.material.opacity = 0.8, this.material.transparent = !0;
|
|
2201
2355
|
}, 20);
|
|
2202
2356
|
});
|
|
2203
2357
|
}
|
|
@@ -2210,7 +2364,7 @@ class J extends X {
|
|
|
2210
2364
|
return new Promise((e) => {
|
|
2211
2365
|
this.material.opacity = 1, this.material.needsUpdate = !0, setTimeout(async () => {
|
|
2212
2366
|
if (typeof window == "object")
|
|
2213
|
-
|
|
2367
|
+
lt.parse(this.whiteModelGroup.children, (n) => {
|
|
2214
2368
|
e(n), this.material.opacity = 0.8, this.material.transparent = !0;
|
|
2215
2369
|
}, () => {
|
|
2216
2370
|
e(void 0);
|
|
@@ -2219,7 +2373,7 @@ class J extends X {
|
|
|
2219
2373
|
});
|
|
2220
2374
|
else if (typeof global != "function")
|
|
2221
2375
|
try {
|
|
2222
|
-
const n = await
|
|
2376
|
+
const n = await G("obj2gltf", !0), i = await G("fs", !1), o = await this.toOBJ();
|
|
2223
2377
|
i.writeFileSync(this.uuid, o);
|
|
2224
2378
|
const s = await n(this.uuid, {
|
|
2225
2379
|
binary: t
|
|
@@ -2262,7 +2416,7 @@ class J extends X {
|
|
|
2262
2416
|
n.href = URL.createObjectURL(e), n.download = t, n.click();
|
|
2263
2417
|
} else if (typeof global < "u") {
|
|
2264
2418
|
const e = await this.toOBJ();
|
|
2265
|
-
e && (await
|
|
2419
|
+
e && (await G("fs", !1)).writeFileSync(t, e);
|
|
2266
2420
|
}
|
|
2267
2421
|
}
|
|
2268
2422
|
/**
|
|
@@ -2278,11 +2432,11 @@ class J extends X {
|
|
|
2278
2432
|
i.href = URL.createObjectURL(n), i.download = t, i.click();
|
|
2279
2433
|
} else if (typeof global < "u") {
|
|
2280
2434
|
const n = await this.toGltf(e);
|
|
2281
|
-
n && (await
|
|
2435
|
+
n && (await G("fs", !1)).writeFileSync(t, e ? n : Buffer.from(n));
|
|
2282
2436
|
}
|
|
2283
2437
|
}
|
|
2284
2438
|
}
|
|
2285
|
-
class
|
|
2439
|
+
class Z extends j {
|
|
2286
2440
|
static name = "DetailsPoint";
|
|
2287
2441
|
Dxf = null;
|
|
2288
2442
|
WhiteModel = null;
|
|
@@ -2345,11 +2499,11 @@ class _ extends X {
|
|
|
2345
2499
|
this.racasterHelper(n, i, o), i.z = 0;
|
|
2346
2500
|
const r = new M.Raycaster(n, i, 0, o).intersectObject(t.originalWhiteMode);
|
|
2347
2501
|
if (r.length) {
|
|
2348
|
-
const { point:
|
|
2502
|
+
const { point: c } = r[0];
|
|
2349
2503
|
this.desPoints.push({
|
|
2350
2504
|
message: e.desc,
|
|
2351
2505
|
position: n,
|
|
2352
|
-
intersection:
|
|
2506
|
+
intersection: c
|
|
2353
2507
|
});
|
|
2354
2508
|
}
|
|
2355
2509
|
}), this.dispatchEvent({
|
|
@@ -2359,7 +2513,7 @@ class _ extends X {
|
|
|
2359
2513
|
}, 50);
|
|
2360
2514
|
}
|
|
2361
2515
|
}
|
|
2362
|
-
class
|
|
2516
|
+
class K extends j {
|
|
2363
2517
|
static name = "DxfLineModel";
|
|
2364
2518
|
dxfLineModel = new M.LineSegments();
|
|
2365
2519
|
dxfDoorsLineModel = new M.LineSegments();
|
|
@@ -2382,38 +2536,38 @@ class H extends X {
|
|
|
2382
2536
|
});
|
|
2383
2537
|
}
|
|
2384
2538
|
}
|
|
2385
|
-
const
|
|
2539
|
+
const ut = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2386
2540
|
__proto__: null,
|
|
2387
|
-
DetailsPoint:
|
|
2388
|
-
DxfLineModel:
|
|
2389
|
-
WhiteModel:
|
|
2541
|
+
DetailsPoint: Z,
|
|
2542
|
+
DxfLineModel: K,
|
|
2543
|
+
WhiteModel: H
|
|
2390
2544
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
2391
|
-
function W(
|
|
2545
|
+
function W(y, t = {}) {
|
|
2392
2546
|
const {
|
|
2393
2547
|
detailsPoint: e = !0,
|
|
2394
2548
|
whiteModel: n = !0,
|
|
2395
2549
|
dxfLineModel: i = !0
|
|
2396
2550
|
} = t;
|
|
2397
|
-
i &&
|
|
2551
|
+
i && y.addComponent(new K()), n && y.addComponent(new H()), e && y.addComponent(new Z());
|
|
2398
2552
|
}
|
|
2399
|
-
const
|
|
2400
|
-
create(
|
|
2401
|
-
return (t) => W(t,
|
|
2553
|
+
const ft = Object.assign(W, {
|
|
2554
|
+
create(y = {}) {
|
|
2555
|
+
return (t) => W(t, y);
|
|
2402
2556
|
}
|
|
2403
|
-
}),
|
|
2557
|
+
}), pt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2404
2558
|
__proto__: null,
|
|
2405
|
-
ModelDataPlugin:
|
|
2406
|
-
components:
|
|
2559
|
+
ModelDataPlugin: ft,
|
|
2560
|
+
components: ut
|
|
2407
2561
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
2408
|
-
function
|
|
2562
|
+
function mt() {
|
|
2409
2563
|
return import("./index2.js");
|
|
2410
2564
|
}
|
|
2411
|
-
function
|
|
2565
|
+
function xt() {
|
|
2412
2566
|
return import("./index3.js");
|
|
2413
2567
|
}
|
|
2414
|
-
let
|
|
2415
|
-
async function
|
|
2416
|
-
const i = await Promise.resolve().then(() =>
|
|
2568
|
+
let V = null;
|
|
2569
|
+
async function Et(y, t, e = !1, n) {
|
|
2570
|
+
const i = await Promise.resolve().then(() => pt), o = await mt(), s = await xt(), r = new ct().usePlugin(i.ModelDataPlugin.create({
|
|
2417
2571
|
detailsPoint: !1,
|
|
2418
2572
|
whiteModel: !0
|
|
2419
2573
|
})).usePlugin(o.RenderPlugin.create({
|
|
@@ -2422,14 +2576,14 @@ async function Dt(g, t, e = !1, n) {
|
|
|
2422
2576
|
detailsPoint: !1,
|
|
2423
2577
|
orbitControls: e,
|
|
2424
2578
|
camera: t
|
|
2425
|
-
})).usePlugin(s.Editor.create({ viewPermission: n })),
|
|
2426
|
-
return
|
|
2579
|
+
})).usePlugin(s.Editor.create({ viewPermission: n })), c = r.findComponentByType(o.components.DomContainer);
|
|
2580
|
+
return c && y.appendChild(c.domElement), V = r, {
|
|
2427
2581
|
dxfSystem: r,
|
|
2428
|
-
getFileAll: () =>
|
|
2582
|
+
getFileAll: () => yt(r)
|
|
2429
2583
|
};
|
|
2430
2584
|
}
|
|
2431
|
-
async function
|
|
2432
|
-
const t =
|
|
2585
|
+
async function yt(y = V) {
|
|
2586
|
+
const t = y.findComponentByName("WhiteModel"), e = new File([y.Dxf.toDxfBlob()], "dxf.dxf", { type: "application/dxf" }), n = new File([await t.toOBJBlob()], "model.obj", { type: "application/octet-stream" }), i = new File([await t.toGltfBlob(!0)], "model.glb", { type: "application/octet-stream" }), o = new File([await t.toGltfBlob(!1)], "model.gltf", { type: "application/json" }), s = new File([JSON.stringify(y.Dxf.originalData)], "json.json", { type: "application/json" });
|
|
2433
2587
|
return {
|
|
2434
2588
|
dxf: e,
|
|
2435
2589
|
obj: n,
|
|
@@ -2438,24 +2592,24 @@ async function pt(g = O) {
|
|
|
2438
2592
|
json: s
|
|
2439
2593
|
};
|
|
2440
2594
|
}
|
|
2441
|
-
function
|
|
2442
|
-
return
|
|
2595
|
+
function At() {
|
|
2596
|
+
return V;
|
|
2443
2597
|
}
|
|
2444
2598
|
export {
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2599
|
+
v as B,
|
|
2600
|
+
j as C,
|
|
2601
|
+
ct as D,
|
|
2448
2602
|
$ as E,
|
|
2449
2603
|
b as L,
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2604
|
+
ft as M,
|
|
2605
|
+
p as P,
|
|
2606
|
+
q as Q,
|
|
2607
|
+
_ as V,
|
|
2608
|
+
H as W,
|
|
2609
|
+
Z as a,
|
|
2456
2610
|
U as b,
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2611
|
+
Et as c,
|
|
2612
|
+
At as d,
|
|
2613
|
+
yt as g,
|
|
2614
|
+
ut as i
|
|
2461
2615
|
};
|