@lijuhong1981/jsmath 1.3.5 → 1.3.7

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/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2022-2026 lijuhong1981
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -1,11 +1,21 @@
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
+ > 数学工具集,涵盖插值、夹取、角度/弧度换算、经纬度范围、NDC 坐标转换、随机数与数值解析。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install @lijuhong1981/jsmath
9
+ ```
10
+
11
+ ## 导出
12
+
13
+ - **夹取/范围**:`clamp`、`clampLatitude`、`clampLongitude`、`scalarInRange`、`isBetween`、`convertToRange`
14
+ - **角度换算**:`degreesToRadians`、`radiansToDegrees`、`convertToDegreesCircular`、`convertToRadiansCircular`
15
+ - **经纬度范围**:`convertToLatitudeRange`、`convertToLongitudeRange`
16
+ - **插值**:`lerp`
17
+ - **坐标转换**:`getNDCInElement`、`ndcToWindowPosition`、`windowPositionToNDC`
18
+ - **数值处理**:`normalize`、`toFixed`、`extractFraction`、`acosClamped`、`equalsEpsilon`
19
+ - **随机数**:`randomNumber`、`randomInteger`
20
+ - **解析**:`parseBoolean`、`parseNumber`
21
+ - **类/常量**:`Interval`、`Constant`(命名空间导出)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lijuhong1981/jsmath",
3
- "version": "1.3.5",
4
- "description": "> TODO: description",
3
+ "version": "1.3.7",
4
+ "description": "Math utilities: interpolation, clamp, coordinates and random.",
5
5
  "author": "lijuhong1981 <lijuhong@hotmail.com>",
6
6
  "homepage": "https://github.com/lijuhong1981/jslibs#readme",
7
7
  "license": "ISC",
@@ -18,5 +18,5 @@
18
18
  "bugs": {
19
19
  "url": "https://github.com/lijuhong1981/jslibs/issues"
20
20
  },
21
- "gitHead": "cae3f4be65fe0454718936b9ab5a4d29af4fdda0"
21
+ "gitHead": "5d4bd57b654be98c46364160070d5dd11600afa6"
22
22
  }
package/src/Constant.js CHANGED
@@ -10,7 +10,7 @@ const ONE_OVER_TWO_PI = 1.0 / (2.0 * PI);
10
10
  const RADIANS_PER_DEGREE = PI / 180.0;
11
11
  const DEGREES_PER_RADIAN = 180.0 / PI;
12
12
  /**
13
- * The number of radians in an arc second.
13
+ * 一弧秒所对应的弧度数。
14
14
  *
15
15
  * @type {number}
16
16
  * @constant
@@ -1,4 +1,4 @@
1
- import clamp from "./clamp";
1
+ import clamp from "./clamp.js";
2
2
 
3
3
  /**
4
4
  * 计算一个数值的反余弦值,并将输入值约束在-1到1之间
@@ -8,6 +8,8 @@
8
8
  */
9
9
  function convertToRange(value, rangeMinimum, rangeMaximum) {
10
10
  const length = rangeMaximum - rangeMinimum;
11
+ if (length === 0)
12
+ return rangeMinimum;
11
13
  if (value < rangeMinimum) {
12
14
  value += length;
13
15
  while (value < rangeMinimum)
@@ -4,12 +4,7 @@
4
4
  * @returns {Number} 提取的小数
5
5
  */
6
6
  function extractFraction(value) {
7
- value = value.toString();
8
- const arr = value.split('.');
9
- if (arr.length === 2)
10
- return parseFloat('0.' + arr[1]);
11
- else
12
- return 0.0;
7
+ return value - Math.trunc(value);
13
8
  };
14
9
 
15
10
  export default extractFraction;
@@ -3,7 +3,7 @@ import randomNumber from "./randomNumber.js";
3
3
  /**
4
4
  * 产生一个随机整数,可指定随机范围
5
5
  * @param {Number} rangeMinimum 最小整数,默认0
6
- * @param {Number} rangeMaximum 最大整数,默认Number.MAX_SAFE_INTEGER
6
+ * @param {Number} rangeMaximum 最大整数,默认Number.MAX_SAFE_INTEGER - 1
7
7
  * @returns {Integer} 生成的随机整数
8
8
  */
9
9
  function randomInteger(rangeMinimum = 0, rangeMaximum = Number.MAX_SAFE_INTEGER - 1) {