jc-structure 0.1.2 → 0.1.5
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/dist/jc-structure.js +179 -147
- package/dist/jc-structure.umd.cjs +2 -2
- package/index.d.ts +197 -132
- package/package.json +1 -1
- package/types/heap.d.ts +2 -0
- package/types/queue.d.ts +2 -1
- package/types/stack.d.ts +2 -1
package/dist/jc-structure.js
CHANGED
|
@@ -10,10 +10,19 @@ class j {
|
|
|
10
10
|
return delete this.items[this.lowestCount], this.lowestCount++, t;
|
|
11
11
|
}
|
|
12
12
|
enqueue(...t) {
|
|
13
|
+
if (t.length === 0)
|
|
14
|
+
return this;
|
|
15
|
+
const e = t.length === 1 && Array.isArray(t[0]) ? t[0] : t;
|
|
16
|
+
return this.batchEnqueue(e), this;
|
|
17
|
+
}
|
|
18
|
+
batchEnqueue(t) {
|
|
13
19
|
t.forEach((e) => {
|
|
14
|
-
this.items[this.count] = e, this.count
|
|
20
|
+
this.isValidItem(e) && (this.items[this.count] = e, this.count++);
|
|
15
21
|
});
|
|
16
22
|
}
|
|
23
|
+
isValidItem(t) {
|
|
24
|
+
return t != null;
|
|
25
|
+
}
|
|
17
26
|
front() {
|
|
18
27
|
return this.isEmpty() ? void 0 : this.items[this.lowestCount];
|
|
19
28
|
}
|
|
@@ -42,10 +51,36 @@ class U {
|
|
|
42
51
|
return delete this.items[this.count], t;
|
|
43
52
|
}
|
|
44
53
|
push(...t) {
|
|
54
|
+
if (t.length === 0)
|
|
55
|
+
return this;
|
|
56
|
+
const e = this.extractItems(t);
|
|
57
|
+
return this.addValidItems(e), this;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 从参数中提取需要添加的元素
|
|
61
|
+
* @param args 传入的参数
|
|
62
|
+
* @returns 需要添加的元素数组
|
|
63
|
+
*/
|
|
64
|
+
extractItems(t) {
|
|
65
|
+
return t.length === 1 && Array.isArray(t[0]) ? t[0] : t;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 添加有效元素到集合中
|
|
69
|
+
* @param items 要添加的元素数组
|
|
70
|
+
*/
|
|
71
|
+
addValidItems(t) {
|
|
45
72
|
t.forEach((e) => {
|
|
46
|
-
this.items[this.count] = e, this.count
|
|
73
|
+
this.isValidItem(e) && (this.items[this.count] = e, this.count++);
|
|
47
74
|
});
|
|
48
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* 验证元素是否有效
|
|
78
|
+
* @param item 要验证的元素
|
|
79
|
+
* @returns 是否有效
|
|
80
|
+
*/
|
|
81
|
+
isValidItem(t) {
|
|
82
|
+
return t != null;
|
|
83
|
+
}
|
|
49
84
|
peek() {
|
|
50
85
|
return this.isEmpty() ? void 0 : this.items[this.count - 1];
|
|
51
86
|
}
|
|
@@ -62,13 +97,13 @@ class U {
|
|
|
62
97
|
return this.isEmpty() ? "" : `Stack(count: ${this.count}):[${this.items[this.count - 1]},...rest]`;
|
|
63
98
|
}
|
|
64
99
|
}
|
|
65
|
-
function
|
|
100
|
+
function N(r, t) {
|
|
66
101
|
return r === t ? 0 : r < t ? -1 : 1;
|
|
67
102
|
}
|
|
68
|
-
class
|
|
103
|
+
class w {
|
|
69
104
|
heap = [];
|
|
70
105
|
compareFn;
|
|
71
|
-
constructor(t =
|
|
106
|
+
constructor(t = N) {
|
|
72
107
|
this.compareFn = t;
|
|
73
108
|
}
|
|
74
109
|
static getLeftIndex(t) {
|
|
@@ -99,7 +134,7 @@ class m {
|
|
|
99
134
|
return this.heap.toString();
|
|
100
135
|
}
|
|
101
136
|
}
|
|
102
|
-
class
|
|
137
|
+
class R extends w {
|
|
103
138
|
insert(t) {
|
|
104
139
|
return t ? !1 : (this.heap.push(t), this.siftUp(this.heap.length - 1), !0);
|
|
105
140
|
}
|
|
@@ -110,24 +145,24 @@ class P extends m {
|
|
|
110
145
|
return this.heap[0] = this.heap.pop(), this.siftDown(0), t;
|
|
111
146
|
}
|
|
112
147
|
siftUp(t) {
|
|
113
|
-
let e = t, s =
|
|
114
|
-
s < n && this.compareFn(this.heap[e], this.heap[s]) === -1 && (e = s), i < n && this.compareFn(this.heap[e], this.heap[i]) === 1 && (e = i), e !== t && (
|
|
148
|
+
let e = t, s = w.getLeftIndex(e), i = w.getRightIndex(e), n = this.size();
|
|
149
|
+
s < n && this.compareFn(this.heap[e], this.heap[s]) === -1 && (e = s), i < n && this.compareFn(this.heap[e], this.heap[i]) === 1 && (e = i), e !== t && (w.swap(this.heap, t, e), this.siftUp(e));
|
|
115
150
|
}
|
|
116
151
|
siftDown(t) {
|
|
117
|
-
let e =
|
|
152
|
+
let e = w.getParentIndex(t);
|
|
118
153
|
for (; t > 0 && e && this.compareFn(this.heap[e], this.heap[t]) === 1; )
|
|
119
|
-
|
|
154
|
+
w.swap(this.heap, e, t), t = e, e = w.getParentIndex(t);
|
|
120
155
|
}
|
|
121
156
|
}
|
|
122
|
-
class
|
|
123
|
-
constructor(t = (e, s) =>
|
|
157
|
+
class q extends R {
|
|
158
|
+
constructor(t = (e, s) => N(s, e)) {
|
|
124
159
|
super(t);
|
|
125
160
|
}
|
|
126
161
|
}
|
|
127
|
-
function
|
|
162
|
+
function k(r) {
|
|
128
163
|
return { value: r };
|
|
129
164
|
}
|
|
130
|
-
class
|
|
165
|
+
class _ {
|
|
131
166
|
capacity;
|
|
132
167
|
length = 0;
|
|
133
168
|
head = null;
|
|
@@ -157,14 +192,14 @@ class D {
|
|
|
157
192
|
}
|
|
158
193
|
update(t, e) {
|
|
159
194
|
let s = this.lookup.get(t);
|
|
160
|
-
s ? (this.detach(s), this.prepend(s), s.value = e) : (s =
|
|
195
|
+
s ? (this.detach(s), this.prepend(s), s.value = e) : (s = k(e), this.length++, this.prepend(s), this.trimCache(), this.lookup.set(t, s), this.reverseLookup);
|
|
161
196
|
}
|
|
162
197
|
}
|
|
163
|
-
let
|
|
198
|
+
let A = class {
|
|
164
199
|
value;
|
|
165
200
|
next = void 0;
|
|
166
201
|
};
|
|
167
|
-
class
|
|
202
|
+
class $ {
|
|
168
203
|
count = 0;
|
|
169
204
|
head = void 0;
|
|
170
205
|
constructor() {
|
|
@@ -197,7 +232,7 @@ class _ {
|
|
|
197
232
|
return this.getElementAt(t)?.value;
|
|
198
233
|
}
|
|
199
234
|
insert(t, e) {
|
|
200
|
-
let s = new
|
|
235
|
+
let s = new A();
|
|
201
236
|
if (s.value = t, e > this.count || e < 0)
|
|
202
237
|
throw new Error("index error");
|
|
203
238
|
this.count++;
|
|
@@ -209,7 +244,7 @@ class _ {
|
|
|
209
244
|
i = this.getElementAt(e - 1), n = i.next, i.next = s, s.next = n;
|
|
210
245
|
}
|
|
211
246
|
push(t) {
|
|
212
|
-
let e = new
|
|
247
|
+
let e = new A();
|
|
213
248
|
if (e.value = t, this.count++, this.isEmpty()) {
|
|
214
249
|
this.head = e;
|
|
215
250
|
return;
|
|
@@ -243,7 +278,7 @@ class _ {
|
|
|
243
278
|
return t = t.slice(0, -1), t;
|
|
244
279
|
}
|
|
245
280
|
}
|
|
246
|
-
class
|
|
281
|
+
class z {
|
|
247
282
|
key;
|
|
248
283
|
value;
|
|
249
284
|
constructor(t, e) {
|
|
@@ -253,7 +288,7 @@ class k {
|
|
|
253
288
|
function L(r, t = { emptyString: !1, zeroNumber: !1 }) {
|
|
254
289
|
return r == null ? !(t.emptyString && r === "" || t.zeroNumber && r === 0) : !1;
|
|
255
290
|
}
|
|
256
|
-
class
|
|
291
|
+
class V {
|
|
257
292
|
table = [];
|
|
258
293
|
constructor() {
|
|
259
294
|
}
|
|
@@ -272,7 +307,7 @@ class z {
|
|
|
272
307
|
let s = this.getItemIndex(t);
|
|
273
308
|
this.table[s].value = e;
|
|
274
309
|
} else {
|
|
275
|
-
const s = new
|
|
310
|
+
const s = new z(t, e);
|
|
276
311
|
this.table.push(s);
|
|
277
312
|
}
|
|
278
313
|
}
|
|
@@ -323,12 +358,12 @@ class z {
|
|
|
323
358
|
return t = t.slice(0, -1), t;
|
|
324
359
|
}
|
|
325
360
|
}
|
|
326
|
-
class
|
|
361
|
+
class H {
|
|
327
362
|
isDirected;
|
|
328
363
|
vertices;
|
|
329
364
|
adjList;
|
|
330
365
|
constructor(t = !1) {
|
|
331
|
-
this.isDirected = t, this.vertices = [], this.adjList = new
|
|
366
|
+
this.isDirected = t, this.vertices = [], this.adjList = new V();
|
|
332
367
|
}
|
|
333
368
|
addVertex(t) {
|
|
334
369
|
this.vertices.includes(t) || (this.vertices.push(t), this.adjList.set(t, []));
|
|
@@ -350,10 +385,10 @@ class q {
|
|
|
350
385
|
return t;
|
|
351
386
|
}
|
|
352
387
|
}
|
|
353
|
-
class
|
|
388
|
+
class g {
|
|
354
389
|
_data;
|
|
355
390
|
static zero(t) {
|
|
356
|
-
return new
|
|
391
|
+
return new g(...Array(t).fill(0));
|
|
357
392
|
}
|
|
358
393
|
constructor(...t) {
|
|
359
394
|
this._data = t;
|
|
@@ -372,7 +407,7 @@ class f {
|
|
|
372
407
|
if (t === 0)
|
|
373
408
|
throw new Error("Cannot normalize a zero vector");
|
|
374
409
|
const e = this._data.map((s) => s / t);
|
|
375
|
-
return new
|
|
410
|
+
return new g(...e);
|
|
376
411
|
}
|
|
377
412
|
add(t) {
|
|
378
413
|
if (this.dimension !== t.dimension)
|
|
@@ -380,7 +415,7 @@ class f {
|
|
|
380
415
|
const e = this._data.map(
|
|
381
416
|
(s, i) => s + t._data[i]
|
|
382
417
|
);
|
|
383
|
-
return new
|
|
418
|
+
return new g(...e);
|
|
384
419
|
}
|
|
385
420
|
sub(t) {
|
|
386
421
|
if (this.dimension !== t.dimension)
|
|
@@ -388,10 +423,10 @@ class f {
|
|
|
388
423
|
const e = this._data.map(
|
|
389
424
|
(s, i) => s - t._data[i]
|
|
390
425
|
);
|
|
391
|
-
return new
|
|
426
|
+
return new g(...e);
|
|
392
427
|
}
|
|
393
428
|
mul(t) {
|
|
394
|
-
return new
|
|
429
|
+
return new g(...this._data.map((e) => e * t));
|
|
395
430
|
}
|
|
396
431
|
dot(t) {
|
|
397
432
|
if (this.dimension !== t.dimension)
|
|
@@ -408,10 +443,10 @@ class f {
|
|
|
408
443
|
return this.mul(-1);
|
|
409
444
|
}
|
|
410
445
|
}
|
|
411
|
-
class
|
|
446
|
+
class E {
|
|
412
447
|
_matrix;
|
|
413
448
|
static zero(t, e) {
|
|
414
|
-
return new
|
|
449
|
+
return new E(
|
|
415
450
|
Array.from({ length: t }, () => Array.from({ length: e }, () => 0))
|
|
416
451
|
);
|
|
417
452
|
}
|
|
@@ -431,10 +466,10 @@ class x {
|
|
|
431
466
|
return this.row * this.col;
|
|
432
467
|
}
|
|
433
468
|
rowVector(t) {
|
|
434
|
-
return new
|
|
469
|
+
return new g(...this._matrix[t]);
|
|
435
470
|
}
|
|
436
471
|
colVector(t) {
|
|
437
|
-
return new
|
|
472
|
+
return new g(...this._matrix.map((e) => e[t]));
|
|
438
473
|
}
|
|
439
474
|
getItem(t) {
|
|
440
475
|
return this._matrix[t[0]][t[1]];
|
|
@@ -443,7 +478,7 @@ class x {
|
|
|
443
478
|
return this._matrix[t[0]][t[1]] = e, this;
|
|
444
479
|
}
|
|
445
480
|
mul(t) {
|
|
446
|
-
return new
|
|
481
|
+
return new E(this._matrix.map((e) => e.map((s) => s * t)));
|
|
447
482
|
}
|
|
448
483
|
div(t) {
|
|
449
484
|
return this.mul(1 / t);
|
|
@@ -451,7 +486,7 @@ class x {
|
|
|
451
486
|
add(t) {
|
|
452
487
|
if (this.row !== t.row || this.col !== t.col)
|
|
453
488
|
throw new Error("Matrix dimensions do not match");
|
|
454
|
-
return new
|
|
489
|
+
return new E(
|
|
455
490
|
this._matrix.map(
|
|
456
491
|
(e, s) => e.map((i, n) => i + t.getItem([s, n]))
|
|
457
492
|
)
|
|
@@ -469,14 +504,14 @@ class x {
|
|
|
469
504
|
mulVector(t) {
|
|
470
505
|
if (this.col !== t.dimension)
|
|
471
506
|
throw new Error("Matrix dimensions do not match");
|
|
472
|
-
return new
|
|
507
|
+
return new E(
|
|
473
508
|
this._matrix.map((e) => e.map((s, i) => s * t.getItem(i)))
|
|
474
509
|
);
|
|
475
510
|
}
|
|
476
511
|
mulMatrix(t) {
|
|
477
512
|
if (this.col !== t.row)
|
|
478
513
|
throw new Error("Matrix dimensions do not match");
|
|
479
|
-
const e =
|
|
514
|
+
const e = E.zero(this.row, t.col);
|
|
480
515
|
for (let s = 0; s < this.row; s++) {
|
|
481
516
|
const i = this.rowVector(s);
|
|
482
517
|
for (let n = 0; n < this.col; n++)
|
|
@@ -498,102 +533,99 @@ class a {
|
|
|
498
533
|
return a.distance(this, t);
|
|
499
534
|
}
|
|
500
535
|
}
|
|
501
|
-
class
|
|
536
|
+
class l {
|
|
502
537
|
// 使用更合适的精度阈值常量
|
|
503
538
|
static EPSILON = 1e-10;
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
if (w >= 0 && w <= 1 && I >= 0 && I <= 1) {
|
|
521
|
-
const C = s + w * (n - s), A = i + w * (o - i);
|
|
522
|
-
return new a(C, A);
|
|
539
|
+
static sloped(t, e = l.EPSILON) {
|
|
540
|
+
const s = t.p2.x - t.p1.x, i = t.p2.y - t.p1.y;
|
|
541
|
+
return Math.abs(s) < e ? Math.abs(i) < e ? 0 : null : i / s;
|
|
542
|
+
}
|
|
543
|
+
static isParallel(t, e, s = l.EPSILON) {
|
|
544
|
+
const i = l.sloped(t), n = l.sloped(e);
|
|
545
|
+
return i === null && n === null ? !0 : i === null || n === null ? !1 : Math.abs(i - n) < s;
|
|
546
|
+
}
|
|
547
|
+
static getIntersection(t, e, s = l.EPSILON) {
|
|
548
|
+
if (l.isParallel(t, e)) return null;
|
|
549
|
+
const i = t.p1.x, n = t.p1.y, o = t.p2.x, h = t.p2.y, u = e.p1.x, p = e.p1.y, d = e.p2.x, m = e.p2.y, f = (i - o) * (p - m) - (n - h) * (u - d);
|
|
550
|
+
if (Math.abs(f) < s) return null;
|
|
551
|
+
const y = ((i - u) * (p - m) - (n - p) * (u - d)) / f, S = -((i - o) * (n - p) - (n - h) * (i - u)) / f;
|
|
552
|
+
if (y >= 0 && y <= 1 && S >= 0 && S <= 1) {
|
|
553
|
+
const O = i + y * (o - i), P = n + y * (h - n);
|
|
554
|
+
return new a(O, P);
|
|
523
555
|
}
|
|
524
556
|
return null;
|
|
525
557
|
}
|
|
526
|
-
// 静态方法:判断两条线段是否相交
|
|
527
558
|
static isIntersecting(t, e) {
|
|
528
|
-
return
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
return Math.hypot(w + I);
|
|
559
|
+
return l.getIntersection(t, e) !== null;
|
|
560
|
+
}
|
|
561
|
+
static distanceToPoint(t, e, s = l.EPSILON) {
|
|
562
|
+
const i = e.x - t.p1.x, n = e.y - t.p1.y, o = t.p2.x - t.p1.x, h = t.p2.y - t.p1.y, u = i * o + n * h, p = o * o + h * h;
|
|
563
|
+
let d = -1;
|
|
564
|
+
p > s && (d = u / p);
|
|
565
|
+
let m, f;
|
|
566
|
+
d < 0 ? (m = t.p1.x, f = t.p1.y) : d > 1 ? (m = t.p2.x, f = t.p2.y) : (m = t.p1.x + d * o, f = t.p1.y + d * h);
|
|
567
|
+
const y = e.x - m, S = e.y - f;
|
|
568
|
+
return Math.hypot(y + S);
|
|
539
569
|
}
|
|
540
570
|
p1;
|
|
541
571
|
p2;
|
|
542
572
|
constructor(t, e) {
|
|
543
573
|
this.p1 = t, this.p2 = e;
|
|
544
574
|
}
|
|
545
|
-
// 获取线段长度
|
|
546
575
|
get length() {
|
|
547
576
|
const t = this.p2.x - this.p1.x, e = this.p2.y - this.p1.y;
|
|
548
577
|
return Math.sqrt(t * t + e * e);
|
|
549
578
|
}
|
|
550
|
-
// 获取线段中点
|
|
551
579
|
get midpoint() {
|
|
552
580
|
const t = (this.p1.x + this.p2.x) / 2, e = (this.p1.y + this.p2.y) / 2;
|
|
553
581
|
return new a(t, e);
|
|
554
582
|
}
|
|
555
|
-
// 获取线段的角度(弧度)
|
|
556
583
|
get angle() {
|
|
557
584
|
return Math.atan2(this.p2.y - this.p1.y, this.p2.x - this.p1.x);
|
|
558
585
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
return Math.abs(e) > u.EPSILON ? !1 : (t.x - this.p1.x) * (t.x - this.p2.x) + (t.y - this.p1.y) * (t.y - this.p2.y) <= u.EPSILON;
|
|
586
|
+
containsPoint(t, e = l.EPSILON) {
|
|
587
|
+
const s = (t.x - this.p1.x) * (this.p2.y - this.p1.y) - (t.y - this.p1.y) * (this.p2.x - this.p1.x);
|
|
588
|
+
return Math.abs(s) > e ? !1 : (t.x - this.p1.x) * (t.x - this.p2.x) + (t.y - this.p1.y) * (t.y - this.p2.y) <= e;
|
|
563
589
|
}
|
|
564
590
|
// 获取线段的方向向量
|
|
565
591
|
get direction() {
|
|
566
592
|
const t = this.length;
|
|
567
|
-
if (t <
|
|
593
|
+
if (t < l.EPSILON) return new a(0, 0);
|
|
568
594
|
const e = (this.p2.x - this.p1.x) / t, s = (this.p2.y - this.p1.y) / t;
|
|
569
595
|
return new a(e, s);
|
|
570
596
|
}
|
|
597
|
+
get start() {
|
|
598
|
+
return this.p1;
|
|
599
|
+
}
|
|
600
|
+
get end() {
|
|
601
|
+
return this.p2;
|
|
602
|
+
}
|
|
571
603
|
}
|
|
572
|
-
class
|
|
604
|
+
class C {
|
|
573
605
|
static EPSILON = 1e-10;
|
|
574
606
|
name;
|
|
575
607
|
constructor(t) {
|
|
576
608
|
this.name = t;
|
|
577
609
|
}
|
|
578
610
|
}
|
|
579
|
-
class
|
|
611
|
+
class c extends C {
|
|
580
612
|
static isValid(t, e, s) {
|
|
581
613
|
return t <= 0 || e <= 0 || s <= 0 ? !1 : t + e > s && t + s > e && e + s > t;
|
|
582
614
|
}
|
|
583
615
|
static area(t, e, s) {
|
|
584
|
-
if (!
|
|
616
|
+
if (!c.isValid(t, e, s))
|
|
585
617
|
throw new Error("Invalid triangle");
|
|
586
618
|
const i = (t + e + s) / 2;
|
|
587
619
|
return Math.sqrt(i * (i - t) * (i - e) * (i - s));
|
|
588
620
|
}
|
|
589
621
|
static getType(t, e, s) {
|
|
590
|
-
if (!
|
|
622
|
+
if (!c.isValid(t, e, s))
|
|
591
623
|
throw new Error("Invalid triangle sides");
|
|
592
|
-
const i = [t, e, s].sort((
|
|
593
|
-
return Math.abs(n - o) <
|
|
624
|
+
const i = [t, e, s].sort((u, p) => u - p), [n, o, h] = i;
|
|
625
|
+
return Math.abs(n - o) < c.EPSILON && Math.abs(o - h) < c.EPSILON ? "equilateral" : Math.abs(n - o) < c.EPSILON || Math.abs(o - h) < c.EPSILON ? "isosceles" : "scalene";
|
|
594
626
|
}
|
|
595
627
|
static getAngles(t, e, s) {
|
|
596
|
-
if (!
|
|
628
|
+
if (!c.isValid(t, e, s))
|
|
597
629
|
throw new Error("Invalid triangle sides");
|
|
598
630
|
const i = Math.acos((e * e + s * s - t * t) / (2 * e * s)), n = Math.acos((t * t + s * s - e * e) / (2 * t * s)), o = Math.PI - i - n;
|
|
599
631
|
return [i, n, o];
|
|
@@ -609,7 +641,7 @@ class h extends N {
|
|
|
609
641
|
areCollinear() {
|
|
610
642
|
return Math.abs(
|
|
611
643
|
(this.p2.x - this.p1.x) * (this.p3.y - this.p1.y) - (this.p3.x - this.p1.x) * (this.p2.y - this.p1.y)
|
|
612
|
-
) <
|
|
644
|
+
) < C.EPSILON;
|
|
613
645
|
}
|
|
614
646
|
get side() {
|
|
615
647
|
return [
|
|
@@ -619,19 +651,19 @@ class h extends N {
|
|
|
619
651
|
];
|
|
620
652
|
}
|
|
621
653
|
perimeter() {
|
|
622
|
-
return
|
|
654
|
+
return c.isValid(this.side[0], this.side[1], this.side[2]), this.side.reduce((t, e) => t + e, 0);
|
|
623
655
|
}
|
|
624
656
|
area() {
|
|
625
657
|
const [t, e, s] = this.side;
|
|
626
|
-
return
|
|
658
|
+
return c.area(t, e, s);
|
|
627
659
|
}
|
|
628
660
|
get type() {
|
|
629
661
|
const [t, e, s] = this.side;
|
|
630
|
-
return
|
|
662
|
+
return c.getType(t, e, s);
|
|
631
663
|
}
|
|
632
664
|
get angles() {
|
|
633
665
|
const [t, e, s] = this.side;
|
|
634
|
-
return
|
|
666
|
+
return c.getAngles(t, e, s);
|
|
635
667
|
}
|
|
636
668
|
get centroid() {
|
|
637
669
|
return new a(
|
|
@@ -645,32 +677,32 @@ class h extends N {
|
|
|
645
677
|
}
|
|
646
678
|
get circumcenter() {
|
|
647
679
|
const t = 2 * (this.p1.x * (this.p2.y - this.p3.y) + this.p2.x * (this.p3.y - this.p1.y) + this.p3.x * (this.p1.y - this.p2.y));
|
|
648
|
-
if (Math.abs(t) <
|
|
680
|
+
if (Math.abs(t) < c.EPSILON)
|
|
649
681
|
throw new Error("Cannot calculate circumcenter for collinear points");
|
|
650
682
|
const e = ((this.p1.x * this.p1.x + this.p1.y * this.p1.y) * (this.p2.y - this.p3.y) + (this.p2.x * this.p2.x + this.p2.y * this.p2.y) * (this.p3.y - this.p1.y) + (this.p3.x * this.p3.x + this.p3.y * this.p3.y) * (this.p1.y - this.p2.y)) / t, s = ((this.p1.x * this.p1.x + this.p1.y * this.p1.y) * (this.p3.x - this.p2.x) + (this.p2.x * this.p2.x + this.p2.y * this.p2.y) * (this.p1.x - this.p3.x) + (this.p3.x * this.p3.x + this.p3.y * this.p3.y) * (this.p2.x - this.p1.x)) / t;
|
|
651
683
|
return new a(e, s);
|
|
652
684
|
}
|
|
653
685
|
containsPoint(t) {
|
|
654
|
-
const e =
|
|
686
|
+
const e = c.area(
|
|
655
687
|
a.distance(t, this.p1),
|
|
656
688
|
a.distance(t, this.p2),
|
|
657
689
|
a.distance(this.p1, this.p2)
|
|
658
|
-
), s =
|
|
690
|
+
), s = c.area(
|
|
659
691
|
a.distance(t, this.p2),
|
|
660
692
|
a.distance(t, this.p3),
|
|
661
693
|
a.distance(this.p2, this.p3)
|
|
662
|
-
), i =
|
|
694
|
+
), i = c.area(
|
|
663
695
|
a.distance(t, this.p3),
|
|
664
696
|
a.distance(t, this.p1),
|
|
665
697
|
a.distance(this.p3, this.p1)
|
|
666
698
|
);
|
|
667
|
-
return Math.abs(e + s + i - this.area()) <
|
|
699
|
+
return Math.abs(e + s + i - this.area()) < c.EPSILON;
|
|
668
700
|
}
|
|
669
701
|
}
|
|
670
|
-
function
|
|
702
|
+
function W(r) {
|
|
671
703
|
return new Promise((t) => setTimeout(t, r));
|
|
672
704
|
}
|
|
673
|
-
function
|
|
705
|
+
function T(r) {
|
|
674
706
|
const t = [], e = {
|
|
675
707
|
"(": ")",
|
|
676
708
|
"[": "]",
|
|
@@ -683,23 +715,23 @@ function W(r) {
|
|
|
683
715
|
return !1;
|
|
684
716
|
return t.length === 0;
|
|
685
717
|
}
|
|
686
|
-
function
|
|
718
|
+
function M(r) {
|
|
687
719
|
return r !== null && (typeof r == "object" || typeof r == "function");
|
|
688
720
|
}
|
|
689
|
-
class
|
|
721
|
+
class F {
|
|
690
722
|
map = /* @__PURE__ */ new Map();
|
|
691
723
|
weakMap = /* @__PURE__ */ new WeakMap();
|
|
692
724
|
set(t, e) {
|
|
693
|
-
|
|
725
|
+
M(t) ? this.weakMap.set(t, e) : this.map.set(t, e);
|
|
694
726
|
}
|
|
695
727
|
get(t) {
|
|
696
|
-
return
|
|
728
|
+
return M(t) ? this.weakMap.get(t) : this.map.get(t);
|
|
697
729
|
}
|
|
698
730
|
has(t) {
|
|
699
|
-
return
|
|
731
|
+
return M(t) ? this.weakMap.has(t) : this.map.has(t);
|
|
700
732
|
}
|
|
701
733
|
}
|
|
702
|
-
function
|
|
734
|
+
function G(r) {
|
|
703
735
|
if (!r.length) return [];
|
|
704
736
|
const t = [[r[0]]];
|
|
705
737
|
for (let s = 1, i = r.length; s < i; s++) {
|
|
@@ -717,7 +749,7 @@ function F(r) {
|
|
|
717
749
|
}
|
|
718
750
|
return t[t.length - 1];
|
|
719
751
|
}
|
|
720
|
-
class
|
|
752
|
+
class B {
|
|
721
753
|
static ROMAN_MAP = /* @__PURE__ */ new Map([
|
|
722
754
|
["M", 1e3],
|
|
723
755
|
["CM", 900],
|
|
@@ -746,10 +778,10 @@ class G {
|
|
|
746
778
|
if (this.ROMAN_MAP.has(o))
|
|
747
779
|
s += this.ROMAN_MAP.get(o), i += 2;
|
|
748
780
|
else {
|
|
749
|
-
const
|
|
750
|
-
if (!
|
|
781
|
+
const h = t[i], u = this.ROMAN_MAP.get(h);
|
|
782
|
+
if (!u)
|
|
751
783
|
throw new Error(`Invalid Roman numeral sequence at position ${i}`);
|
|
752
|
-
s +=
|
|
784
|
+
s += u, i += 1;
|
|
753
785
|
}
|
|
754
786
|
}
|
|
755
787
|
if (this.toRoman(s) !== t)
|
|
@@ -768,7 +800,7 @@ class G {
|
|
|
768
800
|
return e;
|
|
769
801
|
}
|
|
770
802
|
}
|
|
771
|
-
function
|
|
803
|
+
function X(r) {
|
|
772
804
|
let t;
|
|
773
805
|
const e = new Proxy(r, {
|
|
774
806
|
construct(s, i, n) {
|
|
@@ -781,7 +813,7 @@ function B(r) {
|
|
|
781
813
|
});
|
|
782
814
|
return r.prototype.constructor = e, e;
|
|
783
815
|
}
|
|
784
|
-
const
|
|
816
|
+
const x = {
|
|
785
817
|
AUTH_UNAUTHORIZED: "未授权事件",
|
|
786
818
|
AUTH_LOGIN_SUCCESS: "登录成功事件",
|
|
787
819
|
AUTH_LOGOUT: "注销事件",
|
|
@@ -793,12 +825,12 @@ const y = {
|
|
|
793
825
|
UI_HIDE_LOADING: "隐藏加载事件",
|
|
794
826
|
UI_SHOW_MESSAGE: "显示消息事件"
|
|
795
827
|
};
|
|
796
|
-
class
|
|
828
|
+
class v {
|
|
797
829
|
static instance = null;
|
|
798
830
|
listeners = {};
|
|
799
831
|
debugMode;
|
|
800
832
|
constructor(t = !1) {
|
|
801
|
-
this.debugMode = t, Object.keys(
|
|
833
|
+
this.debugMode = t, Object.keys(x).forEach(
|
|
802
834
|
(e) => {
|
|
803
835
|
this.listeners[e] = /* @__PURE__ */ new Set();
|
|
804
836
|
}
|
|
@@ -806,7 +838,7 @@ class b {
|
|
|
806
838
|
}
|
|
807
839
|
// 单例模式
|
|
808
840
|
static getInstance(t) {
|
|
809
|
-
return
|
|
841
|
+
return v.instance || (v.instance = new v(t)), v.instance;
|
|
810
842
|
}
|
|
811
843
|
/**
|
|
812
844
|
* 添加事件监听器
|
|
@@ -814,7 +846,7 @@ class b {
|
|
|
814
846
|
* @param listener 监听函数
|
|
815
847
|
*/
|
|
816
848
|
on(t, e) {
|
|
817
|
-
this.debugLog(`添加事件监听: ${
|
|
849
|
+
this.debugLog(`添加事件监听: ${x[t]}`), this.listeners[t].add(e);
|
|
818
850
|
}
|
|
819
851
|
/**
|
|
820
852
|
* 触发事件
|
|
@@ -822,11 +854,11 @@ class b {
|
|
|
822
854
|
* @param params 事件参数
|
|
823
855
|
*/
|
|
824
856
|
emit(t, e) {
|
|
825
|
-
this.debugLog(`触发事件: ${
|
|
857
|
+
this.debugLog(`触发事件: ${x[t]}`, e), this.listeners[t].forEach((s) => {
|
|
826
858
|
try {
|
|
827
859
|
s(e);
|
|
828
860
|
} catch (i) {
|
|
829
|
-
console.error(`事件 ${
|
|
861
|
+
console.error(`事件 ${x[t]} 处理出错:`, i);
|
|
830
862
|
}
|
|
831
863
|
});
|
|
832
864
|
}
|
|
@@ -836,7 +868,7 @@ class b {
|
|
|
836
868
|
* @param listener 监听函数
|
|
837
869
|
*/
|
|
838
870
|
off(t, e) {
|
|
839
|
-
this.debugLog(`移除事件监听: ${
|
|
871
|
+
this.debugLog(`移除事件监听: ${x[t]}`), this.listeners[t].delete(e);
|
|
840
872
|
}
|
|
841
873
|
/**
|
|
842
874
|
* 添加一次性事件监听器
|
|
@@ -844,7 +876,7 @@ class b {
|
|
|
844
876
|
* @param listener 监听函数
|
|
845
877
|
*/
|
|
846
878
|
once(t, e) {
|
|
847
|
-
this.debugLog(`添加一次性事件监听: ${
|
|
879
|
+
this.debugLog(`添加一次性事件监听: ${x[t]}`);
|
|
848
880
|
const s = (i) => {
|
|
849
881
|
e(i), this.off(t, s);
|
|
850
882
|
};
|
|
@@ -866,7 +898,7 @@ class b {
|
|
|
866
898
|
this.debugMode && console.log(`[EventEmitter] ${t}`, e || "");
|
|
867
899
|
}
|
|
868
900
|
}
|
|
869
|
-
const
|
|
901
|
+
const b = {
|
|
870
902
|
scriptRegex: /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
|
|
871
903
|
javascriptRegex: /javascript:/gi,
|
|
872
904
|
eventHandlerRegex: /on\w+\s*=/gi,
|
|
@@ -913,12 +945,12 @@ const E = {
|
|
|
913
945
|
]),
|
|
914
946
|
allowedAttributes: /* @__PURE__ */ new Set(["class", "id", "href", "src", "alt", "title"])
|
|
915
947
|
};
|
|
916
|
-
class
|
|
948
|
+
class I {
|
|
917
949
|
static instance;
|
|
918
950
|
constructor() {
|
|
919
951
|
}
|
|
920
952
|
static getInstance() {
|
|
921
|
-
return
|
|
953
|
+
return I.instance || (I.instance = new I()), I.instance;
|
|
922
954
|
}
|
|
923
955
|
/**
|
|
924
956
|
* 创建DOM元素
|
|
@@ -928,7 +960,7 @@ class v {
|
|
|
928
960
|
* @returns 创建的HTMLElement
|
|
929
961
|
*/
|
|
930
962
|
createElement(t, e = {}, s = "") {
|
|
931
|
-
if (!
|
|
963
|
+
if (!b.allowedTags.has(t.toLowerCase()))
|
|
932
964
|
throw new Error(`Unsupported tag: ${t}`);
|
|
933
965
|
const i = document.createElement(t);
|
|
934
966
|
return this._processAttributes(i, e), this._processContent(i, s), i;
|
|
@@ -964,7 +996,7 @@ class v {
|
|
|
964
996
|
*/
|
|
965
997
|
_processAttributes(t, e) {
|
|
966
998
|
Object.entries(e).forEach(([s, i]) => {
|
|
967
|
-
if (!
|
|
999
|
+
if (!b.allowedAttributes.has(s) && !s.startsWith("data-")) {
|
|
968
1000
|
console.warn(`Potentially unsafe attribute: ${s}`);
|
|
969
1001
|
return;
|
|
970
1002
|
}
|
|
@@ -1003,10 +1035,10 @@ class v {
|
|
|
1003
1035
|
* @private
|
|
1004
1036
|
*/
|
|
1005
1037
|
_sanitizeHtml(t) {
|
|
1006
|
-
return t.replace(
|
|
1038
|
+
return t.replace(b.scriptRegex, "").replace(b.javascriptRegex, "").replace(b.eventHandlerRegex, "");
|
|
1007
1039
|
}
|
|
1008
1040
|
}
|
|
1009
|
-
class
|
|
1041
|
+
class Q {
|
|
1010
1042
|
features;
|
|
1011
1043
|
constructor() {
|
|
1012
1044
|
this.features = this.detectFeatures();
|
|
@@ -1155,32 +1187,32 @@ Text.prototype.surround = function(r = "strong", t = "") {
|
|
|
1155
1187
|
if (!this.nodeValue || !r || !t) return null;
|
|
1156
1188
|
const s = r.split("."), i = s[0], n = s.slice(1).join(" "), o = this.textContent.indexOf(t);
|
|
1157
1189
|
if (o < 0) return null;
|
|
1158
|
-
const
|
|
1159
|
-
|
|
1160
|
-
const
|
|
1161
|
-
return n && (
|
|
1190
|
+
const h = document.createRange();
|
|
1191
|
+
h.setStart(this, o), h.setEnd(this, o + t.length);
|
|
1192
|
+
const u = document.createElement(i);
|
|
1193
|
+
return n && (u.className = n), h.surroundContents(u), u;
|
|
1162
1194
|
};
|
|
1163
1195
|
export {
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1196
|
+
V as Dictionary,
|
|
1197
|
+
I as DomHelper,
|
|
1198
|
+
v as Emitter,
|
|
1199
|
+
H as Graph,
|
|
1200
|
+
G as LIS,
|
|
1201
|
+
_ as LRU,
|
|
1202
|
+
l as Line,
|
|
1203
|
+
$ as LinkedList,
|
|
1204
|
+
E as Matrix,
|
|
1205
|
+
q as MaxHeap,
|
|
1206
|
+
F as MemoizeMap,
|
|
1207
|
+
R as MinHeap,
|
|
1176
1208
|
a as Point,
|
|
1177
1209
|
j as Queue,
|
|
1178
|
-
|
|
1210
|
+
B as Roman,
|
|
1179
1211
|
U as Stack,
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1212
|
+
c as Triangle,
|
|
1213
|
+
g as Vector,
|
|
1214
|
+
Q as WebAppManager,
|
|
1215
|
+
T as isValidBracket,
|
|
1216
|
+
X as singleton,
|
|
1217
|
+
W as sleep
|
|
1186
1218
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(a,
|
|
2
|
-
`;return t}}class f{_data;static zero(t){return new f(...Array(t).fill(0))}constructor(...t){this._data=t}get dimension(){return this._data.length}get norm(){return Math.hypot(...this._data)}getItem(t){return this._data[t]}normalize(){const t=this.norm;if(t===0)throw new Error("Cannot normalize a zero vector");const e=this._data.map(s=>s/t);return new f(...e)}add(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to add");const e=this._data.map((s,i)=>s+t._data[i]);return new f(...e)}sub(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to subtract");const e=this._data.map((s,i)=>s-t._data[i]);return new f(...e)}mul(t){return new f(...this._data.map(e=>e*t))}dot(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to dot product");return this._data.reduce((e,s,i)=>e+s*t._data[i],0)}pos(){return this.mul(1)}neg(){return this.mul(-1)}}class w{_matrix;static zero(t,e){return new w(Array.from({length:t},()=>Array.from({length:e},()=>0)))}constructor(t){this._matrix=t}get shape(){return[this._matrix.length,this._matrix[0].length]}get row(){return this.shape[0]}get col(){return this.shape[1]}get size(){return this.row*this.col}rowVector(t){return new f(...this._matrix[t])}colVector(t){return new f(...this._matrix.map(e=>e[t]))}getItem(t){return this._matrix[t[0]][t[1]]}setItem(t,e){return this._matrix[t[0]][t[1]]=e,this}mul(t){return new w(this._matrix.map(e=>e.map(s=>s*t)))}div(t){return this.mul(1/t)}add(t){if(this.row!==t.row||this.col!==t.col)throw new Error("Matrix dimensions do not match");return new w(this._matrix.map((e,s)=>e.map((i,n)=>i+t.getItem([s,n]))))}sub(t){return this.add(t.neg())}pos(){return this.mul(1)}neg(){return this.mul(-1)}mulVector(t){if(this.col!==t.dimension)throw new Error("Matrix dimensions do not match");return new w(this._matrix.map(e=>e.map((s,i)=>s*t.getItem(i))))}mulMatrix(t){if(this.col!==t.row)throw new Error("Matrix dimensions do not match");const e=w.zero(this.row,t.col);for(let s=0;s<this.row;s++){const i=this.rowVector(s);for(let n=0;n<this.col;n++)e.setItem([s,n],i.dot(t.colVector(n)))}return e}}class h{static distance(t,e){return Math.hypot(e.x-t.x,e.y-t.y)}x;y;constructor(t,e){this.x=t,this.y=e}distanceTo(t){return h.distance(this,t)}}class p{static EPSILON=1e-10;static sloped(t){const e=t.p2.x-t.p1.x,s=t.p2.y-t.p1.y;return Math.abs(e)<p.EPSILON?Math.abs(s)<p.EPSILON?0:null:s/e}static isParallel(t,e){const s=p.sloped(t),i=p.sloped(e);return s===null&&i===null?!0:s===null||i===null?!1:Math.abs(s-i)<p.EPSILON}static getIntersection(t,e){if(p.isParallel(t,e))return null;const s=t.p1.x,i=t.p1.y,n=t.p2.x,o=t.p2.y,l=e.p1.x,u=e.p1.y,d=e.p2.x,y=e.p2.y,g=(s-n)*(u-y)-(i-o)*(l-d);if(Math.abs(g)<p.EPSILON)return null;const v=((s-l)*(u-y)-(i-u)*(l-d))/g,S=-((s-n)*(i-u)-(i-o)*(s-l))/g;if(v>=0&&v<=1&&S>=0&&S<=1){const B=s+v*(n-s),X=i+v*(o-i);return new h(B,X)}return null}static isIntersecting(t,e){return p.getIntersection(t,e)!==null}static distanceToPoint(t,e){const s=e.x-t.p1.x,i=e.y-t.p1.y,n=t.p2.x-t.p1.x,o=t.p2.y-t.p1.y,l=s*n+i*o,u=n*n+o*o;let d=-1;u>p.EPSILON&&(d=l/u);let y,g;d<0?(y=t.p1.x,g=t.p1.y):d>1?(y=t.p2.x,g=t.p2.y):(y=t.p1.x+d*n,g=t.p1.y+d*o);const v=e.x-y,S=e.y-g;return Math.hypot(v+S)}p1;p2;constructor(t,e){this.p1=t,this.p2=e}get length(){const t=this.p2.x-this.p1.x,e=this.p2.y-this.p1.y;return Math.sqrt(t*t+e*e)}get midpoint(){const t=(this.p1.x+this.p2.x)/2,e=(this.p1.y+this.p2.y)/2;return new h(t,e)}get angle(){return Math.atan2(this.p2.y-this.p1.y,this.p2.x-this.p1.x)}containsPoint(t){const e=(t.x-this.p1.x)*(this.p2.y-this.p1.y)-(t.y-this.p1.y)*(this.p2.x-this.p1.x);return Math.abs(e)>p.EPSILON?!1:(t.x-this.p1.x)*(t.x-this.p2.x)+(t.y-this.p1.y)*(t.y-this.p2.y)<=p.EPSILON}get direction(){const t=this.length;if(t<p.EPSILON)return new h(0,0);const e=(this.p2.x-this.p1.x)/t,s=(this.p2.y-this.p1.y)/t;return new h(e,s)}}class R{static EPSILON=1e-10;name;constructor(t){this.name=t}}class c extends R{static isValid(t,e,s){return t<=0||e<=0||s<=0?!1:t+e>s&&t+s>e&&e+s>t}static area(t,e,s){if(!c.isValid(t,e,s))throw new Error("Invalid triangle");const i=(t+e+s)/2;return Math.sqrt(i*(i-t)*(i-e)*(i-s))}static getType(t,e,s){if(!c.isValid(t,e,s))throw new Error("Invalid triangle sides");const i=[t,e,s].sort((u,d)=>u-d),[n,o,l]=i;return Math.abs(n-o)<c.EPSILON&&Math.abs(o-l)<c.EPSILON?"equilateral":Math.abs(n-o)<c.EPSILON||Math.abs(o-l)<c.EPSILON?"isosceles":"scalene"}static getAngles(t,e,s){if(!c.isValid(t,e,s))throw new Error("Invalid triangle sides");const i=Math.acos((e*e+s*s-t*t)/(2*e*s)),n=Math.acos((t*t+s*s-e*e)/(2*t*s)),o=Math.PI-i-n;return[i,n,o]}p1;p2;p3;constructor(t,e,s,i="triangle"){if(super(i),this.p1=t,this.p2=e,this.p3=s,this.areCollinear())throw new Error("Points are collinear, cannot form a triangle")}areCollinear(){return Math.abs((this.p2.x-this.p1.x)*(this.p3.y-this.p1.y)-(this.p3.x-this.p1.x)*(this.p2.y-this.p1.y))<R.EPSILON}get side(){return[h.distance(this.p1,this.p2),h.distance(this.p2,this.p3),h.distance(this.p3,this.p1)]}perimeter(){return c.isValid(this.side[0],this.side[1],this.side[2]),this.side.reduce((t,e)=>t+e,0)}area(){const[t,e,s]=this.side;return c.area(t,e,s)}get type(){const[t,e,s]=this.side;return c.getType(t,e,s)}get angles(){const[t,e,s]=this.side;return c.getAngles(t,e,s)}get centroid(){return new h((this.p1.x+this.p2.x+this.p3.x)/3,(this.p1.y+this.p2.y+this.p3.y)/3)}get incenter(){const[t,e,s]=this.side,i=this.perimeter()/2,n=(t*this.p1.x+e*this.p2.x+s*this.p3.x)/i,o=(t*this.p1.y+e*this.p2.y+s*this.p3.y)/i;return new h(n,o)}get circumcenter(){const t=2*(this.p1.x*(this.p2.y-this.p3.y)+this.p2.x*(this.p3.y-this.p1.y)+this.p3.x*(this.p1.y-this.p2.y));if(Math.abs(t)<c.EPSILON)throw new Error("Cannot calculate circumcenter for collinear points");const e=((this.p1.x*this.p1.x+this.p1.y*this.p1.y)*(this.p2.y-this.p3.y)+(this.p2.x*this.p2.x+this.p2.y*this.p2.y)*(this.p3.y-this.p1.y)+(this.p3.x*this.p3.x+this.p3.y*this.p3.y)*(this.p1.y-this.p2.y))/t,s=((this.p1.x*this.p1.x+this.p1.y*this.p1.y)*(this.p3.x-this.p2.x)+(this.p2.x*this.p2.x+this.p2.y*this.p2.y)*(this.p1.x-this.p3.x)+(this.p3.x*this.p3.x+this.p3.y*this.p3.y)*(this.p2.x-this.p1.x))/t;return new h(e,s)}containsPoint(t){const e=c.area(h.distance(t,this.p1),h.distance(t,this.p2),h.distance(this.p1,this.p2)),s=c.area(h.distance(t,this.p2),h.distance(t,this.p3),h.distance(this.p2,this.p3)),i=c.area(h.distance(t,this.p3),h.distance(t,this.p1),h.distance(this.p3,this.p1));return Math.abs(e+s+i-this.area())<c.EPSILON}}function $(r){return new Promise(t=>setTimeout(t,r))}function W(r){const t=[],e={"(":")","[":"]","{":"}"},s=new Set(Object.values(e));for(const i of r)if(i in e)t.push(e[i]);else if(s.has(i)&&i!==t.pop())return!1;return t.length===0}function L(r){return r!==null&&(typeof r=="object"||typeof r=="function")}class _{map=new Map;weakMap=new WeakMap;set(t,e){L(t)?this.weakMap.set(t,e):this.map.set(t,e)}get(t){return L(t)?this.weakMap.get(t):this.map.get(t)}has(t){return L(t)?this.weakMap.has(t):this.map.has(t)}}function q(r){if(!r.length)return[];const t=[[r[0]]];for(let s=1,i=r.length;s<i;s++){const n=r[s];e(n)}function e(s){for(let i=t.length-1;i>=0;i--){const n=t[i],o=n[t[i].length-1];if(o<s){t[i+1]=[...n,s];break}else o>s&&i===0&&(t[i]=[s])}}return t[t.length-1]}class T{static ROMAN_MAP=new Map([["M",1e3],["CM",900],["D",500],["CD",400],["C",100],["XC",90],["L",50],["XL",40],["X",10],["IX",9],["V",5],["IV",4],["I",1]]);static toInteger(t){if(t.length===0)throw new Error("Input cannot be empty");const e=new Set(["I","V","X","L","C","D","M"]);for(const o of t)if(!e.has(o))throw new Error(`Invalid Roman numeral character: ${o}`);let s=0,i=0;for(;i<t.length;){const o=t.slice(i,i+2);if(this.ROMAN_MAP.has(o))s+=this.ROMAN_MAP.get(o),i+=2;else{const l=t[i],u=this.ROMAN_MAP.get(l);if(!u)throw new Error(`Invalid Roman numeral sequence at position ${i}`);s+=u,i+=1}}if(this.toRoman(s)!==t)throw new Error("Invalid Roman numeral sequence");return s}static toRoman(t){if(t<=0||t>=4e3)throw new Error("Number must be between 1 and 3999");if(!Number.isInteger(t))throw new Error("Number must be an integer");let e="";for(const[s,i]of this.ROMAN_MAP)for(;t>=i;)e+=s,t-=i;return e}}function G(r){let t;const e=new Proxy(r,{construct(s,i,n){return t||(t=Reflect.construct(s,i,n)),t}});return r.prototype.constructor=e,e}const E={AUTH_UNAUTHORIZED:"未授权事件",AUTH_LOGIN_SUCCESS:"登录成功事件",AUTH_LOGOUT:"注销事件",AUTH_TOKEN_EXPIRED:"令牌过期事件",REQUEST_ERROR:"请求错误事件",REQUEST_TIMEOUT:"请求超时事件",REQUEST_NETWORK_ERROR:"网络错误事件",UI_SHOW_LOADING:"显示加载事件",UI_HIDE_LOADING:"隐藏加载事件",UI_SHOW_MESSAGE:"显示消息事件"};class x{static instance=null;listeners={};debugMode;constructor(t=!1){this.debugMode=t,Object.keys(E).forEach(e=>{this.listeners[e]=new Set})}static getInstance(t){return x.instance||(x.instance=new x(t)),x.instance}on(t,e){this.debugLog(`添加事件监听: ${E[t]}`),this.listeners[t].add(e)}emit(t,e){this.debugLog(`触发事件: ${E[t]}`,e),this.listeners[t].forEach(s=>{try{s(e)}catch(i){console.error(`事件 ${E[t]} 处理出错:`,i)}})}off(t,e){this.debugLog(`移除事件监听: ${E[t]}`),this.listeners[t].delete(e)}once(t,e){this.debugLog(`添加一次性事件监听: ${E[t]}`);const s=i=>{e(i),this.off(t,s)};this.on(t,s)}clear(){this.debugLog("清除所有事件监听器"),Object.values(this.listeners).forEach(t=>t.clear())}getListenerCount(t){return this.listeners[t].size}debugLog(t,e){this.debugMode&&console.log(`[EventEmitter] ${t}`,e||"")}}const M={scriptRegex:/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,javascriptRegex:/javascript:/gi,eventHandlerRegex:/on\w+\s*=/gi,allowedTags:new Set(["div","span","p","a","img","button","input","form","label","select","option","textarea","ul","ol","li","table","tr","td","th","thead","tbody","tfoot","h1","h2","h3","h4","h5","h6","hr","br","section","article","nav","header","footer","main","aside","figure","figcaption"]),allowedAttributes:new Set(["class","id","href","src","alt","title"])};class b{static instance;constructor(){}static getInstance(){return b.instance||(b.instance=new b),b.instance}createElement(t,e={},s=""){if(!M.allowedTags.has(t.toLowerCase()))throw new Error(`Unsupported tag: ${t}`);const i=document.createElement(t);return this._processAttributes(i,e),this._processContent(i,s),i}createBatch(t,e){const s=document.createDocumentFragment();t.forEach(i=>{const n=this.createElement(i.tag,i.attributes||{},i.content||"");s.appendChild(n)}),e.appendChild(s)}setHtml(t,e){const s=this._sanitizeHtml(e);t.innerHTML=s}_processAttributes(t,e){Object.entries(e).forEach(([s,i])=>{if(!M.allowedAttributes.has(s)&&!s.startsWith("data-")){console.warn(`Potentially unsafe attribute: ${s}`);return}if(typeof i=="function")s.startsWith("on")&&t.addEventListener(s.slice(2).toLowerCase(),i);else switch(s){case"className":t.className=i;break;case"dataset":Object.assign(t.dataset,i);break;case"style":Object.assign(t.style,i);break;default:t.setAttribute(s,i)}})}_processContent(t,e){typeof e=="string"?t.textContent=e:e instanceof Node?t.appendChild(e):Array.isArray(e)&&e.forEach(s=>{typeof s=="string"?t.appendChild(document.createTextNode(s)):t.appendChild(s)})}_sanitizeHtml(t){return t.replace(M.scriptRegex,"").replace(M.javascriptRegex,"").replace(M.eventHandlerRegex,"")}}class F{features;constructor(){this.features=this.detectFeatures()}detectFeatures(){return{geolocation:"geolocation"in navigator,notification:"Notification"in window,serviceWorker:"serviceWorker"in navigator,webShare:"share"in navigator,deviceOrientation:"DeviceOrientationEvent"in window,battery:"getBattery"in navigator,online:"onLine"in navigator}}async getLocation(t={}){if(!this.features.geolocation)throw new Error("Geolocation is not supported");const e={enableHighAccuracy:!0,timeout:10*1e3,maximumAge:300*1e3};return new Promise((s,i)=>{navigator.geolocation.getCurrentPosition(n=>s({latitude:n.coords.latitude,longitude:n.coords.longitude,accuracy:n.coords.accuracy,timstamp:n.timestamp}),n=>{const o={1:"User denied the request for Geolocation.",2:"Position information is unavailable.",3:"The request to get user location timed out."};i(new Error(o[n.code]||"Unknown error"))},{...e,...t})})}async sendNotification(t,e){if(!this.features.notification)throw new Error("Notification is not supported");if(Notification.permission==="default"&&await Notification.requestPermission()!=="granted")throw new Error("Notification permission is not granted");if(Notification.permission!=="granted")throw new Error("Notification permission is not granted");return new Notification(t,{icon:e.icon,badge:e.badge,...e})}async registerServiceWorker(t){if(!this.features.serviceWorker)throw new Error("Service Worker is not supported");try{const e=await navigator.serviceWorker.register(t);return console.log("Service Worker registered with scope:",e),e}catch(e){throw console.error("Service Worker registration failed:",e),e}}async shareContent(t){if(this.features.webShare)try{return await navigator.share(t),!0}catch(e){return e instanceof Error&&e.name!="AbortError"&&console.error("Error sharing content:",e),!1}else try{return await navigator.clipboard.writeText(t.url||t.text||""),this.sendNotification("Copied to clipboard",{body:"Link copied to clipboard"}),!0}catch(e){return console.error("Error copying to clipboard:",e),!1}}}String.prototype.pointLength=function(){let r=0;for(let t=0,e=this.length;t<e;){const s=this.codePointAt(t);t+=s>65535?2:1,r++}return r},String.prototype.pointAt=function(r){if(r>=this.pointLength())return;let t=0;for(let e=0,s=this.length;e<s;){const i=this.codePointAt(e);if(!i)return;if(t===r)return String.fromCodePoint(i);e+=i>65535?2:1,t++}},String.prototype.sliceByPoint=function(r,t=this.pointLength()){let e="";for(let s=r;s<t;s++)e+=this.pointAt(s);return e},RegExp.escape=function(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},Element.prototype.farthest=function(r){if(typeof r!="string"||!r)return null;let t=null,e=this;for(;e;){const s=e.closest(r);if(!s)break;t=s,e=s.parentElement}return t},Object.defineProperties(Element.prototype,{firstElement:{get:function(){if(!this.children.length)return null;let r=this.firstElementChild,t=null;for(;r;)t=r,r=r.firstElementChild;return t}},lastElement:{get:function(){if(!this.children.length)return null;let r=this.lastElementChild,t=null;for(;r;)t=r,r=r.lastElementChild;return t}}}),Text.prototype.surround=function(r="strong",t=""){if(!this.nodeValue||!r||!t)return null;const s=r.split("."),i=s[0],n=s.slice(1).join(" "),o=this.textContent.indexOf(t);if(o<0)return null;const l=document.createRange();l.setStart(this,o),l.setEnd(this,o+t.length);const u=document.createElement(i);return n&&(u.className=n),l.surroundContents(u),u},a.Dictionary=P,a.DomHelper=b,a.Emitter=x,a.Graph=H,a.LIS=q,a.LRU=U,a.Line=p,a.LinkedList=V,a.Matrix=w,a.MaxHeap=j,a.MemoizeMap=_,a.MinHeap=O,a.Point=h,a.Queue=I,a.Roman=T,a.Stack=k,a.Triangle=c,a.Vector=f,a.WebAppManager=F,a.isValidBracket=W,a.singleton=G,a.sleep=$,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(a,M){typeof exports=="object"&&typeof module<"u"?M(exports):typeof define=="function"&&define.amd?define(["exports"],M):(a=typeof globalThis<"u"?globalThis:a||self,M(a["jc-structure"]={}))})(this,(function(a){"use strict";class M{items={};count=0;lowestCount=0;constructor(){}dequeue(){if(this.isEmpty())return;const t=this.items[this.lowestCount];return delete this.items[this.lowestCount],this.lowestCount++,t}enqueue(...t){if(t.length===0)return this;const e=t.length===1&&Array.isArray(t[0])?t[0]:t;return this.batchEnqueue(e),this}batchEnqueue(t){t.forEach(e=>{this.isValidItem(e)&&(this.items[this.count]=e,this.count++)})}isValidItem(t){return t!=null}front(){return this.isEmpty()?void 0:this.items[this.lowestCount]}isEmpty(){return this.size()===0}size(){return this.count-this.lowestCount}clear(){this.items={},this.count=0,this.lowestCount=0}toString(){return this.isEmpty()?"":`Queue(size: ${this.size()}):[${this.items[this.lowestCount]},...rest]`}}class j{items={};count=0;constructor(){}pop(){if(this.isEmpty())return;this.count--;const t=this.items[this.count];return delete this.items[this.count],t}push(...t){if(t.length===0)return this;const e=this.extractItems(t);return this.addValidItems(e),this}extractItems(t){return t.length===1&&Array.isArray(t[0])?t[0]:t}addValidItems(t){t.forEach(e=>{this.isValidItem(e)&&(this.items[this.count]=e,this.count++)})}isValidItem(t){return t!=null}peek(){return this.isEmpty()?void 0:this.items[this.count-1]}isEmpty(){return this.count===0}size(){return this.count}clear(){this.items={},this.count=0}toString(){return this.isEmpty()?"":`Stack(count: ${this.count}):[${this.items[this.count-1]},...rest]`}}function C(r,t){return r===t?0:r<t?-1:1}class y{heap=[];compareFn;constructor(t=C){this.compareFn=t}static getLeftIndex(t){return 2*t+1}static getRightIndex(t){return 2*t+2}static getParentIndex(t){return t===0?void 0:Math.floor((t-1)/2)}static swap(t,e,s){[t[e],t[s]]=[t[s],t[e]]}find(){return this.isEmpty()?void 0:this.heap[0]}size(){return this.heap.length}isEmpty(){return this.size()===0}clear(){this.heap=[]}toString(){return this.heap.toString()}}class N extends y{insert(t){return t?!1:(this.heap.push(t),this.siftUp(this.heap.length-1),!0)}extract(){if(this.isEmpty())return;if(this.heap.length===1)return this.heap.shift();const t=this.heap[0];return this.heap[0]=this.heap.pop(),this.siftDown(0),t}siftUp(t){let e=t,s=y.getLeftIndex(e),i=y.getRightIndex(e),n=this.size();s<n&&this.compareFn(this.heap[e],this.heap[s])===-1&&(e=s),i<n&&this.compareFn(this.heap[e],this.heap[i])===1&&(e=i),e!==t&&(y.swap(this.heap,t,e),this.siftUp(e))}siftDown(t){let e=y.getParentIndex(t);for(;t>0&&e&&this.compareFn(this.heap[e],this.heap[t])===1;)y.swap(this.heap,e,t),t=e,e=y.getParentIndex(t)}}class z extends N{constructor(t=(e,s)=>C(s,e)){super(t)}}function V(r){return{value:r}}class U{capacity;length=0;head=null;tail=null;lookup=new Map;reverseLookup=new Map;constructor(t=10){this.capacity=t}prepend(t){this.head?(t.next=this.head,this.head.prev=t,this.head=t):this.head=this.tail=t}detach(t){t.prev&&(t.prev.next=t.next),t.next&&(t.next.prev=t.prev),this.head===t&&(this.head=this.head.next||null),this.tail===t&&(this.tail=this.tail.prev||null),t.next=void 0,t.prev=void 0}trimCache(){if(this.length<=this.capacity)return;const t=this.tail;this.detach(t);const e=this.reverseLookup.get(t);this.lookup.delete(e),this.reverseLookup.delete(t),this.length--}get(t){const e=this.lookup.get(t);if(e)return this.detach(e),this.prepend(e),e.value}update(t,e){let s=this.lookup.get(t);s?(this.detach(s),this.prepend(s),s.value=e):(s=V(e),this.length++,this.prepend(s),this.trimCache(),this.lookup.set(t,s),this.reverseLookup)}}let O=class{value;next=void 0};class D{count=0;head=void 0;constructor(){}indexOf(t){let e=this.head,s=0,i=!1;for(;e;){if(this.equals(e.value,t)){i=!0;break}s++,e=e.next}return i?s:-1}equals(t,e){return!1}getElementAt(t){if(t<0||t>=this.count)return;if(t===0)return this.head;let e=this.head;for(let s=0;s<t;s++)e=e?.next;return e}getValueAt(t){return this.getElementAt(t)?.value}insert(t,e){let s=new O;if(s.value=t,e>this.count||e<0)throw new Error("index error");this.count++;let i,n;if(e===0){s.next=this.head,this.head=s;return}i=this.getElementAt(e-1),n=i.next,i.next=s,s.next=n}push(t){let e=new O;if(e.value=t,this.count++,this.isEmpty()){this.head=e;return}let s=this.getElementAt(this.count-1);s.next=e}remove(t){const e=this.indexOf(t);return e===-1?void 0:this.removeAt(e)}removeAt(t){if(this.isEmpty()||t<0||t>=this.count)return;let e=this.getElementAt(t),s=this.getElementAt(t-1),i=e?.next;return t===0&&(this.head=i),s&&(s.next=i),this.count--,e?.value}isEmpty(){return this.count===0}size(){return this.count}clear(){this.count=0,this.head=void 0}toString(){let t="",e=this.head;for(;e;)t+=e.value,t+=",",e=e.next;return t=t.slice(0,-1),t}}class q{key;value;constructor(t,e){this.key=t,this.value=e}}function P(r,t={emptyString:!1,zeroNumber:!1}){return r==null?!(t.emptyString&&r===""||t.zeroNumber&&r===0):!1}class R{table=[];constructor(){}getItemIndex(t){for(let e=0,s=this.table.length;e<s;e++)if(this.table[e].key===t)return e;return-1}set(t,e){if(P(t))throw new Error("key is required");if(P(e))throw new Error("value is required");if(this.has(t)){let s=this.getItemIndex(t);this.table[s].value=e}else{const s=new q(t,e);this.table.push(s)}}remove(t){if(this.has(t)){let e=this.getItemIndex(t);return this.table.splice(e,1)[0]}}has(t){return this.getItemIndex(t)!==-1}get(t){if(this.has(t)){let e=this.getItemIndex(t);return this.table[e]}}keys(){return this.table.map(t=>t.key)}values(){return this.table.map(t=>t.value)}keyValues(){return this.table.map(t=>[t.key,t.value])}forEach(t){for(let e=0,s=this.size();e<s;e++){let i=this.table[e];if(!t(i.key,i.value))break}}isEmpty(){return!this.size()}size(){return this.table.length}clear(){this.table=[]}toString(){let t="";for(let e=0,s=this.table.length;e<s;e++)t+=this.table[e].toString(),t+=",";return t=t.slice(0,-1),t}}class H{isDirected;vertices;adjList;constructor(t=!1){this.isDirected=t,this.vertices=[],this.adjList=new R}addVertex(t){this.vertices.includes(t)||(this.vertices.push(t),this.adjList.set(t,[]))}addEdge(t,e){this.adjList.get(t)||this.addVertex(t),this.adjList.get(e)||this.addVertex(e),this.adjList.get(t)?.value.indexOf(e)===-1&&this.adjList.get(t)?.value.push(e),this.isDirected||this.adjList.get(e)?.value.indexOf(t)===-1&&this.adjList.get(e)?.value.push(t)}getVertices(){return this.vertices}getAdjacencyList(){return this.adjList}toString(){let t="";for(let e=0;e<this.vertices.length;e++)t+=this.vertices[e]+"-->",t+=this.adjList.get(this.vertices[e])?.toString()||"",t+=`
|
|
2
|
+
`;return t}}class d{_data;static zero(t){return new d(...Array(t).fill(0))}constructor(...t){this._data=t}get dimension(){return this._data.length}get norm(){return Math.hypot(...this._data)}getItem(t){return this._data[t]}normalize(){const t=this.norm;if(t===0)throw new Error("Cannot normalize a zero vector");const e=this._data.map(s=>s/t);return new d(...e)}add(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to add");const e=this._data.map((s,i)=>s+t._data[i]);return new d(...e)}sub(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to subtract");const e=this._data.map((s,i)=>s-t._data[i]);return new d(...e)}mul(t){return new d(...this._data.map(e=>e*t))}dot(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to dot product");return this._data.reduce((e,s,i)=>e+s*t._data[i],0)}pos(){return this.mul(1)}neg(){return this.mul(-1)}}class w{_matrix;static zero(t,e){return new w(Array.from({length:t},()=>Array.from({length:e},()=>0)))}constructor(t){this._matrix=t}get shape(){return[this._matrix.length,this._matrix[0].length]}get row(){return this.shape[0]}get col(){return this.shape[1]}get size(){return this.row*this.col}rowVector(t){return new d(...this._matrix[t])}colVector(t){return new d(...this._matrix.map(e=>e[t]))}getItem(t){return this._matrix[t[0]][t[1]]}setItem(t,e){return this._matrix[t[0]][t[1]]=e,this}mul(t){return new w(this._matrix.map(e=>e.map(s=>s*t)))}div(t){return this.mul(1/t)}add(t){if(this.row!==t.row||this.col!==t.col)throw new Error("Matrix dimensions do not match");return new w(this._matrix.map((e,s)=>e.map((i,n)=>i+t.getItem([s,n]))))}sub(t){return this.add(t.neg())}pos(){return this.mul(1)}neg(){return this.mul(-1)}mulVector(t){if(this.col!==t.dimension)throw new Error("Matrix dimensions do not match");return new w(this._matrix.map(e=>e.map((s,i)=>s*t.getItem(i))))}mulMatrix(t){if(this.col!==t.row)throw new Error("Matrix dimensions do not match");const e=w.zero(this.row,t.col);for(let s=0;s<this.row;s++){const i=this.rowVector(s);for(let n=0;n<this.col;n++)e.setItem([s,n],i.dot(t.colVector(n)))}return e}}class h{static distance(t,e){return Math.hypot(e.x-t.x,e.y-t.y)}x;y;constructor(t,e){this.x=t,this.y=e}distanceTo(t){return h.distance(this,t)}}class p{static EPSILON=1e-10;static sloped(t,e=p.EPSILON){const s=t.p2.x-t.p1.x,i=t.p2.y-t.p1.y;return Math.abs(s)<e?Math.abs(i)<e?0:null:i/s}static isParallel(t,e,s=p.EPSILON){const i=p.sloped(t),n=p.sloped(e);return i===null&&n===null?!0:i===null||n===null?!1:Math.abs(i-n)<s}static getIntersection(t,e,s=p.EPSILON){if(p.isParallel(t,e))return null;const i=t.p1.x,n=t.p1.y,o=t.p2.x,u=t.p2.y,l=e.p1.x,f=e.p1.y,g=e.p2.x,E=e.p2.y,m=(i-o)*(f-E)-(n-u)*(l-g);if(Math.abs(m)<s)return null;const I=((i-l)*(f-E)-(n-f)*(l-g))/m,L=-((i-o)*(n-f)-(n-u)*(i-l))/m;if(I>=0&&I<=1&&L>=0&&L<=1){const X=i+I*(o-i),Q=n+I*(u-n);return new h(X,Q)}return null}static isIntersecting(t,e){return p.getIntersection(t,e)!==null}static distanceToPoint(t,e,s=p.EPSILON){const i=e.x-t.p1.x,n=e.y-t.p1.y,o=t.p2.x-t.p1.x,u=t.p2.y-t.p1.y,l=i*o+n*u,f=o*o+u*u;let g=-1;f>s&&(g=l/f);let E,m;g<0?(E=t.p1.x,m=t.p1.y):g>1?(E=t.p2.x,m=t.p2.y):(E=t.p1.x+g*o,m=t.p1.y+g*u);const I=e.x-E,L=e.y-m;return Math.hypot(I+L)}p1;p2;constructor(t,e){this.p1=t,this.p2=e}get length(){const t=this.p2.x-this.p1.x,e=this.p2.y-this.p1.y;return Math.sqrt(t*t+e*e)}get midpoint(){const t=(this.p1.x+this.p2.x)/2,e=(this.p1.y+this.p2.y)/2;return new h(t,e)}get angle(){return Math.atan2(this.p2.y-this.p1.y,this.p2.x-this.p1.x)}containsPoint(t,e=p.EPSILON){const s=(t.x-this.p1.x)*(this.p2.y-this.p1.y)-(t.y-this.p1.y)*(this.p2.x-this.p1.x);return Math.abs(s)>e?!1:(t.x-this.p1.x)*(t.x-this.p2.x)+(t.y-this.p1.y)*(t.y-this.p2.y)<=e}get direction(){const t=this.length;if(t<p.EPSILON)return new h(0,0);const e=(this.p2.x-this.p1.x)/t,s=(this.p2.y-this.p1.y)/t;return new h(e,s)}get start(){return this.p1}get end(){return this.p2}}class k{static EPSILON=1e-10;name;constructor(t){this.name=t}}class c extends k{static isValid(t,e,s){return t<=0||e<=0||s<=0?!1:t+e>s&&t+s>e&&e+s>t}static area(t,e,s){if(!c.isValid(t,e,s))throw new Error("Invalid triangle");const i=(t+e+s)/2;return Math.sqrt(i*(i-t)*(i-e)*(i-s))}static getType(t,e,s){if(!c.isValid(t,e,s))throw new Error("Invalid triangle sides");const i=[t,e,s].sort((l,f)=>l-f),[n,o,u]=i;return Math.abs(n-o)<c.EPSILON&&Math.abs(o-u)<c.EPSILON?"equilateral":Math.abs(n-o)<c.EPSILON||Math.abs(o-u)<c.EPSILON?"isosceles":"scalene"}static getAngles(t,e,s){if(!c.isValid(t,e,s))throw new Error("Invalid triangle sides");const i=Math.acos((e*e+s*s-t*t)/(2*e*s)),n=Math.acos((t*t+s*s-e*e)/(2*t*s)),o=Math.PI-i-n;return[i,n,o]}p1;p2;p3;constructor(t,e,s,i="triangle"){if(super(i),this.p1=t,this.p2=e,this.p3=s,this.areCollinear())throw new Error("Points are collinear, cannot form a triangle")}areCollinear(){return Math.abs((this.p2.x-this.p1.x)*(this.p3.y-this.p1.y)-(this.p3.x-this.p1.x)*(this.p2.y-this.p1.y))<k.EPSILON}get side(){return[h.distance(this.p1,this.p2),h.distance(this.p2,this.p3),h.distance(this.p3,this.p1)]}perimeter(){return c.isValid(this.side[0],this.side[1],this.side[2]),this.side.reduce((t,e)=>t+e,0)}area(){const[t,e,s]=this.side;return c.area(t,e,s)}get type(){const[t,e,s]=this.side;return c.getType(t,e,s)}get angles(){const[t,e,s]=this.side;return c.getAngles(t,e,s)}get centroid(){return new h((this.p1.x+this.p2.x+this.p3.x)/3,(this.p1.y+this.p2.y+this.p3.y)/3)}get incenter(){const[t,e,s]=this.side,i=this.perimeter()/2,n=(t*this.p1.x+e*this.p2.x+s*this.p3.x)/i,o=(t*this.p1.y+e*this.p2.y+s*this.p3.y)/i;return new h(n,o)}get circumcenter(){const t=2*(this.p1.x*(this.p2.y-this.p3.y)+this.p2.x*(this.p3.y-this.p1.y)+this.p3.x*(this.p1.y-this.p2.y));if(Math.abs(t)<c.EPSILON)throw new Error("Cannot calculate circumcenter for collinear points");const e=((this.p1.x*this.p1.x+this.p1.y*this.p1.y)*(this.p2.y-this.p3.y)+(this.p2.x*this.p2.x+this.p2.y*this.p2.y)*(this.p3.y-this.p1.y)+(this.p3.x*this.p3.x+this.p3.y*this.p3.y)*(this.p1.y-this.p2.y))/t,s=((this.p1.x*this.p1.x+this.p1.y*this.p1.y)*(this.p3.x-this.p2.x)+(this.p2.x*this.p2.x+this.p2.y*this.p2.y)*(this.p1.x-this.p3.x)+(this.p3.x*this.p3.x+this.p3.y*this.p3.y)*(this.p2.x-this.p1.x))/t;return new h(e,s)}containsPoint(t){const e=c.area(h.distance(t,this.p1),h.distance(t,this.p2),h.distance(this.p1,this.p2)),s=c.area(h.distance(t,this.p2),h.distance(t,this.p3),h.distance(this.p2,this.p3)),i=c.area(h.distance(t,this.p3),h.distance(t,this.p1),h.distance(this.p3,this.p1));return Math.abs(e+s+i-this.area())<c.EPSILON}}function _(r){return new Promise(t=>setTimeout(t,r))}function $(r){const t=[],e={"(":")","[":"]","{":"}"},s=new Set(Object.values(e));for(const i of r)if(i in e)t.push(e[i]);else if(s.has(i)&&i!==t.pop())return!1;return t.length===0}function A(r){return r!==null&&(typeof r=="object"||typeof r=="function")}class T{map=new Map;weakMap=new WeakMap;set(t,e){A(t)?this.weakMap.set(t,e):this.map.set(t,e)}get(t){return A(t)?this.weakMap.get(t):this.map.get(t)}has(t){return A(t)?this.weakMap.has(t):this.map.has(t)}}function W(r){if(!r.length)return[];const t=[[r[0]]];for(let s=1,i=r.length;s<i;s++){const n=r[s];e(n)}function e(s){for(let i=t.length-1;i>=0;i--){const n=t[i],o=n[t[i].length-1];if(o<s){t[i+1]=[...n,s];break}else o>s&&i===0&&(t[i]=[s])}}return t[t.length-1]}class G{static ROMAN_MAP=new Map([["M",1e3],["CM",900],["D",500],["CD",400],["C",100],["XC",90],["L",50],["XL",40],["X",10],["IX",9],["V",5],["IV",4],["I",1]]);static toInteger(t){if(t.length===0)throw new Error("Input cannot be empty");const e=new Set(["I","V","X","L","C","D","M"]);for(const o of t)if(!e.has(o))throw new Error(`Invalid Roman numeral character: ${o}`);let s=0,i=0;for(;i<t.length;){const o=t.slice(i,i+2);if(this.ROMAN_MAP.has(o))s+=this.ROMAN_MAP.get(o),i+=2;else{const u=t[i],l=this.ROMAN_MAP.get(u);if(!l)throw new Error(`Invalid Roman numeral sequence at position ${i}`);s+=l,i+=1}}if(this.toRoman(s)!==t)throw new Error("Invalid Roman numeral sequence");return s}static toRoman(t){if(t<=0||t>=4e3)throw new Error("Number must be between 1 and 3999");if(!Number.isInteger(t))throw new Error("Number must be an integer");let e="";for(const[s,i]of this.ROMAN_MAP)for(;t>=i;)e+=s,t-=i;return e}}function F(r){let t;const e=new Proxy(r,{construct(s,i,n){return t||(t=Reflect.construct(s,i,n)),t}});return r.prototype.constructor=e,e}const x={AUTH_UNAUTHORIZED:"未授权事件",AUTH_LOGIN_SUCCESS:"登录成功事件",AUTH_LOGOUT:"注销事件",AUTH_TOKEN_EXPIRED:"令牌过期事件",REQUEST_ERROR:"请求错误事件",REQUEST_TIMEOUT:"请求超时事件",REQUEST_NETWORK_ERROR:"网络错误事件",UI_SHOW_LOADING:"显示加载事件",UI_HIDE_LOADING:"隐藏加载事件",UI_SHOW_MESSAGE:"显示消息事件"};class b{static instance=null;listeners={};debugMode;constructor(t=!1){this.debugMode=t,Object.keys(x).forEach(e=>{this.listeners[e]=new Set})}static getInstance(t){return b.instance||(b.instance=new b(t)),b.instance}on(t,e){this.debugLog(`添加事件监听: ${x[t]}`),this.listeners[t].add(e)}emit(t,e){this.debugLog(`触发事件: ${x[t]}`,e),this.listeners[t].forEach(s=>{try{s(e)}catch(i){console.error(`事件 ${x[t]} 处理出错:`,i)}})}off(t,e){this.debugLog(`移除事件监听: ${x[t]}`),this.listeners[t].delete(e)}once(t,e){this.debugLog(`添加一次性事件监听: ${x[t]}`);const s=i=>{e(i),this.off(t,s)};this.on(t,s)}clear(){this.debugLog("清除所有事件监听器"),Object.values(this.listeners).forEach(t=>t.clear())}getListenerCount(t){return this.listeners[t].size}debugLog(t,e){this.debugMode&&console.log(`[EventEmitter] ${t}`,e||"")}}const S={scriptRegex:/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,javascriptRegex:/javascript:/gi,eventHandlerRegex:/on\w+\s*=/gi,allowedTags:new Set(["div","span","p","a","img","button","input","form","label","select","option","textarea","ul","ol","li","table","tr","td","th","thead","tbody","tfoot","h1","h2","h3","h4","h5","h6","hr","br","section","article","nav","header","footer","main","aside","figure","figcaption"]),allowedAttributes:new Set(["class","id","href","src","alt","title"])};class v{static instance;constructor(){}static getInstance(){return v.instance||(v.instance=new v),v.instance}createElement(t,e={},s=""){if(!S.allowedTags.has(t.toLowerCase()))throw new Error(`Unsupported tag: ${t}`);const i=document.createElement(t);return this._processAttributes(i,e),this._processContent(i,s),i}createBatch(t,e){const s=document.createDocumentFragment();t.forEach(i=>{const n=this.createElement(i.tag,i.attributes||{},i.content||"");s.appendChild(n)}),e.appendChild(s)}setHtml(t,e){const s=this._sanitizeHtml(e);t.innerHTML=s}_processAttributes(t,e){Object.entries(e).forEach(([s,i])=>{if(!S.allowedAttributes.has(s)&&!s.startsWith("data-")){console.warn(`Potentially unsafe attribute: ${s}`);return}if(typeof i=="function")s.startsWith("on")&&t.addEventListener(s.slice(2).toLowerCase(),i);else switch(s){case"className":t.className=i;break;case"dataset":Object.assign(t.dataset,i);break;case"style":Object.assign(t.style,i);break;default:t.setAttribute(s,i)}})}_processContent(t,e){typeof e=="string"?t.textContent=e:e instanceof Node?t.appendChild(e):Array.isArray(e)&&e.forEach(s=>{typeof s=="string"?t.appendChild(document.createTextNode(s)):t.appendChild(s)})}_sanitizeHtml(t){return t.replace(S.scriptRegex,"").replace(S.javascriptRegex,"").replace(S.eventHandlerRegex,"")}}class B{features;constructor(){this.features=this.detectFeatures()}detectFeatures(){return{geolocation:"geolocation"in navigator,notification:"Notification"in window,serviceWorker:"serviceWorker"in navigator,webShare:"share"in navigator,deviceOrientation:"DeviceOrientationEvent"in window,battery:"getBattery"in navigator,online:"onLine"in navigator}}async getLocation(t={}){if(!this.features.geolocation)throw new Error("Geolocation is not supported");const e={enableHighAccuracy:!0,timeout:10*1e3,maximumAge:300*1e3};return new Promise((s,i)=>{navigator.geolocation.getCurrentPosition(n=>s({latitude:n.coords.latitude,longitude:n.coords.longitude,accuracy:n.coords.accuracy,timstamp:n.timestamp}),n=>{const o={1:"User denied the request for Geolocation.",2:"Position information is unavailable.",3:"The request to get user location timed out."};i(new Error(o[n.code]||"Unknown error"))},{...e,...t})})}async sendNotification(t,e){if(!this.features.notification)throw new Error("Notification is not supported");if(Notification.permission==="default"&&await Notification.requestPermission()!=="granted")throw new Error("Notification permission is not granted");if(Notification.permission!=="granted")throw new Error("Notification permission is not granted");return new Notification(t,{icon:e.icon,badge:e.badge,...e})}async registerServiceWorker(t){if(!this.features.serviceWorker)throw new Error("Service Worker is not supported");try{const e=await navigator.serviceWorker.register(t);return console.log("Service Worker registered with scope:",e),e}catch(e){throw console.error("Service Worker registration failed:",e),e}}async shareContent(t){if(this.features.webShare)try{return await navigator.share(t),!0}catch(e){return e instanceof Error&&e.name!="AbortError"&&console.error("Error sharing content:",e),!1}else try{return await navigator.clipboard.writeText(t.url||t.text||""),this.sendNotification("Copied to clipboard",{body:"Link copied to clipboard"}),!0}catch(e){return console.error("Error copying to clipboard:",e),!1}}}String.prototype.pointLength=function(){let r=0;for(let t=0,e=this.length;t<e;){const s=this.codePointAt(t);t+=s>65535?2:1,r++}return r},String.prototype.pointAt=function(r){if(r>=this.pointLength())return;let t=0;for(let e=0,s=this.length;e<s;){const i=this.codePointAt(e);if(!i)return;if(t===r)return String.fromCodePoint(i);e+=i>65535?2:1,t++}},String.prototype.sliceByPoint=function(r,t=this.pointLength()){let e="";for(let s=r;s<t;s++)e+=this.pointAt(s);return e},RegExp.escape=function(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},Element.prototype.farthest=function(r){if(typeof r!="string"||!r)return null;let t=null,e=this;for(;e;){const s=e.closest(r);if(!s)break;t=s,e=s.parentElement}return t},Object.defineProperties(Element.prototype,{firstElement:{get:function(){if(!this.children.length)return null;let r=this.firstElementChild,t=null;for(;r;)t=r,r=r.firstElementChild;return t}},lastElement:{get:function(){if(!this.children.length)return null;let r=this.lastElementChild,t=null;for(;r;)t=r,r=r.lastElementChild;return t}}}),Text.prototype.surround=function(r="strong",t=""){if(!this.nodeValue||!r||!t)return null;const s=r.split("."),i=s[0],n=s.slice(1).join(" "),o=this.textContent.indexOf(t);if(o<0)return null;const u=document.createRange();u.setStart(this,o),u.setEnd(this,o+t.length);const l=document.createElement(i);return n&&(l.className=n),u.surroundContents(l),l},a.Dictionary=R,a.DomHelper=v,a.Emitter=b,a.Graph=H,a.LIS=W,a.LRU=U,a.Line=p,a.LinkedList=D,a.Matrix=w,a.MaxHeap=z,a.MemoizeMap=T,a.MinHeap=N,a.Point=h,a.Queue=M,a.Roman=G,a.Stack=j,a.Triangle=c,a.Vector=d,a.WebAppManager=B,a.isValidBracket=$,a.singleton=F,a.sleep=_,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
|
package/index.d.ts
CHANGED
|
@@ -1,125 +1,59 @@
|
|
|
1
|
-
import { Vector } from "./lib/dataStructure";
|
|
2
|
-
|
|
3
1
|
declare module "jc-structure" {
|
|
2
|
+
/// <reference path="./types/stack.d.ts">
|
|
3
|
+
/// <reference path="./types/queue.d.ts">
|
|
4
|
+
/// <reference path="./types/heap.d.ts">
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* 栈类,采用object实现
|
|
6
8
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* @param args 要添加的元素,可以是多个或一个元素。
|
|
12
|
-
*/
|
|
13
|
-
push(...args: Array<T>): void;
|
|
14
|
-
/**
|
|
15
|
-
* #### 移除栈顶元素并返回该元素
|
|
16
|
-
*/
|
|
17
|
-
pop(): T | undefined;
|
|
18
|
-
/**
|
|
19
|
-
* #### 返回栈顶元素,但不移除
|
|
20
|
-
*/
|
|
21
|
-
peek(): T | undefined;
|
|
22
|
-
/**
|
|
23
|
-
* 判断数据结构是否为空
|
|
24
|
-
*/
|
|
25
|
-
isEmpty(): boolean;
|
|
26
|
-
/**
|
|
27
|
-
* 数据结构元素长度
|
|
28
|
-
*/
|
|
29
|
-
size(): number;
|
|
30
|
-
/**
|
|
31
|
-
* 重写 toString 方法
|
|
32
|
-
*/
|
|
33
|
-
toString(): string;
|
|
34
|
-
/**
|
|
35
|
-
* 清除数据结构元素
|
|
36
|
-
*/
|
|
37
|
-
clear(): void;
|
|
9
|
+
interface Stack<T> extends IStack<T> {}
|
|
10
|
+
interface StackConstructor {
|
|
11
|
+
new <T>(): Stack<T>;
|
|
12
|
+
readonly prototype: Stack<T>;
|
|
38
13
|
}
|
|
14
|
+
declare const Stack: StackConstructor;
|
|
39
15
|
|
|
40
16
|
/**
|
|
41
17
|
* 队列类,采用object实现
|
|
42
18
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
* @param args 要添加的元素,可以是多个或一个元素。
|
|
48
|
-
*/
|
|
49
|
-
enqueue(...args: Array<T>): void;
|
|
50
|
-
/**
|
|
51
|
-
* #### 移除队列头部元素并返回该元素
|
|
52
|
-
*/
|
|
53
|
-
dequeue(): T | undefined;
|
|
54
|
-
/**
|
|
55
|
-
* #### 返回队列头部元素,但不移除
|
|
56
|
-
*/
|
|
57
|
-
front(): T | undefined;
|
|
58
|
-
/**
|
|
59
|
-
* 判断数据结构是否为空
|
|
60
|
-
*/
|
|
61
|
-
isEmpty(): boolean;
|
|
62
|
-
/**
|
|
63
|
-
* 数据结构元素长度
|
|
64
|
-
*/
|
|
65
|
-
size(): number;
|
|
66
|
-
/**
|
|
67
|
-
* 重写 toString 方法
|
|
68
|
-
*/
|
|
69
|
-
toString(): string;
|
|
70
|
-
/**
|
|
71
|
-
* 清除数据结构元素
|
|
72
|
-
*/
|
|
73
|
-
clear(): void;
|
|
19
|
+
interface Queue<T> extends IQueue<T> {}
|
|
20
|
+
interface QueueConstructor {
|
|
21
|
+
new <T>(): Queue<T>;
|
|
22
|
+
readonly prototype: Queue<T>;
|
|
74
23
|
}
|
|
24
|
+
declare const Queue: QueueConstructor;
|
|
75
25
|
|
|
76
|
-
|
|
26
|
+
type CompareResult = -1 | 0 | 1;
|
|
77
27
|
|
|
28
|
+
interface CompareFn<T> {
|
|
29
|
+
(a: T, b: T): CompareResult;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface Obj<V = any> {
|
|
33
|
+
[key: string]: V;
|
|
34
|
+
}
|
|
78
35
|
/**
|
|
79
36
|
* 最小堆
|
|
80
37
|
*/
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
* @param args 要添加的元素,可以是多个或一个元素。
|
|
86
|
-
*/
|
|
87
|
-
insert(...args: Array<T>): void;
|
|
88
|
-
/**
|
|
89
|
-
* #### 移除最小值或最大值,返回该值
|
|
90
|
-
*/
|
|
91
|
-
extract(): T | undefined;
|
|
92
|
-
/**
|
|
93
|
-
* 查找一个值
|
|
94
|
-
* @param value 要查找的值
|
|
95
|
-
*/
|
|
96
|
-
find(): T | undefined;
|
|
97
|
-
/**
|
|
98
|
-
* 判断数据结构是否为空
|
|
99
|
-
*/
|
|
100
|
-
isEmpty(): boolean;
|
|
101
|
-
/**
|
|
102
|
-
* 数据结构元素长度
|
|
103
|
-
*/
|
|
104
|
-
size(): number;
|
|
105
|
-
/**
|
|
106
|
-
* 重写 toString 方法
|
|
107
|
-
*/
|
|
108
|
-
toString(): string;
|
|
38
|
+
interface MinHeap<T> extends IHeap<T> {}
|
|
39
|
+
interface MinHeapConstructor {
|
|
40
|
+
new <T>(fn?: CompareFn<T>): MinHeap<T>;
|
|
41
|
+
readonly prototype: MinHeap<T>;
|
|
109
42
|
}
|
|
43
|
+
declare const MinHeap: MinHeapConstructor;
|
|
110
44
|
|
|
111
45
|
/**
|
|
112
46
|
* 最大堆
|
|
113
47
|
*/
|
|
114
|
-
|
|
115
|
-
|
|
48
|
+
interface Constructor {
|
|
49
|
+
new <T>(fn?: CompareFn<T>): MinHeap<T>;
|
|
50
|
+
readonly prototype: MinHeap<T>;
|
|
116
51
|
}
|
|
117
|
-
|
|
52
|
+
declare const MaxHeap: Constructor;
|
|
118
53
|
/**
|
|
119
54
|
* LRU缓存类
|
|
120
55
|
*/
|
|
121
|
-
|
|
122
|
-
constructor(capacity?: number);
|
|
56
|
+
interface LRU<K, V> {
|
|
123
57
|
/**
|
|
124
58
|
* 获取缓存的值
|
|
125
59
|
* @param key 键值
|
|
@@ -132,6 +66,11 @@ declare module "jc-structure" {
|
|
|
132
66
|
*/
|
|
133
67
|
update(key: K, value: V): void;
|
|
134
68
|
}
|
|
69
|
+
interface LRUConstructor {
|
|
70
|
+
new <K, V>(capacity?: number): LRU<K, V>;
|
|
71
|
+
readonly prototype: LRU<K, V>;
|
|
72
|
+
}
|
|
73
|
+
declare const LRU: LRUConstructor;
|
|
135
74
|
|
|
136
75
|
/**
|
|
137
76
|
* 链表节点类
|
|
@@ -319,40 +258,47 @@ declare module "jc-structure" {
|
|
|
319
258
|
/**
|
|
320
259
|
* 罗马数字类
|
|
321
260
|
*/
|
|
322
|
-
|
|
261
|
+
interface RomanConstructor {
|
|
323
262
|
/**
|
|
324
263
|
* #### 转阿拉伯数字
|
|
325
264
|
* @param str 罗马数字文本
|
|
326
265
|
*/
|
|
327
|
-
|
|
266
|
+
toInteger(str: string): number;
|
|
328
267
|
/**
|
|
329
268
|
* #### 转罗马数字
|
|
330
269
|
* @param num 阿拉伯整数
|
|
331
270
|
*/
|
|
332
|
-
|
|
271
|
+
toRoman(num: number): string;
|
|
333
272
|
}
|
|
273
|
+
declare const Roman: RomanConstructor;
|
|
334
274
|
|
|
335
|
-
|
|
275
|
+
interface Point {
|
|
336
276
|
/**
|
|
337
|
-
* ####
|
|
338
|
-
* @param x x坐标
|
|
339
|
-
* @param y y坐标
|
|
277
|
+
* #### 点x坐标
|
|
340
278
|
*/
|
|
341
|
-
|
|
279
|
+
readonly x: number;
|
|
342
280
|
/**
|
|
343
|
-
* ####
|
|
344
|
-
* @param p1 点1
|
|
345
|
-
* @param p2 点2
|
|
281
|
+
* #### 点y坐标
|
|
346
282
|
*/
|
|
347
|
-
|
|
283
|
+
readonly y: number;
|
|
348
284
|
/**
|
|
349
285
|
* #### 计算点与点之间的距离,实例方法
|
|
350
286
|
* @param p 点p
|
|
351
287
|
*/
|
|
352
288
|
distanceTo(p: Point): number;
|
|
353
289
|
}
|
|
290
|
+
interface PointConstructor {
|
|
291
|
+
new (x: number, y: number): Point;
|
|
292
|
+
/**
|
|
293
|
+
* #### 计算两点之间的距离
|
|
294
|
+
* @param p1 点1
|
|
295
|
+
* @param p2 点2
|
|
296
|
+
*/
|
|
297
|
+
distance(p1: Point, p2: Point): number;
|
|
298
|
+
}
|
|
299
|
+
declare var Point: PointConstructor;
|
|
354
300
|
|
|
355
|
-
|
|
301
|
+
interface Line {
|
|
356
302
|
/**
|
|
357
303
|
* #### 线段长度
|
|
358
304
|
*/
|
|
@@ -369,39 +315,130 @@ declare module "jc-structure" {
|
|
|
369
315
|
* #### 获取线段的方向向量
|
|
370
316
|
*/
|
|
371
317
|
get direction(): Point;
|
|
318
|
+
/**
|
|
319
|
+
* #### 获取线段的起点
|
|
320
|
+
*/
|
|
321
|
+
get start(): Point;
|
|
322
|
+
/**
|
|
323
|
+
* #### 获取线段的终点
|
|
324
|
+
*/
|
|
325
|
+
get end(): Point;
|
|
372
326
|
/**
|
|
373
327
|
* #### 判断点是否在线段上
|
|
374
328
|
* @param point
|
|
329
|
+
* @param tolerance 容差,默认1e-10
|
|
375
330
|
*/
|
|
376
|
-
containsPoint(point: Point): boolean;
|
|
331
|
+
containsPoint(point: Point, tolerance?: number): boolean;
|
|
377
332
|
}
|
|
333
|
+
interface LineConstructor {
|
|
334
|
+
new (p1: Point, p2: Point): Line;
|
|
335
|
+
readonly prototype: Line;
|
|
378
336
|
|
|
379
|
-
/**
|
|
380
|
-
* ### 三角形类
|
|
381
|
-
*/
|
|
382
|
-
export class Triangle {
|
|
383
337
|
/**
|
|
384
|
-
* ####
|
|
385
|
-
* @param
|
|
386
|
-
* @param
|
|
387
|
-
* @param c 边长
|
|
338
|
+
* #### 判断线段是否平行
|
|
339
|
+
* @param line 线段
|
|
340
|
+
* @param tolerance 容差,默认1e-10
|
|
388
341
|
*/
|
|
389
|
-
|
|
342
|
+
sloped(line: Line, tolerance?: number): number | null;
|
|
343
|
+
|
|
390
344
|
/**
|
|
391
|
-
* ####
|
|
392
|
-
* @param
|
|
393
|
-
* @param
|
|
394
|
-
* @param
|
|
345
|
+
* #### 判断线段是否平行
|
|
346
|
+
* @param line1 线段1
|
|
347
|
+
* @param line2 线段2
|
|
348
|
+
* @param tolerance 容差,默认1e-10
|
|
395
349
|
*/
|
|
396
|
-
|
|
350
|
+
isParallel(line1: Line, line2: Line, tolerance?: number): boolean;
|
|
351
|
+
|
|
397
352
|
/**
|
|
398
|
-
* ####
|
|
399
|
-
* @param
|
|
400
|
-
* @param
|
|
401
|
-
* @param c 边长
|
|
353
|
+
* #### 判断线段是否相交
|
|
354
|
+
* @param line1 线段1
|
|
355
|
+
* @param line2 线段2
|
|
402
356
|
*/
|
|
403
|
-
|
|
404
|
-
|
|
357
|
+
isIntersecting(line1: Line, line2: Line): boolean;
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* #### 获取两线段交点
|
|
361
|
+
* @param line1 线段1
|
|
362
|
+
* @param line2 线段2
|
|
363
|
+
* @param tolerance 容差,默认1e-10
|
|
364
|
+
*/
|
|
365
|
+
getIntersection(line1: Line, line2: Line, tolerance?: number): Point | null;
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* #### 获取线段到点的距离
|
|
369
|
+
* @param line1 线段1
|
|
370
|
+
* @param line2 线段2
|
|
371
|
+
* @param tolerance 容差,默认1e-10
|
|
372
|
+
*/
|
|
373
|
+
distanceToPoint(line: Line, point: Point, tolerance?: number): number;
|
|
374
|
+
}
|
|
375
|
+
declare var Line: LineConstructor;
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* ### 三角形类
|
|
379
|
+
*/
|
|
380
|
+
// export class Triangle {
|
|
381
|
+
// /**
|
|
382
|
+
// * #### 判断三条边是否能构成三角形
|
|
383
|
+
// * @param a 边长
|
|
384
|
+
// * @param b 边长
|
|
385
|
+
// * @param c 边长
|
|
386
|
+
// */
|
|
387
|
+
// static isValid(a: number, b: number, c: number): boolean;
|
|
388
|
+
// /**
|
|
389
|
+
// * #### 计算三角形的面积,采用秦九昭公式或叫海伦面积公式
|
|
390
|
+
// * @param a 边长
|
|
391
|
+
// * @param b 边长
|
|
392
|
+
// * @param c 边长
|
|
393
|
+
// */
|
|
394
|
+
// static area(a: number, b: number, c: number): number;
|
|
395
|
+
// /**
|
|
396
|
+
// * #### 获取三角形的角度
|
|
397
|
+
// * @param a 边长
|
|
398
|
+
// * @param b 边长
|
|
399
|
+
// * @param c 边长
|
|
400
|
+
// */
|
|
401
|
+
// static getAngles(a: number, b: number, c: number): [number, number, number];
|
|
402
|
+
// constructor(p1: Point, p2: Point, p3: Point): Triangle;
|
|
403
|
+
// /**
|
|
404
|
+
// * #### 获取三角形的边长
|
|
405
|
+
// */
|
|
406
|
+
// get side(): [number, number, number];
|
|
407
|
+
// /**
|
|
408
|
+
// * #### 获取三角形的内心点
|
|
409
|
+
// */
|
|
410
|
+
// get centroid(): Point;
|
|
411
|
+
// /**
|
|
412
|
+
// * #### 获取三角形的外切园心点
|
|
413
|
+
// */
|
|
414
|
+
// get circumcenter(): Point;
|
|
415
|
+
// /**
|
|
416
|
+
// * #### 获取三角形的内切园心点
|
|
417
|
+
// */
|
|
418
|
+
// get incenter(): Point;
|
|
419
|
+
// /**
|
|
420
|
+
// * #### 获取三角形的周长
|
|
421
|
+
// */
|
|
422
|
+
// perimeter(): number;
|
|
423
|
+
// /**
|
|
424
|
+
// * #### 获取三角形的面积
|
|
425
|
+
// */
|
|
426
|
+
// area(): number;
|
|
427
|
+
// /**
|
|
428
|
+
// * #### 判断点是否在三角形内
|
|
429
|
+
// * @param point
|
|
430
|
+
// */
|
|
431
|
+
// containsPoint(point: Point): boolean;
|
|
432
|
+
// }
|
|
433
|
+
enum TriangleType {
|
|
434
|
+
Equilateral = "equilateral", // 等边
|
|
435
|
+
Isosceles = "isosceles", // 等腰
|
|
436
|
+
Scalene = "scalene", // 不等边
|
|
437
|
+
}
|
|
438
|
+
interface Triangle {
|
|
439
|
+
readonly p1: Point;
|
|
440
|
+
readonly p2: Point;
|
|
441
|
+
readonly p3: Point;
|
|
405
442
|
/**
|
|
406
443
|
* #### 获取三角形的边长
|
|
407
444
|
*/
|
|
@@ -432,7 +469,35 @@ declare module "jc-structure" {
|
|
|
432
469
|
*/
|
|
433
470
|
containsPoint(point: Point): boolean;
|
|
434
471
|
}
|
|
472
|
+
interface TriangleConstructor {
|
|
473
|
+
new (p1: Point, p2: Point, p3: Point): Triangle;
|
|
474
|
+
readonly prototype: Triangle;
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* #### 判断三条边是否能构成三角形
|
|
478
|
+
* @param a
|
|
479
|
+
* @param b
|
|
480
|
+
* @param c
|
|
481
|
+
*/
|
|
482
|
+
isValid(a: number, b: number, c: number): boolean;
|
|
483
|
+
/**
|
|
484
|
+
* #### 计算三角形的面积,采用秦九昭公式或叫海伦面积公式
|
|
485
|
+
* @param a
|
|
486
|
+
* @param b
|
|
487
|
+
* @param c
|
|
488
|
+
*/
|
|
489
|
+
area(a: number, b: number, c: number): number;
|
|
490
|
+
/**
|
|
491
|
+
* #### 获取三角形的角度
|
|
492
|
+
* @param a
|
|
493
|
+
* @param b
|
|
494
|
+
* @param c
|
|
495
|
+
*/
|
|
496
|
+
getAngles(a: number, b: number, c: number): [number, number, number];
|
|
435
497
|
|
|
498
|
+
getTYpe(a: number, b: number, c: number): TriangleType;
|
|
499
|
+
}
|
|
500
|
+
declare var Triangle: TriangleConstructor;
|
|
436
501
|
/**
|
|
437
502
|
* ### 向量类
|
|
438
503
|
*/
|
package/package.json
CHANGED
package/types/heap.d.ts
CHANGED
package/types/queue.d.ts
CHANGED
package/types/stack.d.ts
CHANGED