Use degToRad/radToDeg methods from AngleHelper where possible
This commit is contained in:
parent
a453c314bd
commit
318e61be46
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
@ -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()];
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user