We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c9d41af commit dafbe4bCopy full SHA for dafbe4b
src/utils.js
@@ -16,6 +16,26 @@ export const randomInt = (min = 0, max = 1) => {
16
17
};
18
19
+// converts screen point to canvas point
20
+
21
+export const screenToCanvas = (cnv, x, y) => {
22
23
+ const rect = cnv.getBoundingClientRect(), // abs. size of element
24
25
+ scaleX = cnv.width / rect.width, // relationship bitmap vs. element for X
26
27
+ scaleY = cmv.height / rect.height; // relationship bitmap vs. element for Y
28
29
+ return {
30
31
+ x: (x - rect.left) * scaleX, // scale mouse coordinates after they have
32
33
+ y: (y - rect.top) * scaleY // been adjusted to be relative to element
34
35
+ }
36
37
+};
38
39
// array stuff
40
41
export const unique = arr => [...new Set(arr)];
0 commit comments