summaryrefslogtreecommitdiff
path: root/core/math/vector2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/math/vector2.cpp')
-rw-r--r--core/math/vector2.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp
index ab114673d8..ea430b15c4 100644
--- a/core/math/vector2.cpp
+++ b/core/math/vector2.cpp
@@ -122,6 +122,12 @@ Vector2 Vector2::project(const Vector2 &p_to) const {
return p_to * (dot(p_to) / p_to.length_squared());
}
+Vector2 Vector2::clamp(const Vector2 &p_min, const Vector2 &p_max) const {
+ return Vector2(
+ CLAMP(x, p_min.x, p_max.x),
+ CLAMP(y, p_min.y, p_max.y));
+}
+
Vector2 Vector2::snapped(const Vector2 &p_step) const {
return Vector2(
Math::snapped(x, p_step.x),
@@ -189,6 +195,12 @@ bool Vector2::is_equal_approx(const Vector2 &p_v) const {
/* Vector2i */
+Vector2i Vector2i::clamp(const Vector2i &p_min, const Vector2i &p_max) const {
+ return Vector2i(
+ CLAMP(x, p_min.x, p_max.x),
+ CLAMP(y, p_min.y, p_max.y));
+}
+
Vector2i Vector2i::operator+(const Vector2i &p_v) const {
return Vector2i(x + p_v.x, y + p_v.y);
}