From fdd6020d22c6c9d54ce977f125e38b024e284159 Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期六, 17 八月 2024 11:23:17 +0800 Subject: [PATCH] # --- src/utils/common.js | 29 ++++++++++++++++++++++------- 1 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/utils/common.js b/src/utils/common.js index 50bfdb4..9709c90 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -20,12 +20,27 @@ } export const rotationParseNum = (num) => { - const normalizedDegrees = num % 360; + const normalizedDegrees = positiveAngle(num); return normalizedDegrees * Math.PI / 180; } export const minDiffTheta = (originTheta, targetTheta) => { 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) => { @@ -47,13 +62,13 @@ } }; -export const setColor = (obj) => { +export const setColor = (obj, color = 0x4680BF) => { if (obj.material) { - obj.material.color.set(0x4680BF); + obj.material.color.set(color); } if (obj.children) { obj.children.forEach((child) => { - setColor(child); + setColor(child, color); }); } }; @@ -84,9 +99,9 @@ } const locParseArr = locNo.split('-'); return { - row: locParseArr?.[0], - bay: locParseArr?.[1], - lev: locParseArr?.[2], + row: Number(locParseArr?.[0]), + bay: Number(locParseArr?.[1]), + lev: Number(locParseArr?.[2]), } } -- Gitblit v1.9.1