@lijuhong1981/jsmath 1.0.12 → 1.0.14

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.js CHANGED
@@ -10,7 +10,28 @@ import {
10
10
  ONE_OVER_TWO_PI,
11
11
  RADIANS_PER_DEGREE,
12
12
  DEGREES_PER_RADIAN,
13
- RADIANS_PER_ARCSECOND
13
+ RADIANS_PER_ARCSECOND,
14
+ EPSILON1,
15
+ EPSILON2,
16
+ EPSILON3,
17
+ EPSILON4,
18
+ EPSILON5,
19
+ EPSILON6,
20
+ EPSILON7,
21
+ EPSILON8,
22
+ EPSILON9,
23
+ EPSILON10,
24
+ EPSILON11,
25
+ EPSILON12,
26
+ EPSILON13,
27
+ EPSILON14,
28
+ EPSILON15,
29
+ EPSILON16,
30
+ EPSILON17,
31
+ EPSILON18,
32
+ EPSILON19,
33
+ EPSILON20,
34
+ EPSILON21,
14
35
  } from "./src/Constant.js";
15
36
  import degToRad from "./src/degToRad.js";
16
37
  import radToDeg from "./src/radToDeg.js";
@@ -22,6 +43,7 @@ import convertToDegreesCircular from "./src/convertToDegreesCircular .js";
22
43
  import convertToRadiansCircular from "./src/convertToRadiansCircular.js";
23
44
  import convertToLatitudeRange from "./src/convertToLatitudeRange.js";
24
45
  import convertToLongitudeRange from "./src/convertToLongitudeRange.js";
46
+ import equalsEpsilon from "./src/equalsEpsilon.js";
25
47
  import isBetween from "./src/isBetween.js";
26
48
  import lerp from "./src/lerp.js";
27
49
  import scalarInRange from "./src/scalarInRange.js";
