lyb-js 1.6.5 → 1.6.6

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.
@@ -9,4 +9,4 @@ export declare const libJsCoordsAngle: (coord1: {
9
9
  }, coord2: {
10
10
  x: number;
11
11
  y: number;
12
- }) => number;
12
+ }, mode?: "deg" | "rad") => number;
@@ -3,19 +3,22 @@
3
3
  * @param coord2 终点坐标
4
4
  * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsCoordsAngle-两点角度
5
5
  */
6
- export const libJsCoordsAngle = (coord1, coord2) => {
6
+ export const libJsCoordsAngle = (coord1, coord2, mode = "deg") => {
7
7
  //计算相对于第一个坐标的水平和垂直距离
8
8
  const deltaX = coord2.x - coord1.x;
9
9
  const deltaY = coord2.y - coord1.y;
10
10
  //使用反三角函数计算角度(以弧度为单位)
11
11
  const angleRad = Math.atan2(deltaY, deltaX);
12
- //将弧度转换为角度
13
- let angleDeg = angleRad * (180 / Math.PI);
14
- //将角度转换为顺时针方向为正方向的角度
15
- angleDeg = -angleDeg + 90;
16
- //调整角度使得右边成为 360 度的位置变为 0
17
- if (angleDeg < 0) {
18
- angleDeg += 360;
12
+ if (mode === "deg") {
13
+ //将弧度转换为角度
14
+ let angleDeg = angleRad * (180 / Math.PI);
15
+ //将角度转换为顺时针方向为正方向的角度
16
+ angleDeg = -angleDeg + 90;
17
+ //调整角度使得右边成为 360 度的位置变为 0
18
+ if (angleDeg < 0) {
19
+ angleDeg += 360;
20
+ }
21
+ return angleDeg;
19
22
  }
20
- return angleDeg;
23
+ return angleRad;
21
24
  };
package/libJs.d.ts CHANGED
@@ -198,7 +198,7 @@ export declare const Math: {
198
198
  }, coord2: {
199
199
  x: number;
200
200
  y: number;
201
- }) => number;
201
+ }, mode?: "deg" | "rad") => number;
202
202
  /** @description 计算两点距离
203
203
  * @param coord1 起点坐标
204
204
  * @param coord2 终点坐标
package/lyb.js CHANGED
@@ -284,16 +284,19 @@ ${log3.label}:`, log3.value];
284
284
  throw new Error("请使用正确类型");
285
285
  }
286
286
  };
287
- const libJsCoordsAngle = (coord1, coord2) => {
287
+ const libJsCoordsAngle = (coord1, coord2, mode = "deg") => {
288
288
  const deltaX = coord2.x - coord1.x;
289
289
  const deltaY = coord2.y - coord1.y;
290
290
  const angleRad = Math.atan2(deltaY, deltaX);
291
- let angleDeg = angleRad * (180 / Math.PI);
292
- angleDeg = -angleDeg + 90;
293
- if (angleDeg < 0) {
294
- angleDeg += 360;
291
+ if (mode === "deg") {
292
+ let angleDeg = angleRad * (180 / Math.PI);
293
+ angleDeg = -angleDeg + 90;
294
+ if (angleDeg < 0) {
295
+ angleDeg += 360;
296
+ }
297
+ return angleDeg;
295
298
  }
296
- return angleDeg;
299
+ return angleRad;
297
300
  };
298
301
  const libJsCoordsDistance = (coord1, coord2) => {
299
302
  const deltaX = coord2.x - coord1.x;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lyb-js",
3
- "version": "1.6.5",
3
+ "version": "1.6.6",
4
4
  "description": "自用JS方法库",
5
5
  "license": "ISC",
6
6
  "type": "module",