@lijuhong1981/jsmath 1.0.3 → 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 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
19
  import convertToDegreesCircular from "./src/convertToDegreesCircular .js";
18
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
46
  convertToDegreesCircular,
41
47
  convertToRadiansCircular,
48
+ convertToLatitudeRange,
49
+ convertToLongitudeRange,
42
50
  isBetween,
43
51
  percentInRange,
44
52
  percentToRange,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lijuhong1981/jsmath",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -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;
@@ -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;