diff options
author | David Snopek <dsnopek@gmail.com> | 2024-01-04 08:36:30 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-04 08:36:30 -0600 |
commit | dd62b9685fbc9b733a25e26a788b5d7f3212a804 (patch) | |
tree | a755762614f9144fd5a0cc450d6cb0594a1a267f /src/variant/vector2i.cpp | |
parent | 8d13acca919daa09f2db68e4de36a59199ce6b55 (diff) | |
parent | b733102f4a7fd19e18c86751ea3ec7398571bacf (diff) | |
download | redot-cpp-dd62b9685fbc9b733a25e26a788b5d7f3212a804.tar.gz |
Merge pull request #1347 from Chubercik/vector_method_parity
Add `Vector2i/3i/4i` methods: `distance_to` and `distance_squared_to`
Diffstat (limited to 'src/variant/vector2i.cpp')
-rw-r--r-- | src/variant/vector2i.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/variant/vector2i.cpp b/src/variant/vector2i.cpp index 226a061..c1c1ab0 100644 --- a/src/variant/vector2i.cpp +++ b/src/variant/vector2i.cpp @@ -49,6 +49,14 @@ double Vector2i::length() const { return Math::sqrt((double)length_squared()); } +int64_t Vector2i::distance_squared_to(const Vector2i &p_to) const { + return (p_to - *this).length_squared(); +} + +double Vector2i::distance_to(const Vector2i &p_to) const { + return (p_to - *this).length(); +} + Vector2i Vector2i::operator+(const Vector2i &p_v) const { return Vector2i(x + p_v.x, y + p_v.y); } |