@lijuhong1981/jsmath 1.2.4 → 1.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/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
- import {
2
- PI,
3
- ONE_OVER_PI,
4
- PI_OVER_TWO,
5
- PI_OVER_THREE,
6
- PI_OVER_FOUR,
7
- PI_OVER_SIX,
8
- THREE_PI_OVER_TWO,
9
- TWO_PI,
10
- ONE_OVER_TWO_PI,
11
- RADIANS_PER_DEGREE,
12
- DEGREES_PER_RADIAN,
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,
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,22 +1,22 @@
1
- {
2
- "name": "@lijuhong1981/jsmath",
3
- "version": "1.2.4",
4
- "description": "> TODO: description",
5
- "author": "lijuhong1981 <lijuhong@hotmail.com>",
6
- "homepage": "https://github.com/lijuhong1981/jslibs#readme",
7
- "license": "ISC",
8
- "type": "module",
9
- "main": "index.js",
10
- "module": "index.js",
11
- "publishConfig": {
12
- "access": "public"
13
- },
14
- "repository": {
15
- "type": "git",
16
- "url": "git+https://github.com/lijuhong1981/jslibs.git"
17
- },
18
- "bugs": {
19
- "url": "https://github.com/lijuhong1981/jslibs/issues"
20
- },
21
- "gitHead": "75538582d4f88fbef4e366404a96264c40bb05d8"
22
- }
1
+ {
2
+ "name": "@lijuhong1981/jsmath",
3
+ "version": "1.3.0",
4
+ "description": "> TODO: description",
5
+ "author": "lijuhong1981 <lijuhong@hotmail.com>",
6
+ "homepage": "https://github.com/lijuhong1981/jslibs#readme",
7
+ "license": "ISC",
8
+ "type": "module",
9
+ "main": "index.js",
10
+ "module": "index.js",
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/lijuhong1981/jslibs.git"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/lijuhong1981/jslibs/issues"
20
+ },
21
+ "gitHead": "cae3f4be65fe0454718936b9ab5a4d29af4fdda0"
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
@@ -9,4 +9,5 @@ function clamp(value, rangeMinimum, rangeMaximum) {
9
9
  return value < rangeMinimum ? rangeMinimum : value > rangeMaximum ? rangeMaximum : value;
10
10
  };
11
11
 
12
- export default clamp;
12
+ export default clamp;
13
+ export { clamp };
@@ -14,4 +14,5 @@ function clampLatitude(latitude, degrees = true) {
14
14
  return clamp(latitude, -PI_OVER_TWO, PI_OVER_TWO);
15
15
  };
16
16
 
17
- export default clampLatitude;
17
+ export default clampLatitude;
18
+ export { clampLatitude };
@@ -13,4 +13,5 @@ function clampLongitude(longitude, degrees = true) {
13
13
  return clamp(longitude, -Math.PI, Math.PI);
14
14
  };
15
15
 
16
- export default clampLongitude;
16
+ export default clampLongitude;
17
+ export { clampLongitude };
@@ -10,4 +10,5 @@ function convertToDegreesCircular(degrees, minValue = 0) {
10
10
  return convertToRange(degrees, minValue, minValue + 360);
11
11
  };
12
12
 
13
- export default convertToDegreesCircular;
13
+ export default convertToDegreesCircular;
14
+ export { convertToDegreesCircular };
@@ -27,4 +27,5 @@ function convertToLatitudeRange(latitude, degrees = true) {
27
27
  return latitude;
28
28
  };
29
29
 
30
- export default convertToLatitudeRange;
30
+ export default convertToLatitudeRange;
31
+ export { convertToLatitudeRange };
@@ -13,4 +13,5 @@ function convertToLongitudeRange(longitude, degrees = true) {
13
13
  return convertToRange(longitude, -Math.PI, Math.PI);
14
14
  };
15
15
 
16
- export default convertToLongitudeRange;
16
+ export default convertToLongitudeRange;
17
+ export { convertToLongitudeRange };
@@ -11,4 +11,5 @@ function convertToRadiansCircular(radians, minValue = 0) {
11
11
  return convertToRange(radians, minValue, minValue + TWO_PI);
12
12
  };
13
13
 
14
- export default convertToRadiansCircular;
14
+ export default convertToRadiansCircular;
15
+ export { convertToRadiansCircular };
@@ -20,4 +20,5 @@ function convertToRange(value, rangeMinimum, rangeMaximum) {
20
20
  return value;
21
21
  };
22
22
 
23
- export default convertToRange;
23
+ export default convertToRange;
24
+ export { convertToRange };
@@ -9,4 +9,5 @@ function degreesToRadians(degrees) {
9
9
  return degrees * RADIANS_PER_DEGREE;
10
10
  };
11
11
 
12
- export default degreesToRadians;
12
+ export default degreesToRadians;
13
+ export { degreesToRadians };
@@ -2,11 +2,12 @@
2
2
  * 比较两个数值是否近似相等
3
3
  * @param {Number} left
4
4
  * @param {Number} right
5
- * @param {Number} epsilon=0 近似精度,Math.abs(left - right)小于或等于该值时返回true
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 };
@@ -12,4 +12,5 @@ function extractFraction(value) {
12
12
  return 0.0;
13
13
  };
