Skip to content

Commit

Permalink
Merge pull request #1347 from Chubercik/vector_method_parity
Browse files Browse the repository at this point in the history
Add `Vector2i/3i/4i` methods: `distance_to` and `distance_squared_to`
  • Loading branch information
dsnopek authored Jan 4, 2024
2 parents 8d13acc + b733102 commit dd62b96
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/godot_cpp/variant/vector2i.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ struct _NO_DISCARD_ Vector2i {
int64_t length_squared() const;
double length() const;

int64_t distance_squared_to(const Vector2i &p_to) const;
double distance_to(const Vector2i &p_to) const;

real_t aspect() const { return width / (real_t)height; }
Vector2i sign() const { return Vector2i(SIGN(x), SIGN(y)); }
Vector2i abs() const { return Vector2i(Math::abs(x), Math::abs(y)); }
Expand Down
11 changes: 11 additions & 0 deletions include/godot_cpp/variant/vector3i.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ struct _NO_DISCARD_ Vector3i {
_FORCE_INLINE_ int64_t length_squared() const;
_FORCE_INLINE_ double length() const;

_FORCE_INLINE_ int64_t distance_squared_to(const Vector3i &p_to) const;
_FORCE_INLINE_ double distance_to(const Vector3i &p_to) const;

_FORCE_INLINE_ void zero();

_FORCE_INLINE_ Vector3i abs() const;
Expand Down Expand Up @@ -136,6 +139,14 @@ double Vector3i::length() const {
return Math::sqrt((double)length_squared());
}

int64_t Vector3i::distance_squared_to(const Vector3i &p_to) const {
return (p_to - *this).length_squared();
}

double Vector3i::distance_to(const Vector3i &p_to) const {
return (p_to - *this).length();
}

Vector3i Vector3i::abs() const {
return Vector3i(Math::abs(x), Math::abs(y), Math::abs(z));
}
Expand Down
11 changes: 11 additions & 0 deletions include/godot_cpp/variant/vector4i.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ struct _NO_DISCARD_ Vector4i {
_FORCE_INLINE_ int64_t length_squared() const;
_FORCE_INLINE_ double length() const;

_FORCE_INLINE_ int64_t distance_squared_to(const Vector4i &p_to) const;
_FORCE_INLINE_ double distance_to(const Vector4i &p_to) const;

_FORCE_INLINE_ void zero();

_FORCE_INLINE_ Vector4i abs() const;
Expand Down Expand Up @@ -140,6 +143,14 @@ double Vector4i::length() const {
return Math::sqrt((double)length_squared());
}

int64_t Vector4i::distance_squared_to(const Vector4i &p_to) const {
return (p_to - *this).length_squared();
}

double Vector4i::distance_to(const Vector4i &p_to) const {
return (p_to - *this).length();
}

Vector4i Vector4i::abs() const {
return Vector4i(Math::abs(x), Math::abs(y), Math::abs(z), Math::abs(w));
}
Expand Down
8 changes: 8 additions & 0 deletions src/variant/vector2i.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit dd62b96

Please sign in to comment.