@@ -43,6 +65,27 @@ export {
43
65
  RADIANS_PER_DEGREE,
44
66
  DEGREES_PER_RADIAN,
45
67
  RADIANS_PER_ARCSECOND,
68
+ EPSILON1,
69
+ EPSILON2,
70
+ EPSILON3,
71
+ EPSILON4,
72
+ EPSILON5,
73
+ EPSILON6,
74
+ EPSILON7,
75
+ EPSILON8,
76
+ EPSILON9,
77
+ EPSILON10,
78
+ EPSILON11,
79
+ EPSILON12,
80
+ EPSILON13,
81
+ EPSILON14,
82
+ EPSILON15,
83
+ EPSILON16,
84
+ EPSILON17,
85
+ EPSILON18,
86
+ EPSILON19,
87
+ EPSILON20,
88
+ EPSILON21,
46
89
  degToRad,
47
90
  radToDeg,
48
91
  clamp,
@@ -53,6 +96,7 @@ export {
53
96
  convertToRadiansCircular,
54
97
  convertToLatitudeRange,
55
98
  convertToLongitudeRange,
99
+ equalsEpsilon,
56
100
  isBetween,
57
101
  lerp,
58
102
  scalarInRange,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lijuhong1981/jsmath",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
package/src/Constant.js CHANGED
@@ -11,6 +11,153 @@ const RADIANS_PER_DEGREE = PI / 180.0;
11
11
  const DEGREES_PER_RADIAN = 180.0 / PI;
12
12
  const RADIANS_PER_ARCSECOND = RADIANS_PER_DEGREE / 3600.0;
13
13
 
14
+ /**
15
+ * 0.1
16
+ * @type {Number}
17
+ * @constant
18
+ */
19
+ const EPSILON1 = 0.1;
20
+
21
+ /**
22
+ * 0.01
23
+ * @type {Number}
24
+ * @constant
25
+ */
26
+ const EPSILON2 = 0.01;
27
+
28
+ /**
29
+ * 0.001
30
+ * @type {Number}
31
+ * @constant
32
+ */
33
+ const EPSILON3 = 0.001;
34
+
35
+ /**
36
+ * 0.0001
37
+ * @type {Number}
38
+ * @constant
39
+ */
40
+ const EPSILON4 = 0.0001;
41
+
42
+ /**
43
+ * 0.00001
44
+ * @type {Number}
45
+ * @constant
46
+ */
47
+ const EPSILON5 = 0.00001;
48
+
49
+ /**
50
+ * 0.000001
51
+ * @type {Number}
52
+ * @constant
53
+ */
54
+ const EPSILON6 = 0.000001;
55
+
56
+ /**
57
+ * 0.0000001
58
+ * @type {Number}
59
+ * @constant
60
+ */
61
+ const EPSILON7 = 0.0000001;
62
+
63
+ /**
64
+ * 0.00000001
65
+ * @type {Number}
66
+ * @constant
67
+ */
68
+ const EPSILON8 = 0.00000001;
69
+
70
+ /**
71
+ * 0.000000001
72
+ * @type {Number}
73
+ * @constant
74
+ */
75
+ const EPSILON9 = 0.000000001;
76
+
77
+ /**
78
+ * 0.0000000001
79
+ * @type {Number}
80
+ * @constant
81
+ */
82
+ const EPSILON10 = 0.0000000001;
83
+
84
+ /**
85
+ * 0.00000000001
86
+ * @type {Number}
87
+ * @constant
88
+ */
89
+ const EPSILON11 = 0.00000000001;
90
+
91
+ /**
92
+ * 0.000000000001
93
+ * @type {Number}
94
+ * @constant
95
+ */
96
+ const EPSILON12 = 0.000000000001;
97
+
98
+ /**
99
+ * 0.0000000000001
100
+ * @type {Number}
101
+ * @constant
102
+ */
103
+ const EPSILON13 = 0.0000000000001;
104
+
105
+ /**
106
+ * 0.00000000000001
107
+ * @type {Number}
108
+ * @constant
109
+ */
110
+ const EPSILON14 = 0.00000000000001;
111
+
112
+ /**
113
+ * 0.000000000000001
114
+ * @type {Number}
115
+ * @constant
116
+ */
117
+ const EPSILON15 = 0.000000000000001;
118
+
119
+ /**
120
+ * 0.0000000000000001
121
+ * @type {Number}
122
+ * @constant
123
+ */
124
+ const EPSILON16 = 0.0000000000000001;
125
+
126
+ /**
127
+ * 0.00000000000000001
128
+ * @type {Number}
129
+ * @constant
130
+ */
131
+ const EPSILON17 = 0.00000000000000001;
132
+
133
+ /**
134
+ * 0.000000000000000001
135
+ * @type {Number}
136
+ * @constant
137
+ */
138
+ const EPSILON18 = 0.000000000000000001;
139
+
140
+ /**
141
+ * 0.0000000000000000001
142
+ * @type {Number}
143
+ * @constant
144
+ */
145
+ const EPSILON19 = 0.0000000000000000001;
146
+
147
+ /**
148
+ * 0.00000000000000000001
149
+ * @type {Number}
150
+ * @constant
151
+ */
152
+ const EPSILON20 = 0.00000000000000000001;
153
+
154
+ /**
155
+ * 0.000000000000000000001
156
+ * @type {Number}
157
+ * @constant
158
+ */
159
+ const EPSILON21 = 0.000000000000000000001;
160
+
14
161
  export {
15
162
  PI,
16
163
  ONE_OVER_PI,
@@ -23,5 +170,26 @@ export {
23
170
  ONE_OVER_TWO_PI,
24
171
  RADIANS_PER_DEGREE,
25
172
  DEGREES_PER_RADIAN,
26
- RADIANS_PER_ARCSECOND
173
+ RADIANS_PER_ARCSECOND,
174
+ EPSILON1,
175
+ EPSILON2,
176
+ EPSILON3,
177
+ EPSILON4,
178
+ EPSILON5,
179
+ EPSILON6,
180
+ EPSILON7,
181
+ EPSILON8,
182
+ EPSILON9,
183
+ EPSILON10,
184
+ EPSILON11,
185
+ EPSILON12,
186
+ EPSILON13,
187
+ EPSILON14,
188
+ EPSILON15,
189
+ EPSILON16,
190
+ EPSILON17,
191
+ EPSILON18,
192
+ EPSILON19,
193
+ EPSILON20,
194
+ EPSILON21,
27
195
  };
package/src/Range.js CHANGED
@@ -1,16 +1,8 @@
1
- import Check from "@lijuhong1981/jscheck";
1
+ import Check, { isValid } from "@lijuhong1981/jscheck";
2
2
  import isBetween from "./isBetween.js";
3
3
  import lerp from "./lerp.js";
4
4
  import scalarInRange from "./scalarInRange.js";
5
5
 
6
- function checkMinMaxValue(range) {
7
- if (range.minimum > range.maximum) {
8
- const temp = range.minimum;
9
- range.minimum = range.maximum;
10
- range.maximum = temp;
11
- }
12
- }
13
-
14
6
  /**
15
7
  * Range对象用来表示数学上的区间集合
16
8
  */
@@ -23,17 +15,37 @@ class Range {
23
15
  * @param {Boolean} containsMaximum 区间是否包含较大数,默认true
24
16
  */
25
17
  constructor(minimum = 0, maximum = 1, containsMinimum = true, containsMaximum = true) {
26
- this.minimum = minimum;
27
- this.maximum = maximum;
28
- this.containsMinimum = containsMinimum;
29
- this.containsMaximum = containsMaximum;
30
- checkMinMaxValue(this);
18
+ this.setValues(minimum, maximum, containsMinimum, containsMaximum);
31
19
  }
32
20
 
33
21
  get isRange() {
34
22
  return true;
35
23
  }
36
24
 
25
+ ensureMinMaxValue() {
26
+ if (this.minimum > this.maximum) {
27
+ const temp = this.minimum;
28
+ this.minimum = this.maximum;
29
+ this.maximum = temp;
30
+ }
31
+ return this;
32
+ }
33
+
34
+ setValues(minimum, maximum, containsMinimum, containsMaximum) {
35
+ if (isValid(minimum))
36
+ this.minimum = minimum;
37
+ if (isValid(maximum))
38
+ this.maximum = maximum;
39
+ if (isValid(containsMinimum))
40
+ this.containsMinimum = containsMinimum;
41
+ if (isValid(containsMaximum))
42
+ this.containsMaximum = containsMaximum;
43
+
44
+ this.ensureMinMaxValue();
45
+
46
+ return this;
47
+ }
48
+
37
49
  /**
38
50
  * @deprecated
39
51
  */
@@ -338,7 +350,7 @@ class Range {
338
350
  }
339
351
 
340
352
  toString() {
341
- return 'Range:' + this.containsMinimum ? '[' : '(' + this.minimum + ', ' + this.maximum + this.containsMaximum ? ']' : ')'
353
+ return 'Range:' + this.containsMinimum ? '[' : '(' + this.minimum + ', ' + this.maximum + this.containsMaximum ? ']' : ')';
342
354
  }
343
355
  };
344
356
 
@@ -0,0 +1,10 @@
1
+ import Check from "@lijuhong1981/jscheck";
2
+
3
+ function equalsEpsilon(left, right, epsilon = 0) {
4
+ Check.typeOf.number('left', left);
5
+ Check.typeOf.number('right', right)
6
+
7
+ return Math.abs(left - right) <= epsilon;
8
+ };
9
+
10
+ export default equalsEpsilon;