Skip to content

Commit

Permalink
Removed Vector2i(Vector2) constructor, added a Vector2i conversion op…
Browse files Browse the repository at this point in the history
…erator to Vector2 instead. This solves ambigous Variant to Vector2i conversion errors.
  • Loading branch information
Relintai committed Mar 7, 2024
1 parent 2e45ffc commit 27b73fa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 6 additions & 1 deletion core/math/vector2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "vector2.h"

#include "core/string/ustring.h"
#include "vector2i.h"

real_t Vector2::angle() const {
return Math::atan2(y, x);
Expand Down Expand Up @@ -173,4 +174,8 @@ bool Vector2::is_equal_approx(const Vector2 &p_v) const {

Vector2::operator String() const {
return "(" + String::num_real(x) + ", " + String::num_real(y) + ")";
}
}

Vector2::operator Vector2i() const {
return Vector2i(x, y);
}
2 changes: 2 additions & 0 deletions core/math/vector2.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "core/error/error_macros.h"

class String;
struct Vector2i;

struct _NO_DISCARD_CLASS_ Vector2 {
static const int AXIS_COUNT = 2;
Expand Down Expand Up @@ -180,6 +181,7 @@ struct _NO_DISCARD_CLASS_ Vector2 {
real_t aspect() const { return width / height; }

operator String() const;
operator Vector2i() const;

_FORCE_INLINE_ Vector2(real_t p_x, real_t p_y) {
x = p_x;
Expand Down
4 changes: 0 additions & 4 deletions core/math/vector2i.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ struct _NO_DISCARD_CLASS_ Vector2i {
operator String() const;
operator Vector2() const { return Vector2(x, y); }

inline Vector2i(const Vector2 &p_vec2) {
x = (int)p_vec2.x;
y = (int)p_vec2.y;
}
inline Vector2i(int p_x, int p_y) {
x = p_x;
y = p_y;
Expand Down

0 comments on commit 27b73fa

Please sign in to comment.