@lijuhong1981/jsmath 1.2.4 → 1.3.1
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/README.md +11 -11
- package/index.js +26 -119
- package/package.json +2 -2
- package/src/Interval.js +4 -3
- package/src/clamp.js +2 -1
- package/src/clampLatitude.js +2 -1
- package/src/clampLongitude.js +2 -1
- package/src/convertToDegreesCircular.js +2 -1
- package/src/convertToLatitudeRange.js +2 -1
- package/src/convertToLongitudeRange.js +2 -1
- package/src/convertToRadiansCircular.js +2 -1
- package/src/convertToRange.js +2 -1
- package/src/degreesToRadians.js +2 -1
- package/src/equalsEpsilon.js +3 -2
- package/src/extractFraction.js +2 -1
- package/src/getNDCInElement.js +2 -1
- package/src/isBetween.js +2 -1
- package/src/lerp.js +2 -1
- package/src/ndcToWindowPosition.js +6 -10
- package/src/normalize.js +2 -1
- package/src/parseBoolean.js +11 -0
- package/src/parseNumber.js +2 -1
- package/src/radiansToDegrees.js +2 -1
- package/src/randomInteger.js +2 -1
- package/src/randomNumber.js +2 -1
- package/src/scalarInRange.js +2 -1
- package/src/toFixed.js +2 -1
- package/src/windowPositionToNDC.js +2 -6
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# `@lijuhong1981/jsmath`
|
|
2
|
-
|
|
3
|
-
> TODO: description
|
|
4
|
-
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
const jsmath = require('@lijuhong1981/jsmath');
|
|
9
|
-
|
|
10
|
-
// TODO: DEMONSTRATE API
|
|
11
|
-
```
|
|
1
|
+
# `@lijuhong1981/jsmath`
|
|
2
|
+
|
|
3
|
+
> TODO: description
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
const jsmath = require('@lijuhong1981/jsmath');
|
|
9
|
+
|
|
10
|
+
// TODO: DEMONSTRATE API
|
|
11
|
+
```
|
package/index.js
CHANGED
|
@@ -1,119 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
EPSILON14,
|
|
28
|
-
EPSILON15,
|
|
29
|
-
EPSILON16,
|
|
30
|
-
EPSILON17,
|
|
31
|
-
EPSILON18,
|
|
32
|
-
EPSILON19,
|
|
33
|
-
EPSILON20,
|
|
34
|
-
EPSILON21,
|
|
35
|
-
} from "./src/Constant.js";
|
|
36
|
-
import degreesToRadians from "./src/degreesToRadians.js";
|
|
37
|
-
import radiansToDegrees from "./src/radiansToDegrees.js";
|
|
38
|
-
import clamp from "./src/clamp.js";
|
|
39
|
-
import clampLatitude from "./src/clampLatitude.js";
|
|
40
|
-
import clampLongitude from "./src/clampLongitude.js";
|
|
41
|
-
import convertToRange from "./src/convertToRange.js";
|
|
42
|
-
import convertToDegreesCircular from "./src/convertToDegreesCircular.js";
|
|
43
|
-
import convertToRadiansCircular from "./src/convertToRadiansCircular.js";
|
|
44
|
-
import convertToLatitudeRange from "./src/convertToLatitudeRange.js";
|
|
45
|
-
import convertToLongitudeRange from "./src/convertToLongitudeRange.js";
|
|
46
|
-
import equalsEpsilon from "./src/equalsEpsilon.js";
|
|
47
|
-
import extractFraction from "./src/extractFraction.js";
|
|
48
|
-
import isBetween from "./src/isBetween.js";
|
|
49
|
-
import lerp from "./src/lerp.js";
|
|
50
|
-
import scalarInRange from "./src/scalarInRange.js";
|
|
51
|
-
import normalize from "./src/normalize.js";
|
|
52
|
-
import parseNumber from "./src/parseNumber.js";
|
|
53
|
-
import randomNumber from "./src/randomNumber.js";
|
|
54
|
-
import randomInteger from "./src/randomInteger.js";
|
|
55
|
-
import toFixed from "./src/toFixed.js";
|
|
56
|
-
import Interval from "./src/Interval.js";
|
|
57
|
-
import windowPositionToNDC from "./src/windowPositionToNDC.js";
|
|
58
|
-
import getNDCInElement from "./src/getNDCInElement.js";
|
|
59
|
-
import ndcToWindowPosition from "./src/ndcToWindowPosition.js";
|
|
60
|
-
|
|
61
|
-
export {
|
|
62
|
-
PI,
|
|
63
|
-
ONE_OVER_PI,
|
|
64
|
-
PI_OVER_TWO,
|
|
65
|
-
PI_OVER_THREE,
|
|
66
|
-
PI_OVER_FOUR,
|
|
67
|
-
PI_OVER_SIX,
|
|
68
|
-
THREE_PI_OVER_TWO,
|
|
69
|
-
TWO_PI,
|
|
70
|
-
ONE_OVER_TWO_PI,
|
|
71
|
-
RADIANS_PER_DEGREE,
|
|
72
|
-
DEGREES_PER_RADIAN,
|
|
73
|
-
RADIANS_PER_ARCSECOND,
|
|
74
|
-
EPSILON1,
|
|
75
|
-
EPSILON2,
|
|
76
|
-
EPSILON3,
|
|
77
|
-
EPSILON4,
|
|
78
|
-
EPSILON5,
|
|
79
|
-
EPSILON6,
|
|
80
|
-
EPSILON7,
|
|
81
|
-
EPSILON8,
|
|
82
|
-
EPSILON9,
|
|
83
|
-
EPSILON10,
|
|
84
|
-
EPSILON11,
|
|
85
|
-
EPSILON12,
|
|
86
|
-
EPSILON13,
|
|
87
|
-
EPSILON14,
|
|
88
|
-
EPSILON15,
|
|
89
|
-
EPSILON16,
|
|
90
|
-
EPSILON17,
|
|
91
|
-
EPSILON18,
|
|
92
|
-
EPSILON19,
|
|
93
|
-
EPSILON20,
|
|
94
|
-
EPSILON21,
|
|
95
|
-
degreesToRadians,
|
|
96
|
-
radiansToDegrees,
|
|
97
|
-
clamp,
|
|
98
|
-
clampLatitude,
|
|
99
|
-
clampLongitude,
|
|
100
|
-
convertToRange,
|
|
101
|
-
convertToDegreesCircular,
|
|
102
|
-
convertToRadiansCircular,
|
|
103
|
-
convertToLatitudeRange,
|
|
104
|
-
convertToLongitudeRange,
|
|
105
|
-
equalsEpsilon,
|
|
106
|
-
extractFraction,
|
|
107
|
-
isBetween,
|
|
108
|
-
lerp,
|
|
109
|
-
scalarInRange,
|
|
110
|
-
normalize,
|
|
111
|
-
parseNumber,
|
|
112
|
-
randomNumber,
|
|
113
|
-
randomInteger,
|
|
114
|
-
toFixed,
|
|
115
|
-
Interval,
|
|
116
|
-
windowPositionToNDC,
|
|
117
|
-
getNDCInElement,
|
|
118
|
-
ndcToWindowPosition,
|
|
119
|
-
};
|
|
1
|
+
export * from "./src/clamp.js";
|
|
2
|
+
export * from "./src/clampLatitude.js";
|
|
3
|
+
export * from "./src/clampLongitude.js";
|
|
4
|
+
export * as Constant from "./src/Constant.js";
|
|
5
|
+
export * from "./src/convertToDegreesCircular.js";
|
|
6
|
+
export * from "./src/convertToLatitudeRange.js";
|
|
7
|
+
export * from "./src/convertToLongitudeRange.js";
|
|
8
|
+
export * from "./src/convertToRadiansCircular.js";
|
|
9
|
+
export * from "./src/convertToRange.js";
|
|
10
|
+
export * from "./src/degreesToRadians.js";
|
|
11
|
+
export * from "./src/equalsEpsilon.js";
|
|
12
|
+
export * from "./src/extractFraction.js";
|
|
13
|
+
export * from "./src/getNDCInElement.js";
|
|
14
|
+
export * from "./src/Interval.js";
|
|
15
|
+
export * from "./src/isBetween.js";
|
|
16
|
+
export * from "./src/lerp.js";
|
|
17
|
+
export * from "./src/ndcToWindowPosition.js";
|
|
18
|
+
export * from "./src/normalize.js";
|
|
19
|
+
export * from "./src/parseBoolean.js";
|
|
20
|
+
export * from "./src/parseNumber.js";
|
|
21
|
+
export * from "./src/radiansToDegrees.js";
|
|
22
|
+
export * from "./src/randomInteger.js";
|
|
23
|
+
export * from "./src/randomNumber.js";
|
|
24
|
+
export * from "./src/scalarInRange.js";
|
|
25
|
+
export * from "./src/toFixed.js";
|
|
26
|
+
export * from "./src/windowPositionToNDC.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lijuhong1981/jsmath",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "lijuhong1981 <lijuhong@hotmail.com>",
|
|
6
6
|
"homepage": "https://github.com/lijuhong1981/jslibs#readme",
|
|
@@ -18,5 +18,5 @@
|
|
|
18
18
|
"bugs": {
|
|
19
19
|
"url": "https://github.com/lijuhong1981/jslibs/issues"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "cae3f4be65fe0454718936b9ab5a4d29af4fdda0"
|
|
22
22
|
}
|
package/src/Interval.js
CHANGED
|
@@ -268,7 +268,7 @@ class Interval {
|
|
|
268
268
|
/**
|
|
269
269
|
* 将一个区间对象的所有属性打包到一个数组中
|
|
270
270
|
* @param {Interval} interval 需要打包的区间对象
|
|
271
|
-
* @param {Array} array
|
|
271
|
+
* @param {Array} array 打包到的目标数组,可不填
|
|
272
272
|
* @param {Integer} startingIndex 数组起始索引,默认0
|
|
273
273
|
* @returns {Array} 打包后的数组
|
|
274
274
|
*/
|
|
@@ -283,7 +283,7 @@ class Interval {
|
|
|
283
283
|
|
|
284
284
|
/**
|
|
285
285
|
* 将当前区间对象属性打包至数组
|
|
286
|
-
* @param {Array} array
|
|
286
|
+
* @param {Array} array 打包到的目标数组,可不填
|
|
287
287
|
* @param {Integer} startingIndex 数组起始索引,默认0
|
|
288
288
|
* @returns {Array} 打包后的数组
|
|
289
289
|
*/
|
|
@@ -333,4 +333,5 @@ class Interval {
|
|
|
333
333
|
|
|
334
334
|
Interval.packedLength = 4;
|
|
335
335
|
|
|
336
|
-
export default Interval;
|
|
336
|
+
export default Interval;
|
|
337
|
+
export { Interval };
|
package/src/clamp.js
CHANGED
package/src/clampLatitude.js
CHANGED
package/src/clampLongitude.js
CHANGED
package/src/convertToRange.js
CHANGED
package/src/degreesToRadians.js
CHANGED
package/src/equalsEpsilon.js
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
* 比较两个数值是否近似相等
|
|
3
3
|
* @param {Number} left
|
|
4
4
|
* @param {Number} right
|
|
5
|
-
* @param {Number} epsilon
|
|
5
|
+
* @param {Number} epsilon 近似精度,Math.abs(left - right)小于或等于该值时返回true
|
|
6
6
|
* @returns {Boolean}
|
|
7
7
|
*/
|
|
8
8
|
function equalsEpsilon(left, right, epsilon = 0) {
|
|
9
9
|
return Math.abs(left - right) <= epsilon;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
export default equalsEpsilon;
|
|
12
|
+
export default equalsEpsilon;
|
|
13
|
+
export { equalsEpsilon };
|
package/src/extractFraction.js
CHANGED
package/src/getNDCInElement.js
CHANGED
|
@@ -11,4 +11,5 @@ function getNDCInElement(element, posInElement, result = {}) {
|
|
|
11
11
|
return windowPositionToNDC(posInElement, element.clientWidth, element.clientHeight, result);
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
export default getNDCInElement;
|
|
14
|
+
export default getNDCInElement;
|
|
15
|
+
export { getNDCInElement };
|
package/src/isBetween.js
CHANGED
package/src/lerp.js
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
import Check from '@lijuhong1981/jscheck/src/Check.js';
|
|
2
|
-
import isValid from '@lijuhong1981/jscheck/src/isValid.js';
|
|
3
|
-
|
|
4
1
|
/**
|
|
5
2
|
* ndc坐标(NormalizedDeviceCoordinates)转换为窗口像素坐标
|
|
6
3
|
* @param {Object} ndc 需转换的ndc坐标, {x: 0.5, y: -0.5, z: 0.0}
|
|
7
4
|
* @param {Number} width 窗口像素宽
|
|
8
5
|
* @param {Number} height 窗口像素高
|
|
9
6
|
* @param {Object} result 输出结果对象
|
|
10
|
-
* @
|
|
7
|
+
* @param {Boolean} checkInvisible 是否检查不可见,默认true
|
|
8
|
+
* @returns {Object|undefined} 输出结果对象, 如:{x: 123, y: 321},返回undefined表示不可见
|
|
11
9
|
*/
|
|
12
|
-
function ndcToWindowPosition(ndc, width, height, result = {}) {
|
|
13
|
-
Check.typeOf.object('ndc', ndc);
|
|
14
|
-
Check.typeOf.number('width', width);
|
|
15
|
-
Check.typeOf.number('height', height);
|
|
10
|
+
function ndcToWindowPosition(ndc, width, height, result = {}, checkInvisible = true) {
|
|
16
11
|
|
|
17
12
|
// invisible
|
|
18
|
-
if (
|
|
13
|
+
if (checkInvisible && (ndc.z < 0 || ndc.z > 1))
|
|
19
14
|
return;
|
|
20
15
|
|
|
21
16
|
const x = (ndc.x + 1) / 2 * width;
|
|
@@ -27,4 +22,5 @@ function ndcToWindowPosition(ndc, width, height, result = {}) {
|
|
|
27
22
|
return result;
|
|
28
23
|
}
|
|
29
24
|
|
|
30
|
-
export default ndcToWindowPosition;
|
|
25
|
+
export default ndcToWindowPosition;
|
|
26
|
+
export { ndcToWindowPosition };
|
package/src/normalize.js
CHANGED
package/src/parseNumber.js
CHANGED
package/src/radiansToDegrees.js
CHANGED
package/src/randomInteger.js
CHANGED
package/src/randomNumber.js
CHANGED
package/src/scalarInRange.js
CHANGED
package/src/toFixed.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import Check from '@lijuhong1981/jscheck/src/Check.js';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* 窗口像素坐标转换为NDC坐标(NormalizedDeviceCoordinates)
|
|
5
3
|
* @param {Object} posInWindow 需转换的窗口像素坐标,{x: 500, y: 300}
|
|
@@ -9,9 +7,6 @@ import Check from '@lijuhong1981/jscheck/src/Check.js';
|
|
|
9
7
|
* @returns {Object} 输出结果对象, 如:{x: 0.5, y: -0.5}
|
|
10
8
|
*/
|
|
11
9
|
function windowPositionToNDC(posInWindow, width, height, result = {}) {
|
|
12
|
-
Check.typeOf.object('posInWindow', posInWindow);
|
|
13
|
-
Check.typeOf.number('width', width);
|
|
14
|
-
Check.typeOf.number('height', height);
|
|
15
10
|
|
|
16
11
|
result.x = (posInWindow.x / width) * 2 - 1;
|
|
17
12
|
result.y = -(posInWindow.y / height) * 2 + 1;
|
|
@@ -19,4 +14,5 @@ function windowPositionToNDC(posInWindow, width, height, result = {}) {
|
|
|
19
14
|
return result;
|
|
20
15
|
};
|
|
21
16
|
|
|
22
|
-
export default windowPositionToNDC;
|
|
17
|
+
export default windowPositionToNDC;
|
|
18
|
+
export { windowPositionToNDC };
|