14
14
 
15
- export default extractFraction;
15
+ export default extractFraction;
16
+ export { extractFraction };
@@ -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
@@ -15,4 +15,5 @@ function isBetween(value, rangeMinimum, rangeMaximum, equalsMinimum = true, equa
15
15
  return true;
16
16
  };
17
17
 
18
- export default isBetween;
18
+ export default isBetween;
19
+ export { isBetween };
package/src/lerp.js CHANGED
@@ -14,4 +14,5 @@ function lerp(start, end, scalar, needClamp = true) {
14
14
  return start + (end - start) * scalar;
15
15
  };
16
16
 
17
- export default lerp;
17
+ export default lerp;
18
+ export { lerp };
@@ -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
- * @returns {Object} 输出结果对象, 如:{x: 123, y: 321}
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 (isValid(ndc.z) && (ndc.z < 0 || ndc.z > 1))
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
@@ -12,4 +12,5 @@ function normalize(value, rangeMinimum, rangeMaximum) {
12
12
  return scalarInRange(value, rangeMinimum, rangeMaximum, true);
13
13
  };
14
14
 
15
- export default normalize;
15
+ export default normalize;
16
+ export { normalize };
@@ -0,0 +1,11 @@
1
+ /**
2
+ *
3
+ * @param {Boolean|String} value
4
+ * @returns {Boolean}
5
+ */
6
+ function parseBoolean(value) {
7
+ return value === true || value === 'true';
8
+ };
9
+
10
+ export default parseBoolean;
11
+ export { parseBoolean };
@@ -13,4 +13,5 @@ function parseNumber(value) {
13
13
  }
14
14
  }
15
15
 
16
- export default parseNumber;
16
+ export default parseNumber;
17
+ export { parseNumber };
@@ -9,4 +9,5 @@ function radiansToDegrees(radians) {
9
9
  return radians * DEGREES_PER_RADIAN;
10
10
  }
11
11
 
12
- export default radiansToDegrees;
12
+ export default radiansToDegrees;
13
+ export { radiansToDegrees };
@@ -10,4 +10,5 @@ function randomInteger(rangeMinimum = 0, rangeMaximum = Number.MAX_SAFE_INTEGER
10
10
  return Math.floor(randomNumber(rangeMinimum, rangeMaximum + 1));
11
11
  };
12
12
 
13
- export default randomInteger;
13
+ export default randomInteger;
14
+ export { randomInteger };
@@ -8,4 +8,5 @@ function randomNumber(rangeMinimum = 0, rangeMaximum = Number.MAX_SAFE_INTEGER)
8
8
  return Math.random() * (rangeMaximum - rangeMinimum) + rangeMinimum;
9
9
  };
10
10
 
11
- export default randomNumber;
11
+ export default randomNumber;
12
+ export { randomNumber };
@@ -15,4 +15,5 @@ function scalarInRange(value, rangeMinimum, rangeMaximum, needClamp = false) {
15
15
  return scalar;
16
16
  };
17
17
 
18
- export default scalarInRange;
18
+ export default scalarInRange;
19
+ export { scalarInRange };
package/src/toFixed.js CHANGED
@@ -8,4 +8,5 @@ function toFixed(value, decimalNumber = 2) {
8
8
  return parseFloat(value.toFixed(decimalNumber));
9
9
  }
10
10
 
11
- export default toFixed;
11
+ export default toFixed;
12
+ export { toFixed };
@@ -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 };