Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Vector2i/3i/4i methods: distance_to and distance_squared_to #1347

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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