@sc-voice/tools 3.2.0 → 3.3.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/index.mjs CHANGED
@@ -1,8 +1,10 @@
1
1
 
2
2
  import { Fraction } from './src/math/fraction.mjs';
3
+ import { Interval } from './src/math/interval.mjs';
3
4
 
4
5
  export const ScvMath = {
5
6
  Fraction,
7
+ Interval,
6
8
  };
7
9
 
8
10
  import { BilaraPath } from './src/text/bilara-path.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sc-voice/tools",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "Utilities for SC-Voice",
5
5
  "main": "index.mjs",
6
6
  "files": [
@@ -0,0 +1,84 @@
1
+ import { Unicode } from '../text/unicode.mjs';
2
+
3
+ export class Interval {
4
+ constructor(a, b) {
5
+ const msg = 'i6l.ctor';
6
+ let hi = null;
7
+ let lo = null;
8
+ const dbg = 0;
9
+
10
+ let an = typeof a === 'number' && !Number.isNaN(a);
11
+ let bn = typeof b === 'number' && !Number.isNaN(b);
12
+
13
+ if (an && bn) {
14
+ dbg && console.log(msg, 'an bn');
15
+ lo = a;
16
+ hi = b;
17
+ this.isClosed = true;
18
+ } else if (an) {
19
+ dbg && console.log(msg, 'an');
20
+ lo = a;
21
+ hi = Interval.INFINITY;
22
+ this.isClosed = false;
23
+ } else if (bn) {
24
+ dbg && console.log(msg, 'bn');
25
+ lo = Interval.INFINITY;
26
+ hi = b;
27
+ this.isClosed = false;
28
+ } else {
29
+ dbg && console.log(msg, '!an !bn');
30
+ this.isClosed = false;
31
+ }
32
+
33
+ Object.defineProperty(this, 'lo', { value: lo });
34
+ Object.defineProperty(this, 'hi', { value: hi });
35
+ }
36
+
37
+ static get INFINITY() {
38
+ return Unicode.INFINITY;
39
+ }
40
+
41
+ get isEmpty() {
42
+ if (this.lo === null && this.hi === null) {
43
+ return true;
44
+ }
45
+ if (
46
+ this.lo === Interval.INFINITY ||
47
+ this.hi === Interval.INFINITY
48
+ ) {
49
+ return false;
50
+ }
51
+ return this.hi < this.lo;
52
+ }
53
+
54
+ get infimum() {
55
+ return this.lo === Interval.INFINITY
56
+ ? '-' + Interval.INFINITY
57
+ : this.lo;
58
+ }
59
+
60
+ get supremum() {
61
+ return this.hi === Interval.INFINITY
62
+ ? '+' + Interval.INFINITY
63
+ : this.hi;
64
+ }
65
+
66
+ contains(num) {
67
+ if (typeof num !== 'number' || Number.isNaN(num)) {
68
+ return false;
69
+ }
70
+ let { lo, hi } = this;
71
+ if (lo === Interval.INFINITY) {
72
+ throw new Error(`${msg}TBD`);
73
+ }
74
+ if (hi === Interval.INFINITY) {
75
+ throw new Error(`${msg}TBD`);
76
+ }
77
+ if (lo < num && num < hi) {
78
+ return true;
79
+ }
80
+ if (num < lo || hi < num) {
81
+ return false;
82
+ }
83
+ }
84
+ }
@@ -187,6 +187,9 @@ let ROMANIZE_MAP = {
187
187
  };
188
188
 
189
189
  export class Unicode {
190
+ static get INFINITY() {
191
+ return '\u221E';
192
+ }
190
193
  static get LSQUOTE() {
191
194
  return '\u2018';
192
195
  }