diff --git a/js/CanvasHandler.js b/js/CanvasHandler.js index 2a9d5cc..5b80ff6 100644 --- a/js/CanvasHandler.js +++ b/js/CanvasHandler.js @@ -38,6 +38,14 @@ class CanvasHandler { return unit * Math.sqrt(this.width * this.height); } + clientToCanvas(clientX, clientY) { + const rect = this.canvas.getBoundingClientRect(); + return [ + ((clientX - rect.left) / rect.width) * this.width, + ((clientY - rect.top) / rect.height) * this.height, + ]; + } + get width() { return this.canvas.width / window.devicePixelRatio; }