summaryrefslogtreecommitdiff
path: root/src/utils/clamp.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/clamp.js')
-rw-r--r--src/utils/clamp.js6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/utils/clamp.js b/src/utils/clamp.js
new file mode 100644
index 0000000..b709ee5
--- /dev/null
+++ b/src/utils/clamp.js
@@ -0,0 +1,6 @@
+const clamp = (vector, maxX, maxY) => {
+ const newVector = {...vector};
+ newVector.x = Math.max(0, Math.min(maxX, vector.x));
+ newVector.y = Math.max(0, Math.min(maxY, vector.y));
+ return newVector;
+} \ No newline at end of file