@lijuhong1981/jsmath 1.0.2 → 1.0.4
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 +12 -4
- package/package.json +1 -1
- package/src/clampLatitude.js +16 -0
- package/src/clampLongitude.js +16 -0
- package/src/{convertToDegreesRound.js → convertToDegreesCircular .js } +2 -2
- package/src/convertToLatitudeRange.js +24 -0
- package/src/convertToLongitudeRange.js +10 -0
- package/src/{convertToRadiansRound.js → convertToRadiansCircular.js} +2 -2
package/index.js
CHANGED
|
@@ -13,9 +13,13 @@ import {
|
|
|
13
13
|
RADIANS_PER_ARCSECOND
|
|
14
14
|
} from "./src/Constant.js";
|
|
15
15
|
import clamp from "./src/clamp.js";
|
|
16
|
+
import clampLatitude from "./src/clampLatitude.js";
|
|
17
|
+
import clampLongitude from "./src/clampLongitude.js";
|
|
16
18
|
import convertToRange from "./src/convertToRange.js";
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
+
import convertToDegreesCircular from "./src/convertToDegreesCircular .js";
|
|
20
|
+
import convertToRadiansCircular from "./src/convertToRadiansCircular.js";
|
|
21
|
+
import convertToLatitudeRange from "./src/convertToLatitudeRange.js";
|
|
22
|
+
import convertToLongitudeRange from "./src/convertToLongitudeRange.js";
|
|
19
23
|
import isBetween from "./src/isBetween.js";
|
|
20
24
|
import percentInRange from "./src/percentInRange.js";
|
|
21
25
|
import percentToRange from "./src/percentToRange.js";
|
|
@@ -36,9 +40,13 @@ export {
|
|
|
36
40
|
DEGREES_PER_RADIAN,
|
|
37
41
|
RADIANS_PER_ARCSECOND,
|
|
38
42
|
clamp,
|
|
43
|
+
clampLatitude,
|
|
44
|
+
clampLongitude,
|
|
39
45
|
convertToRange,
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
convertToDegreesCircular,
|
|
47
|
+
convertToRadiansCircular,
|
|
48
|
+
convertToLatitudeRange,
|
|
49
|
+
convertToLongitudeRange,
|
|
42
50
|
isBetween,
|
|
43
51
|
percentInRange,
|
|
44
52
|
percentToRange,
|
package/package.json
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PI_OVER_TWO, clamp } from "@lijuhong1981/jsmath";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 将一个纬度值约束在纬度范围内
|
|
5
|
+
* @param {Number} latitude 需要约束的纬度值
|
|
6
|
+
* @param {Boolean} degrees 单位,true表示角度单位,false表示弧度单位,默认true
|
|
7
|
+
* @returns {Number} 约束后的纬度
|
|
8
|
+
*/
|
|
9
|
+
function clampLatitude(latitude, degrees = true) {
|
|
10
|
+
if (degrees)
|
|
11
|
+
return clamp(latitude, -90, 90);
|
|
12
|
+
else
|
|
13
|
+
return clamp(latitude, -PI_OVER_TWO, PI_OVER_TWO);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default clampLatitude;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { clamp } from "@lijuhong1981/jsmath";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 将一个经度值约束在经度范围内
|
|
5
|
+
* @param {Number} longitude 需要约束的经度值
|
|
6
|
+
* @param {Boolean} degrees 单位,true表示角度单位,false表示弧度单位,默认true
|
|
7
|
+
* @returns {Number} 约束后的经度
|
|
8
|
+
*/
|
|
9
|
+
function clampLongitude(longitude, degrees = true) {
|
|
10
|
+
if (degrees)
|
|
11
|
+
return clamp(longitude, -180, 180);
|
|
12
|
+
else
|
|
13
|
+
return clamp(longitude, -Math.PI, Math.PI);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default clampLongitude;
|
|
@@ -6,8 +6,8 @@ import convertToRange from "./convertToRange.js";
|
|
|
6
6
|
* @param {Number} minValue 起始角度,默认0
|
|
7
7
|
* @returns {Number} 转换后的角度
|
|
8
8
|
*/
|
|
9
|
-
function
|
|
9
|
+
function convertToDegreesCircular(degrees, minValue = 0) {
|
|
10
10
|
return convertToRange(degrees, minValue, minValue + 360);
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export default
|
|
13
|
+
export default convertToDegreesCircular;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { PI_OVER_TWO } from "@lijuhong1981/jsmath";
|
|
2
|
+
|
|
3
|
+
function convertToLatitudeRange(latitude, degrees = true) {
|
|
4
|
+
if (degrees) {
|
|
5
|
+
while (latitude > 90 || latitude < -90) {
|
|
6
|
+
if (latitude > 90) {
|
|
7
|
+
latitude = 180 - latitude;
|
|
8
|
+
} else if (latitude < -90) {
|
|
9
|
+
latitude = -180 - latitude;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
} else {
|
|
13
|
+
while (latitude > PI_OVER_TWO || latitude < -PI_OVER_TWO) {
|
|
14
|
+
if (latitude > PI_OVER_TWO) {
|
|
15
|
+
latitude = Math.PI - latitude;
|
|
16
|
+
} else if (latitude < -PI_OVER_TWO) {
|
|
17
|
+
latitude = -Math.PI - latitude;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return latitude;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default convertToLatitudeRange;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { convertToRange } from "@lijuhong1981/jsmath";
|
|
2
|
+
|
|
3
|
+
function convertToLongitudeRange(longitude, degrees = true) {
|
|
4
|
+
if (degrees)
|
|
5
|
+
return convertToRange(longitude, -180, 180);
|
|
6
|
+
else
|
|
7
|
+
return convertToRange(longitude, -Math.PI, Math.PI);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default convertToLongitudeRange;
|
|
@@ -7,8 +7,8 @@ import { TWO_PI } from "./Constant.js";
|
|
|
7
7
|
* @param {Number} minValue 圆周起始弧度,默认0
|
|
8
8
|
* @returns {Number} 转换后的弧度
|
|
9
9
|
*/
|
|
10
|
-
function
|
|
10
|
+
function convertToRadiansCircular(radians, minValue = 0) {
|
|
11
11
|
return convertToRange(radians, minValue, minValue + TWO_PI);
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
export default
|
|
14
|
+
export default convertToRadiansCircular;
|