@sc-voice/tools 3.3.0 → 3.4.0
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/math/interval.mjs +42 -21
package/package.json
CHANGED
package/src/math/interval.mjs
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { Unicode } from '../text/unicode.mjs';
|
|
2
|
+
const { INFINITY } = Unicode;
|
|
3
|
+
|
|
4
|
+
const MINUS_INFINITY = `-${INFINITY}`;
|
|
5
|
+
const PLUS_INFINITY = `+${INFINITY}`;
|
|
2
6
|
|
|
3
7
|
export class Interval {
|
|
4
8
|
constructor(a, b) {
|
|
@@ -10,41 +14,49 @@ export class Interval {
|
|
|
10
14
|
let an = typeof a === 'number' && !Number.isNaN(a);
|
|
11
15
|
let bn = typeof b === 'number' && !Number.isNaN(b);
|
|
12
16
|
|
|
17
|
+
let isClosed = true;
|
|
13
18
|
if (an && bn) {
|
|
14
19
|
dbg && console.log(msg, 'an bn');
|
|
15
20
|
lo = a;
|
|
16
21
|
hi = b;
|
|
17
|
-
|
|
22
|
+
isClosed = true;
|
|
18
23
|
} else if (an) {
|
|
19
24
|
dbg && console.log(msg, 'an');
|
|
20
25
|
lo = a;
|
|
21
|
-
hi =
|
|
22
|
-
|
|
26
|
+
hi = INFINITY;
|
|
27
|
+
isClosed = false;
|
|
23
28
|
} else if (bn) {
|
|
24
29
|
dbg && console.log(msg, 'bn');
|
|
25
|
-
lo =
|
|
30
|
+
lo = INFINITY;
|
|
26
31
|
hi = b;
|
|
27
|
-
|
|
32
|
+
isClosed = false;
|
|
28
33
|
} else {
|
|
29
34
|
dbg && console.log(msg, '!an !bn');
|
|
30
|
-
|
|
35
|
+
isClosed = false;
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
Object.defineProperty(this, '
|
|
34
|
-
|
|
38
|
+
Object.defineProperty(this, 'isClosed', {
|
|
39
|
+
value: isClosed,
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(this, 'lo', {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
value: lo,
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(this, 'hi', {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
value: hi,
|
|
48
|
+
});
|
|
35
49
|
}
|
|
36
50
|
|
|
37
|
-
static get INFINITY() {
|
|
38
|
-
return Unicode.INFINITY;
|
|
39
|
-
}
|
|
51
|
+
static get INFINITY() { return INFINITY; }
|
|
40
52
|
|
|
41
53
|
get isEmpty() {
|
|
42
54
|
if (this.lo === null && this.hi === null) {
|
|
43
55
|
return true;
|
|
44
56
|
}
|
|
45
57
|
if (
|
|
46
|
-
this.lo ===
|
|
47
|
-
this.hi ===
|
|
58
|
+
this.lo === INFINITY ||
|
|
59
|
+
this.hi === INFINITY
|
|
48
60
|
) {
|
|
49
61
|
return false;
|
|
50
62
|
}
|
|
@@ -52,15 +64,11 @@ export class Interval {
|
|
|
52
64
|
}
|
|
53
65
|
|
|
54
66
|
get infimum() {
|
|
55
|
-
return this.lo ===
|
|
56
|
-
? '-' + Interval.INFINITY
|
|
57
|
-
: this.lo;
|
|
67
|
+
return this.lo === INFINITY ? MINUS_INFINITY : this.lo;
|
|
58
68
|
}
|
|
59
69
|
|
|
60
70
|
get supremum() {
|
|
61
|
-
return this.hi ===
|
|
62
|
-
? '+' + Interval.INFINITY
|
|
63
|
-
: this.hi;
|
|
71
|
+
return this.hi === INFINITY ? PLUS_INFINITY : this.hi;
|
|
64
72
|
}
|
|
65
73
|
|
|
66
74
|
contains(num) {
|
|
@@ -68,10 +76,10 @@ export class Interval {
|
|
|
68
76
|
return false;
|
|
69
77
|
}
|
|
70
78
|
let { lo, hi } = this;
|
|
71
|
-
if (lo ===
|
|
79
|
+
if (lo === INFINITY) {
|
|
72
80
|
throw new Error(`${msg}TBD`);
|
|
73
81
|
}
|
|
74
|
-
if (hi ===
|
|
82
|
+
if (hi === INFINITY) {
|
|
75
83
|
throw new Error(`${msg}TBD`);
|
|
76
84
|
}
|
|
77
85
|
if (lo < num && num < hi) {
|
|
@@ -80,5 +88,18 @@ export class Interval {
|
|
|
80
88
|
if (num < lo || hi < num) {
|
|
81
89
|
return false;
|
|
82
90
|
}
|
|
91
|
+
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
toString() {
|
|
96
|
+
let { lo, hi } = this;
|
|
97
|
+
return [
|
|
98
|
+
lo === INFINITY ? '(' : '[',
|
|
99
|
+
lo === INFINITY ? MINUS_INFINITY : lo,
|
|
100
|
+
lo === hi ? '' : ',',
|
|
101
|
+
hi === INFINITY ? PLUS_INFINITY : hi,
|
|
102
|
+
hi === INFINITY ? ')' : ']',
|
|
103
|
+
].join('');
|
|
83
104
|
}
|
|
84
105
|
}
|