From 226001d5a74d2d8d0bdcd0d5413ea7aba5d100c7 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Fri, 14 Jun 2024 22:28:56 +0530 Subject: [PATCH] feat: getMappedCoordinates --- src/helpers/inputHelpers.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/helpers/inputHelpers.ts b/src/helpers/inputHelpers.ts index 0d395ceb..ed48432c 100644 --- a/src/helpers/inputHelpers.ts +++ b/src/helpers/inputHelpers.ts @@ -19,3 +19,27 @@ export const throttle = (callback: any, limit: number) => { } } +export const getMappedCoordinates = ( + event: MouseEvent, + canvas: HTMLCanvasElement | null, + browserWidth: number, + browserHeight: number, +): Coordinates => { + const clientCoordinates = getCoordinates(event, canvas); + const mappedX = mapPixelFromSmallerToLarger( + browserWidth / 100, + ONE_PERCENT_OF_VIEWPORT_W, + clientCoordinates.x, + ); + const mappedY = mapPixelFromSmallerToLarger( + browserHeight / 100, + ONE_PERCENT_OF_VIEWPORT_H, + clientCoordinates.y, + ); + + return { + x: mappedX, + y: mappedY + }; +}; +