summaryrefslogtreecommitdiffstats
path: root/src/variant
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2022-02-20 11:47:57 +0100
committerRémi Verschelde <rverschelde@gmail.com>2022-02-20 12:04:08 +0100
commit7e3321d1b2fc9f81191f53ee427d44bed6a2d923 (patch)
tree7d2abe629e5ad7d6ab76d30a39b967e506d13a84 /src/variant
parent917b0c2ca3e8363082d62acdc7dc73d77b1c68ec (diff)
downloadredot-cpp-7e3321d1b2fc9f81191f53ee427d44bed6a2d923.tar.gz
Use forward declares for vector math types
Adds operators to convert from int vector types to float vector types as done in the upstream engine implementations.
Diffstat (limited to 'src/variant')
-rw-r--r--src/variant/rect2.cpp10
-rw-r--r--src/variant/rect2i.cpp15
-rw-r--r--src/variant/vector2.cpp19
-rw-r--r--src/variant/vector2i.cpp16
-rw-r--r--src/variant/vector3.cpp3
-rw-r--r--src/variant/vector3i.cpp8
6 files changed, 54 insertions, 17 deletions
diff --git a/src/variant/rect2.cpp b/src/variant/rect2.cpp
index 176a250..7ca8719 100644
--- a/src/variant/rect2.cpp
+++ b/src/variant/rect2.cpp
@@ -30,6 +30,8 @@
#include <godot_cpp/variant/rect2.hpp>
+#include <godot_cpp/variant/rect2i.hpp>
+#include <godot_cpp/variant/string.hpp>
#include <godot_cpp/variant/transform2d.hpp>
namespace godot {
@@ -268,4 +270,12 @@ next4:
return true;
}
+Rect2::operator String() const {
+ return String(position) + ", " + String(size);
+}
+
+Rect2::operator Rect2i() const {
+ return Rect2i(position, size);
+}
+
} // namespace godot
diff --git a/src/variant/rect2i.cpp b/src/variant/rect2i.cpp
index 92db0c9..ab3ad7d 100644
--- a/src/variant/rect2i.cpp
+++ b/src/variant/rect2i.cpp
@@ -30,4 +30,17 @@
#include <godot_cpp/variant/rect2i.hpp>
-// No implementation left. This is here to add the header as a compiled unit.
+#include <godot_cpp/variant/rect2.hpp>
+#include <godot_cpp/variant/string.hpp>
+
+namespace godot {
+
+Rect2i::operator String() const {
+ return String(position) + ", " + String(size);
+}
+
+Rect2i::operator Rect2() const {
+ return Rect2(position, size);
+}
+
+} // namespace godot
diff --git a/src/variant/vector2.cpp b/src/variant/vector2.cpp
index 7ba0910..c585892 100644
--- a/src/variant/vector2.cpp
+++ b/src/variant/vector2.cpp
@@ -28,21 +28,14 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+#include <godot_cpp/variant/vector2.hpp>
+
#include <godot_cpp/core/error_macros.hpp>
#include <godot_cpp/variant/string.hpp>
-#include <godot_cpp/variant/vector2.hpp>
#include <godot_cpp/variant/vector2i.hpp>
namespace godot {
-Vector2::operator String() const {
- return String::num(x, 5) + ", " + String::num(y, 5);
-}
-
-Vector2::operator Vector2i() const {
- return Vector2i(x, y);
-}
-
real_t Vector2::angle() const {
return Math::atan2(y, x);
}
@@ -200,4 +193,12 @@ bool Vector2::is_equal_approx(const Vector2 &p_v) const {
return Math::is_equal_approx(x, p_v.x) && Math::is_equal_approx(y, p_v.y);
}
+Vector2::operator String() const {
+ return String::num(x, 5) + ", " + String::num(y, 5);
+}
+
+Vector2::operator Vector2i() const {
+ return Vector2i(x, y);
+}
+
} // namespace godot
diff --git a/src/variant/vector2i.cpp b/src/variant/vector2i.cpp
index fa2d3ab..ed9d5ad 100644
--- a/src/variant/vector2i.cpp
+++ b/src/variant/vector2i.cpp
@@ -28,16 +28,14 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+#include <godot_cpp/variant/vector2i.hpp>
+
#include <godot_cpp/core/error_macros.hpp>
#include <godot_cpp/variant/string.hpp>
-#include <godot_cpp/variant/vector2i.hpp>
+#include <godot_cpp/variant/vector2.hpp>
namespace godot {
-Vector2i::operator String() const {
- return String::num(x, 0) + ", " + String::num(y, 0);
-}
-
Vector2i Vector2i::operator+(const Vector2i &p_v) const {
return Vector2i(x + p_v.x, y + p_v.y);
}
@@ -107,4 +105,12 @@ bool Vector2i::operator!=(const Vector2i &p_vec2) const {
return x != p_vec2.x || y != p_vec2.y;
}
+Vector2i::operator String() const {
+ return String::num(x, 0) + ", " + String::num(y, 0);
+}
+
+Vector2i::operator Vector2() const {
+ return Vector2((real_t)x, (real_t)y);
+}
+
} // namespace godot
diff --git a/src/variant/vector3.cpp b/src/variant/vector3.cpp
index 6cfb92a..f888775 100644
--- a/src/variant/vector3.cpp
+++ b/src/variant/vector3.cpp
@@ -28,9 +28,10 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+#include <godot_cpp/variant/vector3.hpp>
+
#include <godot_cpp/core/error_macros.hpp>
#include <godot_cpp/variant/basis.hpp>
-#include <godot_cpp/variant/vector3.hpp>
#include <godot_cpp/variant/vector3i.hpp>
namespace godot {
diff --git a/src/variant/vector3i.cpp b/src/variant/vector3i.cpp
index 67c0bc5..0849762 100644
--- a/src/variant/vector3i.cpp
+++ b/src/variant/vector3i.cpp
@@ -28,9 +28,11 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+#include <godot_cpp/variant/vector3i.hpp>
+
#include <godot_cpp/core/error_macros.hpp>
#include <godot_cpp/variant/string.hpp>
-#include <godot_cpp/variant/vector3i.hpp>
+#include <godot_cpp/variant/vector3.hpp>
namespace godot {
@@ -56,4 +58,8 @@ Vector3i::operator String() const {
return (String::num(x, 0) + ", " + String::num(y, 0) + ", " + String::num(z, 5));
}
+Vector3i::operator Vector3() const {
+ return Vector3((real_t)x, (real_t)y, (real_t)z);
+}
+
} // namespace godot