diff --git a/src/components/map/ZoomPanWrapper.js b/src/components/map/ZoomPanWrapper.js index 2a5295e..888acdf 100644 --- a/src/components/map/ZoomPanWrapper.js +++ b/src/components/map/ZoomPanWrapper.js @@ -65,8 +65,8 @@ export default function ZoomPanWrapper({children}) { const handleMove = (e) => { const cx = e.movementX / cameraRef.current.zoom; const cy = e.movementY / cameraRef.current.zoom; - const cos = Math.cos(cameraRef.current.rotation * Math.PI / 180); - const sin = Math.sin(cameraRef.current.rotation * Math.PI / 180); + const cos = Math.cos(AngleHelper.degToRad(cameraRef.current.rotation)); + const sin = Math.sin(AngleHelper.degToRad(cameraRef.current.rotation)); cameraRef.current.x -= cx * cos + cy * sin; cameraRef.current.y -= cy * cos - cx * sin; @@ -130,8 +130,8 @@ export default function ZoomPanWrapper({children}) { const offY = (ncy - cy) / newZoom; // update camera position so the cursor stays in the same place - const cos = Math.cos(cameraRef.current.rotation * Math.PI / 180); - const sin = Math.sin(cameraRef.current.rotation * Math.PI / 180); + const cos = Math.cos(AngleHelper.degToRad(cameraRef.current.rotation)); + const sin = Math.sin(AngleHelper.degToRad(cameraRef.current.rotation)); cameraRef.current.x += offX * cos + offY * sin; cameraRef.current.y += offY * cos - offX * sin; diff --git a/src/components/map/distance-meter/DistanceMeterText.js b/src/components/map/distance-meter/DistanceMeterText.js index 597c102..25ebf24 100644 --- a/src/components/map/distance-meter/DistanceMeterText.js +++ b/src/components/map/distance-meter/DistanceMeterText.js @@ -11,7 +11,7 @@ export default function DistanceMeterText(props) { const dx = end[0] - start[0]; const dy = end[1] - start[1]; const len = Math.sqrt(dx * dx + dy * dy); - const angle = Math.atan2(dy, dx) * (180 / Math.PI); + const angle = AngleHelper.radToDeg(Math.atan2(dy, dx)); const rotation = AngleHelper.normalizeDegAngle(mapRotation + angle); const upsideDown = rotation >= 90 && rotation <= 270; const x = cx + len / 2; diff --git a/src/components/map/distance-meter/get-svg-coords.js b/src/components/map/distance-meter/get-svg-coords.js index af12a71..7f94106 100644 --- a/src/components/map/distance-meter/get-svg-coords.js +++ b/src/components/map/distance-meter/get-svg-coords.js @@ -1,10 +1,11 @@ import { getCurrentCamera, getCurrentClientRect, getCurrentViewBox } from "../../../hooks/useZoomPubSub"; +import AngleHelper from "../../../helpers/angleHelper"; export function getSVGCoords(event) { const { left, top } = getCurrentClientRect(); const { x, y, zoom, rotation } = getCurrentCamera(); const { w, h } = getCurrentViewBox(); - + // screen space cursor pos const cx = event.clientX - left; const cy = event.clientY - top; @@ -14,8 +15,8 @@ export function getSVGCoords(event) { const dy = -(h / 2 - cy) / zoom; // apply camera rotation - const cos = Math.cos(rotation * Math.PI / 180); - const sin = Math.sin(rotation * Math.PI / 180); + const cos = Math.cos(AngleHelper.degToRad(rotation)); + const sin = Math.sin(AngleHelper.degToRad(rotation)); const rdx = dx * cos + dy * sin; const rdy = dy * cos - dx * sin; diff --git a/src/model/misc/misc.js b/src/model/misc/misc.js index d3743ca..9786e61 100644 --- a/src/model/misc/misc.js +++ b/src/model/misc/misc.js @@ -39,7 +39,7 @@ export default class Misc extends SceneryObject { } static applyGroupTransforms(localPos, localRot, miscGroups) { - const localRotRad = localRot.multiply(Math.PI / 180); + const localRotRad = AngleHelper.vectorDegToRad(localRot); let worldQuat = Quaternion.fromEulerAnglesRad(localRotRad).normalize(); let worldPos = localPos.clone(); diff --git a/src/model/route.js b/src/model/route.js index f26e541..c0b663a 100644 --- a/src/model/route.js +++ b/src/model/route.js @@ -32,7 +32,7 @@ export default class Route extends SceneryObject { }); this.offsets = this._getOffsets(); - this.end_angle_rad = this.rot.y * Math.PI / 180; + this.end_angle_rad = AngleHelper.degToRad(this.rot.y); this.end_center = this.pos.clone(); this.points = [this.pos.clone()]; }