From c06d11bbb8c87baaa8d7e70e82217873249a43e7 Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期三, 31 七月 2024 17:30:02 +0800 Subject: [PATCH] # --- src/utils/common.js | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-) diff --git a/src/utils/common.js b/src/utils/common.js index 149c847..9709c90 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -20,7 +20,7 @@ } export const rotationParseNum = (num) => { - const normalizedDegrees = num % 360; + const normalizedDegrees = positiveAngle(num); return normalizedDegrees * Math.PI / 180; } @@ -28,6 +28,21 @@ return (targetTheta - originTheta > 180) ? targetTheta - 360 : targetTheta; } +export const positiveAngle = (angle) => { + return ((angle % 360) + 360) % 360; +} + +export const normalizeAngle = (angle) => { + let newAngle = angle % 360; + + if (newAngle < -180) { + newAngle += 360; + } else if (newAngle > 180) { + newAngle -= 360; + } + return newAngle; +} + export const calculateMappedPosition = (realPos) => { return [ realPos[0] * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_X, -- Gitblit v1.9.1