Use degToRad/radToDeg methods from AngleHelper where possible

This commit is contained in:
dominik-korsa 2025-07-24 22:52:45 +02:00
parent a453c314bd
commit 318e61be46
No known key found for this signature in database
GPG Key ID: 5A24D76EE0A30974
5 changed files with 11 additions and 10 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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();

View File

@ -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()];
}