diff options
author | Aaron Franke <arnfranke@yahoo.com> | 2021-11-29 11:13:31 -0600 |
---|---|---|
committer | Aaron Franke <arnfranke@yahoo.com> | 2022-01-06 10:06:56 -0800 |
commit | 2c52f1646480506d6647ec71e6ea14935caf2e7e (patch) | |
tree | 0f23363d6388499376538e2fd340d412d87f3e99 /core/math/vector2.cpp | |
parent | 1dee3e0cc7590480a77d5bb50a4c90e0286c5e50 (diff) |
Add length and length_squared to Vector2i/3i
Diffstat (limited to 'core/math/vector2.cpp')
-rw-r--r-- | core/math/vector2.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp index 38dad893f5..676a0004ea 100644 --- a/core/math/vector2.cpp +++ b/core/math/vector2.cpp @@ -210,6 +210,14 @@ Vector2i Vector2i::clamp(const Vector2i &p_min, const Vector2i &p_max) const { CLAMP(y, p_min.y, p_max.y)); } +int64_t Vector2i::length_squared() const { + return x * (int64_t)x + y * (int64_t)y; +} + +double Vector2i::length() const { + return Math::sqrt((double)length_squared()); +} + Vector2i Vector2i::operator+(const Vector2i &p_v) const { return Vector2i(x + p_v.x, y + p_v.y); } |