summaryrefslogtreecommitdiffstats
path: root/include/godot_cpp/variant
diff options
context:
space:
mode:
Diffstat (limited to 'include/godot_cpp/variant')
-rw-r--r--include/godot_cpp/variant/aabb.hpp123
-rw-r--r--include/godot_cpp/variant/basis.hpp1
-rw-r--r--include/godot_cpp/variant/color.hpp85
-rw-r--r--include/godot_cpp/variant/plane.hpp41
-rw-r--r--include/godot_cpp/variant/projection.hpp25
-rw-r--r--include/godot_cpp/variant/quaternion.hpp3
-rw-r--r--include/godot_cpp/variant/rect2.hpp89
-rw-r--r--include/godot_cpp/variant/rect2i.hpp59
-rw-r--r--include/godot_cpp/variant/transform2d.hpp87
-rw-r--r--include/godot_cpp/variant/vector4i.hpp3
10 files changed, 314 insertions, 202 deletions
diff --git a/include/godot_cpp/variant/aabb.hpp b/include/godot_cpp/variant/aabb.hpp
index 06ddc15..b652a80 100644
--- a/include/godot_cpp/variant/aabb.hpp
+++ b/include/godot_cpp/variant/aabb.hpp
@@ -31,29 +31,29 @@
#ifndef GODOT_AABB_HPP
#define GODOT_AABB_HPP
-#include <godot_cpp/core/error_macros.hpp>
-#include <godot_cpp/core/math.hpp>
#include <godot_cpp/variant/plane.hpp>
#include <godot_cpp/variant/vector3.hpp>
/**
- * AABB / AABB (Axis Aligned Bounding Box)
- * This is implemented by a point (position) and the box size
+ * AABB (Axis Aligned Bounding Box)
+ * This is implemented by a point (position) and the box size.
*/
namespace godot {
+class Variant;
+
struct _NO_DISCARD_ AABB {
Vector3 position;
Vector3 size;
- real_t get_area() const; /// get area
- inline bool has_no_area() const {
- return (size.x <= 0 || size.y <= 0 || size.z <= 0);
+ real_t get_volume() const;
+ _FORCE_INLINE_ bool has_volume() const {
+ return size.x > 0.0f && size.y > 0.0f && size.z > 0.0f;
}
- inline bool has_no_surface() const {
- return (size.x <= 0 && size.y <= 0 && size.z <= 0);
+ _FORCE_INLINE_ bool has_surface() const {
+ return size.x > 0.0f || size.y > 0.0f || size.z > 0.0f;
}
const Vector3 &get_position() const { return position; }
@@ -65,60 +65,67 @@ struct _NO_DISCARD_ AABB {
bool operator!=(const AABB &p_rval) const;
bool is_equal_approx(const AABB &p_aabb) const;
- inline bool intersects(const AABB &p_aabb) const; /// Both AABBs overlap
- inline bool intersects_inclusive(const AABB &p_aabb) const; /// Both AABBs (or their faces) overlap
- inline bool encloses(const AABB &p_aabb) const; /// p_aabb is completely inside this
+ _FORCE_INLINE_ bool intersects(const AABB &p_aabb) const; /// Both AABBs overlap
+ _FORCE_INLINE_ bool intersects_inclusive(const AABB &p_aabb) const; /// Both AABBs (or their faces) overlap
+ _FORCE_INLINE_ bool encloses(const AABB &p_aabb) const; /// p_aabb is completely inside this
AABB merge(const AABB &p_with) const;
- void merge_with(const AABB &p_aabb); /// merge with another AABB
- AABB intersection(const AABB &p_aabb) const; /// get box where two intersect, empty if no intersection occurs
+ void merge_with(const AABB &p_aabb); ///merge with another AABB
+ AABB intersection(const AABB &p_aabb) const; ///get box where two intersect, empty if no intersection occurs
bool intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector3 *r_clip = nullptr, Vector3 *r_normal = nullptr) const;
bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *r_clip = nullptr, Vector3 *r_normal = nullptr) const;
- inline bool smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t t0, real_t t1) const;
+ _FORCE_INLINE_ bool smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t t0, real_t t1) const;
- inline bool intersects_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count) const;
- inline bool inside_convex_shape(const Plane *p_planes, int p_plane_count) const;
+ _FORCE_INLINE_ bool intersects_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count) const;
+ _FORCE_INLINE_ bool inside_convex_shape(const Plane *p_planes, int p_plane_count) const;
bool intersects_plane(const Plane &p_plane) const;
- inline bool has_point(const Vector3 &p_point) const;
- inline Vector3 get_support(const Vector3 &p_normal) const;
+ _FORCE_INLINE_ bool has_point(const Vector3 &p_point) const;
+ _FORCE_INLINE_ Vector3 get_support(const Vector3 &p_normal) const;
Vector3 get_longest_axis() const;
int get_longest_axis_index() const;
- inline real_t get_longest_axis_size() const;
+ _FORCE_INLINE_ real_t get_longest_axis_size() const;
Vector3 get_shortest_axis() const;
int get_shortest_axis_index() const;
- inline real_t get_shortest_axis_size() const;
+ _FORCE_INLINE_ real_t get_shortest_axis_size() const;
AABB grow(real_t p_by) const;
- inline void grow_by(real_t p_amount);
+ _FORCE_INLINE_ void grow_by(real_t p_amount);
void get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const;
- inline Vector3 get_endpoint(int p_point) const;
+ _FORCE_INLINE_ Vector3 get_endpoint(int p_point) const;
AABB expand(const Vector3 &p_vector) const;
- inline void project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const;
- inline void expand_to(const Vector3 &p_vector); /** expand to contain a point if necessary */
+ _FORCE_INLINE_ void project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const;
+ _FORCE_INLINE_ void expand_to(const Vector3 &p_vector); /** expand to contain a point if necessary */
- inline AABB abs() const {
- return AABB(Vector3(position.x + Math::min(size.x, (real_t)0), position.y + Math::min(size.y, (real_t)0), position.z + Math::min(size.z, (real_t)0)), size.abs());
+ _FORCE_INLINE_ AABB abs() const {
+ return AABB(Vector3(position.x + MIN(size.x, (real_t)0), position.y + MIN(size.y, (real_t)0), position.z + MIN(size.z, (real_t)0)), size.abs());
}
- inline void quantize(real_t p_unit);
- inline AABB quantized(real_t p_unit) const;
+ Variant intersects_segment_bind(const Vector3 &p_from, const Vector3 &p_to) const;
+ Variant intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const;
+
+ _FORCE_INLINE_ void quantize(real_t p_unit);
+ _FORCE_INLINE_ AABB quantized(real_t p_unit) const;
- inline void set_end(const Vector3 &p_end) {
+ _FORCE_INLINE_ void set_end(const Vector3 &p_end) {
size = p_end - position;
}
- inline Vector3 get_end() const {
+ _FORCE_INLINE_ Vector3 get_end() const {
return position + size;
}
+ _FORCE_INLINE_ Vector3 get_center() const {
+ return position + (size * 0.5f);
+ }
+
operator String() const;
- inline AABB() {}
+ _FORCE_INLINE_ AABB() {}
inline AABB(const Vector3 &p_pos, const Vector3 &p_size) :
position(p_pos),
size(p_size) {
@@ -126,6 +133,11 @@ struct _NO_DISCARD_ AABB {
};
inline bool AABB::intersects(const AABB &p_aabb) const {
+#ifdef MATH_CHECKS
+ if (unlikely(size.x < 0 || size.y < 0 || size.z < 0 || p_aabb.size.x < 0 || p_aabb.size.y < 0 || p_aabb.size.z < 0)) {
+ ERR_PRINT("AABB size is negative, this is not supported. Use AABB.abs() to get an AABB with a positive size.");
+ }
+#endif
if (position.x >= (p_aabb.position.x + p_aabb.size.x)) {
return false;
}
@@ -149,6 +161,11 @@ inline bool AABB::intersects(const AABB &p_aabb) const {
}
inline bool AABB::intersects_inclusive(const AABB &p_aabb) const {
+#ifdef MATH_CHECKS
+ if (unlikely(size.x < 0 || size.y < 0 || size.z < 0 || p_aabb.size.x < 0 || p_aabb.size.y < 0 || p_aabb.size.z < 0)) {
+ ERR_PRINT("AABB size is negative, this is not supported. Use AABB.abs() to get an AABB with a positive size.");
+ }
+#endif
if (position.x > (p_aabb.position.x + p_aabb.size.x)) {
return false;
}
@@ -172,6 +189,11 @@ inline bool AABB::intersects_inclusive(const AABB &p_aabb) const {
}
inline bool AABB::encloses(const AABB &p_aabb) const {
+#ifdef MATH_CHECKS
+ if (unlikely(size.x < 0 || size.y < 0 || size.z < 0 || p_aabb.size.x < 0 || p_aabb.size.y < 0 || p_aabb.size.z < 0)) {
+ ERR_PRINT("AABB size is negative, this is not supported. Use AABB.abs() to get an AABB with a positive size.");
+ }
+#endif
Vector3 src_min = position;
Vector3 src_max = position + size;
Vector3 dst_min = p_aabb.position;
@@ -187,14 +209,14 @@ inline bool AABB::encloses(const AABB &p_aabb) const {
}
Vector3 AABB::get_support(const Vector3 &p_normal) const {
- Vector3 half_extents = size * 0.5;
+ Vector3 half_extents = size * 0.5f;
Vector3 ofs = position + half_extents;
return Vector3(
(p_normal.x > 0) ? half_extents.x : -half_extents.x,
(p_normal.y > 0) ? half_extents.y : -half_extents.y,
(p_normal.z > 0) ? half_extents.z : -half_extents.z) +
- ofs;
+ ofs;
}
Vector3 AABB::get_endpoint(int p_point) const {
@@ -221,7 +243,7 @@ Vector3 AABB::get_endpoint(int p_point) const {
}
bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count) const {
- Vector3 half_extents = size * 0.5;
+ Vector3 half_extents = size * 0.5f;
Vector3 ofs = position + half_extents;
for (int i = 0; i < p_plane_count; i++) {
@@ -263,7 +285,7 @@ bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count, con
}
bool AABB::inside_convex_shape(const Plane *p_planes, int p_plane_count) const {
- Vector3 half_extents = size * 0.5;
+ Vector3 half_extents = size * 0.5f;
Vector3 ofs = position + half_extents;
for (int i = 0; i < p_plane_count; i++) {
@@ -282,6 +304,11 @@ bool AABB::inside_convex_shape(const Plane *p_planes, int p_plane_count) const {
}
bool AABB::has_point(const Vector3 &p_point) const {
+#ifdef MATH_CHECKS
+ if (unlikely(size.x < 0 || size.y < 0 || size.z < 0)) {
+ ERR_PRINT("AABB size is negative, this is not supported. Use AABB.abs() to get an AABB with a positive size.");
+ }
+#endif
if (p_point.x < position.x) {
return false;
}
@@ -305,6 +332,11 @@ bool AABB::has_point(const Vector3 &p_point) const {
}
inline void AABB::expand_to(const Vector3 &p_vector) {
+#ifdef MATH_CHECKS
+ if (unlikely(size.x < 0 || size.y < 0 || size.z < 0)) {
+ ERR_PRINT("AABB size is negative, this is not supported. Use AABB.abs() to get an AABB with a positive size.");
+ }
+#endif
Vector3 begin = position;
Vector3 end = position + size;
@@ -333,7 +365,7 @@ inline void AABB::expand_to(const Vector3 &p_vector) {
}
void AABB::project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const {
- Vector3 half_extents(size.x * (real_t)0.5, size.y * (real_t)0.5, size.z * (real_t)0.5);
+ Vector3 half_extents(size.x * 0.5f, size.y * 0.5f, size.z * 0.5f);
Vector3 center(position.x + half_extents.x, position.y + half_extents.y, position.z + half_extents.z);
real_t length = p_plane.normal.abs().dot(half_extents);
@@ -371,9 +403,14 @@ inline real_t AABB::get_shortest_axis_size() const {
}
bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t t0, real_t t1) const {
- real_t divx = (real_t)1.0 / p_dir.x;
- real_t divy = (real_t)1.0 / p_dir.y;
- real_t divz = (real_t)1.0 / p_dir.z;
+#ifdef MATH_CHECKS
+ if (unlikely(size.x < 0 || size.y < 0 || size.z < 0)) {
+ ERR_PRINT("AABB size is negative, this is not supported. Use AABB.abs() to get an AABB with a positive size.");
+ }
+#endif
+ real_t divx = 1.0f / p_dir.x;
+ real_t divy = 1.0f / p_dir.y;
+ real_t divz = 1.0f / p_dir.z;
Vector3 upbound = position + size;
real_t tmin, tmax, tymin, tymax, tzmin, tzmax;
@@ -423,9 +460,9 @@ void AABB::grow_by(real_t p_amount) {
position.x -= p_amount;
position.y -= p_amount;
position.z -= p_amount;
- size.x += (real_t)2.0 * p_amount;
- size.y += (real_t)2.0 * p_amount;
- size.z += (real_t)2.0 * p_amount;
+ size.x += 2.0f * p_amount;
+ size.y += 2.0f * p_amount;
+ size.z += 2.0f * p_amount;
}
void AABB::quantize(real_t p_unit) {
diff --git a/include/godot_cpp/variant/basis.hpp b/include/godot_cpp/variant/basis.hpp
index 48c3b0c..00dbc50 100644
--- a/include/godot_cpp/variant/basis.hpp
+++ b/include/godot_cpp/variant/basis.hpp
@@ -31,7 +31,6 @@
#ifndef GODOT_BASIS_HPP
#define GODOT_BASIS_HPP
-#include <godot_cpp/core/math.hpp>
#include <godot_cpp/variant/quaternion.hpp>
#include <godot_cpp/variant/vector3.hpp>
diff --git a/include/godot_cpp/variant/color.hpp b/include/godot_cpp/variant/color.hpp
index f328d7f..c1126c1 100644
--- a/include/godot_cpp/variant/color.hpp
+++ b/include/godot_cpp/variant/color.hpp
@@ -54,15 +54,16 @@ struct _NO_DISCARD_ Color {
uint64_t to_rgba64() const;
uint64_t to_argb64() const;
uint64_t to_abgr64() const;
+ String to_html(bool p_alpha = true) const;
float get_h() const;
float get_s() const;
float get_v() const;
- void set_hsv(float p_h, float p_s, float p_v, float p_alpha = 1.0);
+ void set_hsv(float p_h, float p_s, float p_v, float p_alpha = 1.0f);
- inline float &operator[](int p_idx) {
+ _FORCE_INLINE_ float &operator[](int p_idx) {
return components[p_idx];
}
- inline const float &operator[](int p_idx) const {
+ _FORCE_INLINE_ const float &operator[](int p_idx) const {
return components[p_idx];
}
@@ -92,10 +93,15 @@ struct _NO_DISCARD_ Color {
bool is_equal_approx(const Color &p_color) const;
+ Color clamp(const Color &p_min = Color(0, 0, 0, 0), const Color &p_max = Color(1, 1, 1, 1)) const;
void invert();
Color inverted() const;
- inline Color lerp(const Color &p_to, float p_weight) const {
+ _FORCE_INLINE_ float get_luminance() const {
+ return 0.2126f * r + 0.7152f * g + 0.0722f * b;
+ }
+
+ _FORCE_INLINE_ Color lerp(const Color &p_to, float p_weight) const {
Color res = *this;
res.r += (p_weight * (p_to.r - r));
@@ -106,7 +112,7 @@ struct _NO_DISCARD_ Color {
return res;
}
- inline Color darkened(float p_amount) const {
+ _FORCE_INLINE_ Color darkened(float p_amount) const {
Color res = *this;
res.r = res.r * (1.0f - p_amount);
res.g = res.g * (1.0f - p_amount);
@@ -114,7 +120,7 @@ struct _NO_DISCARD_ Color {
return res;
}
- inline Color lightened(float p_amount) const {
+ _FORCE_INLINE_ Color lightened(float p_amount) const {
Color res = *this;
res.r = res.r + (1.0f - res.r) * p_amount;
res.g = res.g + (1.0f - res.g) * p_amount;
@@ -122,26 +128,26 @@ struct _NO_DISCARD_ Color {
return res;
}
- inline uint32_t to_rgbe9995() const {
+ _FORCE_INLINE_ uint32_t to_rgbe9995() const {
const float pow2to9 = 512.0f;
const float B = 15.0f;
const float N = 9.0f;
float sharedexp = 65408.000f; // Result of: ((pow2to9 - 1.0f) / pow2to9) * powf(2.0f, 31.0f - 15.0f)
- float cRed = Math::max(0.0f, Math::min(sharedexp, r));
- float cGreen = Math::max(0.0f, Math::min(sharedexp, g));
- float cBlue = Math::max(0.0f, Math::min(sharedexp, b));
+ float cRed = MAX(0.0f, MIN(sharedexp, r));
+ float cGreen = MAX(0.0f, MIN(sharedexp, g));
+ float cBlue = MAX(0.0f, MIN(sharedexp, b));
- float cMax = Math::max(cRed, Math::max(cGreen, cBlue));
+ float cMax = MAX(cRed, MAX(cGreen, cBlue));
- float expp = Math::max(-B - 1.0f, Math::floor(Math::log(cMax) / (float)Math_LN2)) + 1.0f + B;
+ float expp = MAX(-B - 1.0f, floor(Math::log(cMax) / (real_t)Math_LN2)) + 1.0f + B;
float sMax = (float)floor((cMax / Math::pow(2.0f, expp - B - N)) + 0.5f);
float exps = expp + 1.0f;
- if (0.0 <= sMax && sMax < pow2to9) {
+ if (0.0f <= sMax && sMax < pow2to9) {
exps = expp;
}
@@ -152,9 +158,9 @@ struct _NO_DISCARD_ Color {
return (uint32_t(Math::fast_ftoi(sRed)) & 0x1FF) | ((uint32_t(Math::fast_ftoi(sGreen)) & 0x1FF) << 9) | ((uint32_t(Math::fast_ftoi(sBlue)) & 0x1FF) << 18) | ((uint32_t(Math::fast_ftoi(exps)) & 0x1F) << 27);
}
- inline Color blend(const Color &p_over) const {
+ _FORCE_INLINE_ Color blend(const Color &p_over) const {
Color res;
- float sa = 1.0 - p_over.a;
+ float sa = 1.0f - p_over.a;
res.a = a * sa + p_over.a;
if (res.a == 0) {
return Color(0, 0, 0, 0);
@@ -166,14 +172,14 @@ struct _NO_DISCARD_ Color {
return res;
}
- inline Color srgb_to_linear() const {
+ _FORCE_INLINE_ Color srgb_to_linear() const {
return Color(
- r < 0.04045 ? r * (1.0 / 12.92) : Math::pow((r + 0.055f) * (1.0 / (1.0 + 0.055)), 2.4),
- g < 0.04045 ? g * (1.0 / 12.92) : Math::pow((g + 0.055f) * (1.0 / (1.0 + 0.055)), 2.4),
- b < 0.04045 ? b * (1.0 / 12.92) : Math::pow((b + 0.055f) * (1.0 / (1.0 + 0.055)), 2.4),
+ r < 0.04045f ? r * (1.0f / 12.92f) : Math::pow((r + 0.055f) * (float)(1.0 / (1.0 + 0.055)), 2.4f),
+ g < 0.04045f ? g * (1.0f / 12.92f) : Math::pow((g + 0.055f) * (float)(1.0 / (1.0 + 0.055)), 2.4f),
+ b < 0.04045f ? b * (1.0f / 12.92f) : Math::pow((b + 0.055f) * (float)(1.0 / (1.0 + 0.055)), 2.4f),
a);
}
- inline Color linear_to_srgb() const {
+ _FORCE_INLINE_ Color linear_to_srgb() const {
return Color(
r < 0.0031308f ? 12.92f * r : (1.0f + 0.055f) * Math::pow(r, 1.0f / 2.4f) - 0.055f,
g < 0.0031308f ? 12.92f * g : (1.0f + 0.055f) * Math::pow(g, 1.0f / 2.4f) - 0.055f,
@@ -191,34 +197,33 @@ struct _NO_DISCARD_ Color {
static String get_named_color_name(int p_idx);
static Color get_named_color(int p_idx);
static Color from_string(const String &p_string, const Color &p_default);
- String to_html(bool p_alpha = true) const;
- static Color from_hsv(float p_h, float p_s, float p_v, float p_a);
+ static Color from_hsv(float p_h, float p_s, float p_v, float p_alpha = 1.0f);
static Color from_rgbe9995(uint32_t p_rgbe);
- inline bool operator<(const Color &p_color) const; // used in set keys
+ _FORCE_INLINE_ bool operator<(const Color &p_color) const; // Used in set keys.
operator String() const;
// For the binder.
- inline void set_r8(int32_t r8) { r = (Math::clamp(r8, 0, 255) / 255.0); }
- inline int32_t get_r8() const { return int32_t(Math::clamp(r * 255.0, 0.0, 255.0)); }
- inline void set_g8(int32_t g8) { g = (Math::clamp(g8, 0, 255) / 255.0); }
- inline int32_t get_g8() const { return int32_t(Math::clamp(g * 255.0, 0.0, 255.0)); }
- inline void set_b8(int32_t b8) { b = (Math::clamp(b8, 0, 255) / 255.0); }
- inline int32_t get_b8() const { return int32_t(Math::clamp(b * 255.0, 0.0, 255.0)); }
- inline void set_a8(int32_t a8) { a = (Math::clamp(a8, 0, 255) / 255.0); }
- inline int32_t get_a8() const { return int32_t(Math::clamp(a * 255.0, 0.0, 255.0)); }
+ _FORCE_INLINE_ void set_r8(int32_t r8) { r = (CLAMP(r8, 0, 255) / 255.0f); }
+ _FORCE_INLINE_ int32_t get_r8() const { return int32_t(CLAMP(Math::round(r * 255.0f), 0.0f, 255.0f)); }
+ _FORCE_INLINE_ void set_g8(int32_t g8) { g = (CLAMP(g8, 0, 255) / 255.0f); }
+ _FORCE_INLINE_ int32_t get_g8() const { return int32_t(CLAMP(Math::round(g * 255.0f), 0.0f, 255.0f)); }
+ _FORCE_INLINE_ void set_b8(int32_t b8) { b = (CLAMP(b8, 0, 255) / 255.0f); }
+ _FORCE_INLINE_ int32_t get_b8() const { return int32_t(CLAMP(Math::round(b * 255.0f), 0.0f, 255.0f)); }
+ _FORCE_INLINE_ void set_a8(int32_t a8) { a = (CLAMP(a8, 0, 255) / 255.0f); }
+ _FORCE_INLINE_ int32_t get_a8() const { return int32_t(CLAMP(Math::round(a * 255.0f), 0.0f, 255.0f)); }
- inline void set_h(float p_h) { set_hsv(p_h, get_s(), get_v()); }
- inline void set_s(float p_s) { set_hsv(get_h(), p_s, get_v()); }
- inline void set_v(float p_v) { set_hsv(get_h(), get_s(), p_v); }
+ _FORCE_INLINE_ void set_h(float p_h) { set_hsv(p_h, get_s(), get_v(), a); }
+ _FORCE_INLINE_ void set_s(float p_s) { set_hsv(get_h(), p_s, get_v(), a); }
+ _FORCE_INLINE_ void set_v(float p_v) { set_hsv(get_h(), get_s(), p_v, a); }
- inline Color() {}
+ _FORCE_INLINE_ Color() {}
/**
* RGBA construct parameters.
* Alpha is not optional as otherwise we can't bind the RGB version for scripting.
*/
- inline Color(float p_r, float p_g, float p_b, float p_a) {
+ _FORCE_INLINE_ Color(float p_r, float p_g, float p_b, float p_a) {
r = p_r;
g = p_g;
b = p_b;
@@ -228,17 +233,17 @@ struct _NO_DISCARD_ Color {
/**
* RGB construct parameters.
*/
- inline Color(float p_r, float p_g, float p_b) {
+ _FORCE_INLINE_ Color(float p_r, float p_g, float p_b) {
r = p_r;
g = p_g;
b = p_b;
- a = 1.0;
+ a = 1.0f;
}
/**
* Construct a Color from another Color, but with the specified alpha value.
*/
- inline Color(const Color &p_c, float p_a) {
+ _FORCE_INLINE_ Color(const Color &p_c, float p_a) {
r = p_c.r;
g = p_c.g;
b = p_c.b;
@@ -275,7 +280,7 @@ bool Color::operator<(const Color &p_color) const {
}
}
-inline Color operator*(float p_scalar, const Color &p_color) {
+_FORCE_INLINE_ Color operator*(float p_scalar, const Color &p_color) {
return p_color * p_scalar;
}
diff --git a/include/godot_cpp/variant/plane.hpp b/include/godot_cpp/variant/plane.hpp
index 3a13ed2..8d5f69f 100644
--- a/include/godot_cpp/variant/plane.hpp
+++ b/include/godot_cpp/variant/plane.hpp
@@ -32,29 +32,30 @@
#define GODOT_PLANE_HPP
#include <godot_cpp/classes/global_constants.hpp>
-#include <godot_cpp/core/math.hpp>
#include <godot_cpp/variant/vector3.hpp>
namespace godot {
+class Variant;
+
struct _NO_DISCARD_ Plane {
Vector3 normal;
real_t d = 0;
void set_normal(const Vector3 &p_normal);
- inline Vector3 get_normal() const { return normal; }; /// Point is coplanar, CMP_EPSILON for precision
+ _FORCE_INLINE_ Vector3 get_normal() const { return normal; };
void normalize();
Plane normalized() const;
/* Plane-Point operations */
- inline Vector3 center() const { return normal * d; }
+ _FORCE_INLINE_ Vector3 center() const { return normal * d; }
Vector3 get_any_perpendicular_normal() const;
- inline bool is_point_over(const Vector3 &p_point) const; ///< Point is over plane
- inline real_t distance_to(const Vector3 &p_point) const;
- inline bool has_point(const Vector3 &p_point, real_t _epsilon = CMP_EPSILON) const;
+ _FORCE_INLINE_ bool is_point_over(const Vector3 &p_point) const; ///< Point is over plane
+ _FORCE_INLINE_ real_t distance_to(const Vector3 &p_point) const;
+ _FORCE_INLINE_ bool has_point(const Vector3 &p_point, real_t p_tolerance = CMP_EPSILON) const;
/* intersections */
@@ -62,7 +63,12 @@ struct _NO_DISCARD_ Plane {
bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection) const;
bool intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 *p_intersection) const;
- inline Vector3 project(const Vector3 &p_point) const {
+ // For Variant bindings.
+ Variant intersect_3_bind(const Plane &p_plane1, const Plane &p_plane2) const;
+ Variant intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const;
+ Variant intersects_segment_bind(const Vector3 &p_begin, const Vector3 &p_end) const;
+
+ _FORCE_INLINE_ Vector3 project(const Vector3 &p_point) const {
return p_point - normal * distance_to(p_point);
}
@@ -72,18 +78,18 @@ struct _NO_DISCARD_ Plane {
bool is_equal_approx(const Plane &p_plane) const;
bool is_equal_approx_any_side(const Plane &p_plane) const;
- inline bool operator==(const Plane &p_plane) const;
- inline bool operator!=(const Plane &p_plane) const;
+ _FORCE_INLINE_ bool operator==(const Plane &p_plane) const;
+ _FORCE_INLINE_ bool operator!=(const Plane &p_plane) const;
operator String() const;
- inline Plane() {}
- inline Plane(real_t p_a, real_t p_b, real_t p_c, real_t p_d) :
+ _FORCE_INLINE_ Plane() {}
+ _FORCE_INLINE_ Plane(real_t p_a, real_t p_b, real_t p_c, real_t p_d) :
normal(p_a, p_b, p_c),
d(p_d) {}
- inline Plane(const Vector3 &p_normal, real_t p_d);
- inline Plane(const Vector3 &p_point, const Vector3 &p_normal);
- inline Plane(const Vector3 &p_point1, const Vector3 &p_point2, const Vector3 &p_point3, ClockDirection p_dir = CLOCKWISE);
+ _FORCE_INLINE_ Plane(const Vector3 &p_normal, real_t p_d = 0.0);
+ _FORCE_INLINE_ Plane(const Vector3 &p_normal, const Vector3 &p_point);
+ _FORCE_INLINE_ Plane(const Vector3 &p_point1, const Vector3 &p_point2, const Vector3 &p_point3, ClockDirection p_dir = CLOCKWISE);
};
bool Plane::is_point_over(const Vector3 &p_point) const {
@@ -94,10 +100,10 @@ real_t Plane::distance_to(const Vector3 &p_point) const {
return (normal.dot(p_point) - d);
}
-bool Plane::has_point(const Vector3 &p_point, real_t _epsilon) const {
+bool Plane::has_point(const Vector3 &p_point, real_t p_tolerance) const {
real_t dist = normal.dot(p_point) - d;
dist = Math::abs(dist);
- return (dist <= _epsilon);
+ return (dist <= p_tolerance);
}
Plane::Plane(const Vector3 &p_normal, real_t p_d) :
@@ -105,7 +111,7 @@ Plane::Plane(const Vector3 &p_normal, real_t p_d) :
d(p_d) {
}
-Plane::Plane(const Vector3 &p_point, const Vector3 &p_normal) :
+Plane::Plane(const Vector3 &p_normal, const Vector3 &p_point) :
normal(p_normal),
d(p_normal.dot(p_point)) {
}
@@ -128,6 +134,7 @@ bool Plane::operator==(const Plane &p_plane) const {
bool Plane::operator!=(const Plane &p_plane) const {
return normal != p_plane.normal || d != p_plane.d;
}
+
} // namespace godot
#endif // GODOT_PLANE_HPP
diff --git a/include/godot_cpp/variant/projection.hpp b/include/godot_cpp/variant/projection.hpp
index 5472490..6510cb0 100644
--- a/include/godot_cpp/variant/projection.hpp
+++ b/include/godot_cpp/variant/projection.hpp
@@ -32,13 +32,12 @@
#define GODOT_PROJECTION_HPP
#include <godot_cpp/core/math.hpp>
-
-#include <godot_cpp/variant/array.hpp>
#include <godot_cpp/variant/vector3.hpp>
#include <godot_cpp/variant/vector4.hpp>
namespace godot {
+class Array;
struct AABB;
struct Plane;
struct Rect2;
@@ -55,14 +54,16 @@ struct _NO_DISCARD_ Projection {
PLANE_BOTTOM
};
- Vector4 matrix[4];
+ Vector4 columns[4];
_FORCE_INLINE_ const Vector4 &operator[](const int p_axis) const {
- return matrix[p_axis];
+ DEV_ASSERT((unsigned int)p_axis < 4);
+ return columns[p_axis];
}
_FORCE_INLINE_ Vector4 &operator[](const int p_axis) {
- return matrix[p_axis];
+ DEV_ASSERT((unsigned int)p_axis < 4);
+ return columns[p_axis];
}
float determinant() const;
@@ -97,7 +98,7 @@ struct _NO_DISCARD_ Projection {
Projection jitter_offseted(const Vector2 &p_offset) const;
static real_t get_fovy(real_t p_fovx, real_t p_aspect) {
- return Math::rad2deg(Math::atan(p_aspect * Math::tan(Math::deg2rad(p_fovx) * 0.5)) * 2.0);
+ return Math::rad_to_deg(Math::atan(p_aspect * Math::tan(Math::deg_to_rad(p_fovx) * 0.5)) * 2.0);
}
real_t get_z_far() const;
@@ -107,8 +108,8 @@ struct _NO_DISCARD_ Projection {
bool is_orthogonal() const;
Array get_projection_planes(const Transform3D &p_transform) const;
- bool get_endpoints(const Transform3D &p_transform, Vector3 *p_8points) const;
+ bool get_endpoints(const Transform3D &p_transform, Vector3 *p_8points) const;
Vector2 get_viewport_half_extents() const;
Vector2 get_far_plane_half_extents() const;
@@ -136,7 +137,7 @@ struct _NO_DISCARD_ Projection {
bool operator==(const Projection &p_cam) const {
for (uint32_t i = 0; i < 4; i++) {
for (uint32_t j = 0; j < 4; j++) {
- if (matrix[i][j] != p_cam.matrix[i][j]) {
+ if (columns[i][j] != p_cam.columns[i][j]) {
return false;
}
}
@@ -158,10 +159,10 @@ struct _NO_DISCARD_ Projection {
Vector3 Projection::xform(const Vector3 &p_vec3) const {
Vector3 ret;
- ret.x = matrix[0][0] * p_vec3.x + matrix[1][0] * p_vec3.y + matrix[2][0] * p_vec3.z + matrix[3][0];
- ret.y = matrix[0][1] * p_vec3.x + matrix[1][1] * p_vec3.y + matrix[2][1] * p_vec3.z + matrix[3][1];
- ret.z = matrix[0][2] * p_vec3.x + matrix[1][2] * p_vec3.y + matrix[2][2] * p_vec3.z + matrix[3][2];
- real_t w = matrix[0][3] * p_vec3.x + matrix[1][3] * p_vec3.y + matrix[2][3] * p_vec3.z + matrix[3][3];
+ ret.x = columns[0][0] * p_vec3.x + columns[1][0] * p_vec3.y + columns[2][0] * p_vec3.z + columns[3][0];
+ ret.y = columns[0][1] * p_vec3.x + columns[1][1] * p_vec3.y + columns[2][1] * p_vec3.z + columns[3][1];
+ ret.z = columns[0][2] * p_vec3.x + columns[1][2] * p_vec3.y + columns[2][2] * p_vec3.z + columns[3][2];
+ real_t w = columns[0][3] * p_vec3.x + columns[1][3] * p_vec3.y + columns[2][3] * p_vec3.z + columns[3][3];
return ret / w;
}
diff --git a/include/godot_cpp/variant/quaternion.hpp b/include/godot_cpp/variant/quaternion.hpp
index e84202d..dd60561 100644
--- a/include/godot_cpp/variant/quaternion.hpp
+++ b/include/godot_cpp/variant/quaternion.hpp
@@ -143,8 +143,7 @@ struct _NO_DISCARD_ Quaternion {
w = p_q.w;
}
- Quaternion(const Vector3 &v0, const Vector3 &v1) // shortest arc
- {
+ Quaternion(const Vector3 &v0, const Vector3 &v1) { // Shortest arc.
Vector3 c = v0.cross(v1);
real_t d = v0.dot(v1);
diff --git a/include/godot_cpp/variant/rect2.hpp b/include/godot_cpp/variant/rect2.hpp
index 6be075d..d6b8bd3 100644
--- a/include/godot_cpp/variant/rect2.hpp
+++ b/include/godot_cpp/variant/rect2.hpp
@@ -32,7 +32,6 @@
#define GODOT_RECT2_HPP
#include <godot_cpp/classes/global_constants.hpp>
-#include <godot_cpp/core/math.hpp>
#include <godot_cpp/variant/vector2.hpp>
namespace godot {
@@ -52,7 +51,14 @@ struct _NO_DISCARD_ Rect2 {
real_t get_area() const { return size.width * size.height; }
+ _FORCE_INLINE_ Vector2 get_center() const { return position + (size * 0.5f); }
+
inline bool intersects(const Rect2 &p_rect, const bool p_include_borders = false) const {
+#ifdef MATH_CHECKS
+ if (unlikely(size.x < 0 || size.y < 0 || p_rect.size.x < 0 || p_rect.size.y < 0)) {
+ ERR_PRINT("Rect2 size is negative, this is not supported. Use Rect2.abs() to get a Rect2 with a positive size.");
+ }
+#endif
if (p_include_borders) {
if (position.x > (p_rect.position.x + p_rect.size.width)) {
return false;
@@ -85,6 +91,11 @@ struct _NO_DISCARD_ Rect2 {
}
inline real_t distance_to(const Vector2 &p_point) const {
+#ifdef MATH_CHECKS
+ if (unlikely(size.x < 0 || size.y < 0)) {
+ ERR_PRINT("Rect2 size is negative, this is not supported. Use Rect2.abs() to get a Rect2 with a positive size.");
+ }
+#endif
real_t dist = 0.0;
bool inside = true;
@@ -121,13 +132,18 @@ struct _NO_DISCARD_ Rect2 {
bool intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_pos = nullptr, Point2 *r_normal = nullptr) const;
inline bool encloses(const Rect2 &p_rect) const {
+#ifdef MATH_CHECKS
+ if (unlikely(size.x < 0 || size.y < 0 || p_rect.size.x < 0 || p_rect.size.y < 0)) {
+ ERR_PRINT("Rect2 size is negative, this is not supported. Use Rect2.abs() to get a Rect2 with a positive size.");
+ }
+#endif
return (p_rect.position.x >= position.x) && (p_rect.position.y >= position.y) &&
- ((p_rect.position.x + p_rect.size.x) <= (position.x + size.x)) &&
- ((p_rect.position.y + p_rect.size.y) <= (position.y + size.y));
+ ((p_rect.position.x + p_rect.size.x) <= (position.x + size.x)) &&
+ ((p_rect.position.y + p_rect.size.y) <= (position.y + size.y));
}
- inline bool has_no_area() const {
- return (size.x <= 0 || size.y <= 0);
+ _FORCE_INLINE_ bool has_area() const {
+ return size.x > 0.0f && size.y > 0.0f;
}
// Returns the instersection between two Rect2s or an empty Rect2 if there is no intersection
@@ -151,7 +167,11 @@ struct _NO_DISCARD_ Rect2 {
}
inline Rect2 merge(const Rect2 &p_rect) const { ///< return a merged rect
-
+#ifdef MATH_CHECKS
+ if (unlikely(size.x < 0 || size.y < 0 || p_rect.size.x < 0 || p_rect.size.y < 0)) {
+ ERR_PRINT("Rect2 size is negative, this is not supported. Use Rect2.abs() to get a Rect2 with a positive size.");
+ }
+#endif
Rect2 new_rect;
new_rect.position.x = Math::min(p_rect.position.x, position.x);
@@ -160,11 +180,17 @@ struct _NO_DISCARD_ Rect2 {
new_rect.size.x = Math::max(p_rect.position.x + p_rect.size.x, position.x + size.x);
new_rect.size.y = Math::max(p_rect.position.y + p_rect.size.y, position.y + size.y);
- new_rect.size = new_rect.size - new_rect.position; // make relative again
+ new_rect.size = new_rect.size - new_rect.position; // Make relative again.
return new_rect;
}
+
inline bool has_point(const Point2 &p_point) const {
+#ifdef MATH_CHECKS
+ if (unlikely(size.x < 0 || size.y < 0)) {
+ ERR_PRINT("Rect2 size is negative, this is not supported. Use Rect2.abs() to get a Rect2 with a positive size.");
+ }
+#endif
if (p_point.x < position.x) {
return false;
}
@@ -181,6 +207,7 @@ struct _NO_DISCARD_ Rect2 {
return true;
}
+
bool is_equal_approx(const Rect2 &p_rect) const;
bool operator==(const Rect2 &p_rect) const { return position == p_rect.position && size == p_rect.size; }
@@ -188,13 +215,17 @@ struct _NO_DISCARD_ Rect2 {
inline Rect2 grow(real_t p_amount) const {
Rect2 g = *this;
- g.position.x -= p_amount;
- g.position.y -= p_amount;
- g.size.width += p_amount * 2;
- g.size.height += p_amount * 2;
+ g.grow_by(p_amount);
return g;
}
+ inline void grow_by(real_t p_amount) {
+ position.x -= p_amount;
+ position.y -= p_amount;
+ size.width += p_amount * 2;
+ size.height += p_amount * 2;
+ }
+
inline Rect2 grow_side(Side p_side, real_t p_amount) const {
Rect2 g = *this;
g = g.grow_individual((SIDE_LEFT == p_side) ? p_amount : 0,
@@ -218,14 +249,18 @@ struct _NO_DISCARD_ Rect2 {
return g;
}
- inline Rect2 expand(const Vector2 &p_vector) const {
+ _FORCE_INLINE_ Rect2 expand(const Vector2 &p_vector) const {
Rect2 r = *this;
r.expand_to(p_vector);
return r;
}
- inline void expand_to(const Vector2 &p_vector) { // in place function for speed
-
+ inline void expand_to(const Vector2 &p_vector) { // In place function for speed.
+#ifdef MATH_CHECKS
+ if (unlikely(size.x < 0 || size.y < 0)) {
+ ERR_PRINT("Rect2 size is negative, this is not supported. Use Rect2.abs() to get a Rect2 with a positive size.");
+ }
+#endif
Vector2 begin = position;
Vector2 end = position + size;
@@ -247,21 +282,21 @@ struct _NO_DISCARD_ Rect2 {
size = end - begin;
}
- inline Rect2 abs() const {
+ _FORCE_INLINE_ Rect2 abs() const {
return Rect2(Point2(position.x + Math::min(size.x, (real_t)0), position.y + Math::min(size.y, (real_t)0)), size.abs());
}
Vector2 get_support(const Vector2 &p_normal) const {
- Vector2 half_extents = size * 0.5;
+ Vector2 half_extents = size * 0.5f;
Vector2 ofs = position + half_extents;
return Vector2(
(p_normal.x > 0) ? -half_extents.x : half_extents.x,
(p_normal.y > 0) ? -half_extents.y : half_extents.y) +
- ofs;
+ ofs;
}
- inline bool intersects_filled_polygon(const Vector2 *p_points, int p_point_count) const {
- Vector2 center = position + size * 0.5;
+ _FORCE_INLINE_ bool intersects_filled_polygon(const Vector2 *p_points, int p_point_count) const {
+ Vector2 center = get_center();
int side_plus = 0;
int side_minus = 0;
Vector2 end = position + size;
@@ -274,22 +309,22 @@ struct _NO_DISCARD_ Rect2 {
Vector2 r = (b - a);
float l = r.length();
- if (l == 0.0) {
+ if (l == 0.0f) {
continue;
}
- // check inside
+ // Check inside.
Vector2 tg = r.orthogonal();
float s = tg.dot(center) - tg.dot(a);
- if (s < 0.0) {
+ if (s < 0.0f) {
side_plus++;
} else {
side_minus++;
}
- // check ray box
+ // Check ray box.
r /= l;
- Vector2 ir((real_t)1.0 / r.x, (real_t)1.0 / r.y);
+ Vector2 ir(1.0f / r.x, 1.0f / r.y);
// lb is the corner of AABB with minimal coordinates - left bottom, rt is maximal corner
// r.org is origin of ray
@@ -308,17 +343,17 @@ struct _NO_DISCARD_ Rect2 {
}
if (side_plus * side_minus == 0) {
- return true; // all inside
+ return true; // All inside.
} else {
return false;
}
}
- inline void set_end(const Vector2 &p_end) {
+ _FORCE_INLINE_ void set_end(const Vector2 &p_end) {
size = p_end - position;
}
- inline Vector2 get_end() const {
+ _FORCE_INLINE_ Vector2 get_end() const {
return position + size;
}
diff --git a/include/godot_cpp/variant/rect2i.hpp b/include/godot_cpp/variant/rect2i.hpp
index 30c7d2d..3bf104e 100644
--- a/include/godot_cpp/variant/rect2i.hpp
+++ b/include/godot_cpp/variant/rect2i.hpp
@@ -32,7 +32,6 @@
#define GODOT_RECT2I_HPP
#include <godot_cpp/classes/global_constants.hpp>
-#include <godot_cpp/core/math.hpp>
#include <godot_cpp/variant/vector2i.hpp>
namespace godot {
@@ -51,17 +50,24 @@ struct _NO_DISCARD_ Rect2i {
int get_area() const { return size.width * size.height; }
+ _FORCE_INLINE_ Vector2i get_center() const { return position + (size / 2); }
+
inline bool intersects(const Rect2i &p_rect) const {
- if (position.x > (p_rect.position.x + p_rect.size.width)) {
+#ifdef MATH_CHECKS
+ if (unlikely(size.x < 0 || size.y < 0 || p_rect.size.x < 0 || p_rect.size.y < 0)) {
+ ERR_PRINT("Rect2i size is negative, this is not supported. Use Rect2i.abs() to get a Rect2i with a positive size.");
+ }
+#endif
+ if (position.x >= (p_rect.position.x + p_rect.size.width)) {
return false;
}
- if ((position.x + size.width) < p_rect.position.x) {
+ if ((position.x + size.width) <= p_rect.position.x) {
return false;
}
- if (position.y > (p_rect.position.y + p_rect.size.height)) {
+ if (position.y >= (p_rect.position.y + p_rect.size.height)) {
return false;
}
- if ((position.y + size.height) < p_rect.position.y) {
+ if ((position.y + size.height) <= p_rect.position.y) {
return false;
}
@@ -69,13 +75,18 @@ struct _NO_DISCARD_ Rect2i {
}
inline bool encloses(const Rect2i &p_rect) const {
+#ifdef MATH_CHECKS
+ if (unlikely(size.x < 0 || size.y < 0 || p_rect.size.x < 0 || p_rect.size.y < 0)) {
+ ERR_PRINT("Rect2i size is negative, this is not supported. Use Rect2i.abs() to get a Rect2i with a positive size.");
+ }
+#endif
return (p_rect.position.x >= position.x) && (p_rect.position.y >= position.y) &&
- ((p_rect.position.x + p_rect.size.x) < (position.x + size.x)) &&
- ((p_rect.position.y + p_rect.size.y) < (position.y + size.y));
+ ((p_rect.position.x + p_rect.size.x) <= (position.x + size.x)) &&
+ ((p_rect.position.y + p_rect.size.y) <= (position.y + size.y));
}
- inline bool has_no_area() const {
- return (size.x <= 0 || size.y <= 0);
+ _FORCE_INLINE_ bool has_area() const {
+ return size.x > 0 && size.y > 0;
}
// Returns the instersection between two Rect2is or an empty Rect2i if there is no intersection
@@ -92,14 +103,18 @@ struct _NO_DISCARD_ Rect2i {
Point2i p_rect_end = p_rect.position + p_rect.size;
Point2i end = position + size;
- new_rect.size.x = (int)(Math::min(p_rect_end.x, end.x) - new_rect.position.x);
- new_rect.size.y = (int)(Math::min(p_rect_end.y, end.y) - new_rect.position.y);
+ new_rect.size.x = Math::min(p_rect_end.x, end.x) - new_rect.position.x;
+ new_rect.size.y = Math::min(p_rect_end.y, end.y) - new_rect.position.y;
return new_rect;
}
inline Rect2i merge(const Rect2i &p_rect) const { ///< return a merged rect
-
+#ifdef MATH_CHECKS
+ if (unlikely(size.x < 0 || size.y < 0 || p_rect.size.x < 0 || p_rect.size.y < 0)) {
+ ERR_PRINT("Rect2i size is negative, this is not supported. Use Rect2i.abs() to get a Rect2i with a positive size.");
+ }
+#endif
Rect2i new_rect;
new_rect.position.x = Math::min(p_rect.position.x, position.x);
@@ -108,11 +123,16 @@ struct _NO_DISCARD_ Rect2i {
new_rect.size.x = Math::max(p_rect.position.x + p_rect.size.x, position.x + size.x);
new_rect.size.y = Math::max(p_rect.position.y + p_rect.size.y, position.y + size.y);
- new_rect.size = new_rect.size - new_rect.position; // make relative again
+ new_rect.size = new_rect.size - new_rect.position; // Make relative again.
return new_rect;
}
bool has_point(const Point2i &p_point) const {
+#ifdef MATH_CHECKS
+ if (unlikely(size.x < 0 || size.y < 0)) {
+ ERR_PRINT("Rect2i size is negative, this is not supported. Use Rect2i.abs() to get a Rect2i with a positive size.");
+ }
+#endif
if (p_point.x < position.x) {
return false;
}
@@ -165,13 +185,18 @@ struct _NO_DISCARD_ Rect2i {
return g;
}
- inline Rect2i expand(const Vector2i &p_vector) const {
+ _FORCE_INLINE_ Rect2i expand(const Vector2i &p_vector) const {
Rect2i r = *this;
r.expand_to(p_vector);
return r;
}
inline void expand_to(const Point2i &p_vector) {
+#ifdef MATH_CHECKS
+ if (unlikely(size.x < 0 || size.y < 0)) {
+ ERR_PRINT("Rect2i size is negative, this is not supported. Use Rect2i.abs() to get a Rect2i with a positive size.");
+ }
+#endif
Point2i begin = position;
Point2i end = position + size;
@@ -193,15 +218,15 @@ struct _NO_DISCARD_ Rect2i {
size = end - begin;
}
- inline Rect2i abs() const {
+ _FORCE_INLINE_ Rect2i abs() const {
return Rect2i(Point2i(position.x + Math::min(size.x, 0), position.y + Math::min(size.y, 0)), size.abs());
}
- inline void set_end(const Vector2i &p_end) {
+ _FORCE_INLINE_ void set_end(const Vector2i &p_end) {
size = p_end - position;
}
- inline Vector2i get_end() const {
+ _FORCE_INLINE_ Vector2i get_end() const {
return position + size;
}
diff --git a/include/godot_cpp/variant/transform2d.hpp b/include/godot_cpp/variant/transform2d.hpp
index dd0c409..e4d6eb7 100644
--- a/include/godot_cpp/variant/transform2d.hpp
+++ b/include/godot_cpp/variant/transform2d.hpp
@@ -31,14 +31,14 @@
#ifndef GODOT_TRANSFORM2D_HPP
#define GODOT_TRANSFORM2D_HPP
-#include <godot_cpp/core/error_macros.hpp>
-#include <godot_cpp/core/math.hpp>
#include <godot_cpp/variant/packed_vector2_array.hpp>
#include <godot_cpp/variant/rect2.hpp>
#include <godot_cpp/variant/vector2.hpp>
namespace godot {
+class String;
+
struct _NO_DISCARD_ Transform2D {
// Warning #1: basis of Transform2D is stored differently from Basis. In terms of columns array, the basis matrix looks like "on paper":
// M = (columns[0][0] columns[1][0])
@@ -53,52 +53,46 @@ struct _NO_DISCARD_ Transform2D {
Vector2 columns[3];
- inline real_t tdotx(const Vector2 &v) const { return columns[0][0] * v.x + columns[1][0] * v.y; }
- inline real_t tdoty(const Vector2 &v) const { return columns[0][1] * v.x + columns[1][1] * v.y; }
+ _FORCE_INLINE_ real_t tdotx(const Vector2 &v) const { return columns[0][0] * v.x + columns[1][0] * v.y; }
+ _FORCE_INLINE_ real_t tdoty(const Vector2 &v) const { return columns[0][1] * v.x + columns[1][1] * v.y; }
const Vector2 &operator[](int p_idx) const { return columns[p_idx]; }
Vector2 &operator[](int p_idx) { return columns[p_idx]; }
- inline Vector2 get_axis(int p_axis) const {
- ERR_FAIL_INDEX_V(p_axis, 3, Vector2());
- return columns[p_axis];
- }
- inline void set_axis(int p_axis, const Vector2 &p_vec) {
- ERR_FAIL_INDEX(p_axis, 3);
- columns[p_axis] = p_vec;
- }
-
void invert();
Transform2D inverse() const;
void affine_invert();
Transform2D affine_inverse() const;
- void set_rotation(real_t p_rot);
+ void set_rotation(const real_t p_rot);
real_t get_rotation() const;
real_t get_skew() const;
- void set_skew(float p_angle);
- inline void set_rotation_and_scale(real_t p_rot, const Size2 &p_scale);
- inline void set_rotation_scale_and_skew(real_t p_rot, const Size2 &p_scale, float p_skew);
- void rotate(real_t p_phi);
+ void set_skew(const real_t p_angle);
+ _FORCE_INLINE_ void set_rotation_and_scale(const real_t p_rot, const Size2 &p_scale);
+ _FORCE_INLINE_ void set_rotation_scale_and_skew(const real_t p_rot, const Size2 &p_scale, const real_t p_skew);
+ void rotate(const real_t p_angle);
void scale(const Size2 &p_scale);
void scale_basis(const Size2 &p_scale);
- void translate(real_t p_tx, real_t p_ty);
- void translate(const Vector2 &p_translation);
+ void translate_local(const real_t p_tx, const real_t p_ty);
+ void translate_local(const Vector2 &p_translation);
real_t basis_determinant() const;
Size2 get_scale() const;
void set_scale(const Size2 &p_scale);
- inline const Vector2 &get_origin() const { return columns[2]; }
- inline void set_origin(const Vector2 &p_origin) { columns[2] = p_origin; }
+ _FORCE_INLINE_ const Vector2 &get_origin() const { return columns[2]; }
+ _FORCE_INLINE_ void set_origin(const Vector2 &p_origin) { columns[2] = p_origin; }
- Transform2D scaled(const Size2 &p_scale) const;
Transform2D basis_scaled(const Size2 &p_scale) const;
+ Transform2D scaled(const Size2 &p_scale) const;
+ Transform2D scaled_local(const Size2 &p_scale) const;
Transform2D translated(const Vector2 &p_offset) const;
- Transform2D rotated(real_t p_phi) const;
+ Transform2D translated_local(const Vector2 &p_offset) const;
+ Transform2D rotated(const real_t p_angle) const;
+ Transform2D rotated_local(const real_t p_angle) const;
Transform2D untranslated() const;
@@ -106,26 +100,30 @@ struct _NO_DISCARD_ Transform2D {
Transform2D orthonormalized() const;
bool is_equal_approx(const Transform2D &p_transform) const;
+ Transform2D looking_at(const Vector2 &p_target) const;
+
bool operator==(const Transform2D &p_transform) const;
bool operator!=(const Transform2D &p_transform) const;
void operator*=(const Transform2D &p_transform);
Transform2D operator*(const Transform2D &p_transform) const;
+ void operator*=(const real_t p_val);
+ Transform2D operator*(const real_t p_val) const;
- Transform2D interpolate_with(const Transform2D &p_transform, real_t p_c) const;
+ Transform2D interpolate_with(const Transform2D &p_transform, const real_t p_c) const;
- inline Vector2 basis_xform(const Vector2 &p_vec) const;
- inline Vector2 basis_xform_inv(const Vector2 &p_vec) const;
- inline Vector2 xform(const Vector2 &p_vec) const;
- inline Vector2 xform_inv(const Vector2 &p_vec) const;
- inline Rect2 xform(const Rect2 &p_rect) const;
- inline Rect2 xform_inv(const Rect2 &p_rect) const;
- inline PackedVector2Array xform(const PackedVector2Array &p_array) const;
- inline PackedVector2Array xform_inv(const PackedVector2Array &p_array) const;
+ _FORCE_INLINE_ Vector2 basis_xform(const Vector2 &p_vec) const;
+ _FORCE_INLINE_ Vector2 basis_xform_inv(const Vector2 &p_vec) const;
+ _FORCE_INLINE_ Vector2 xform(const Vector2 &p_vec) const;
+ _FORCE_INLINE_ Vector2 xform_inv(const Vector2 &p_vec) const;
+ _FORCE_INLINE_ Rect2 xform(const Rect2 &p_rect) const;
+ _FORCE_INLINE_ Rect2 xform_inv(const Rect2 &p_rect) const;
+ _FORCE_INLINE_ PackedVector2Array xform(const PackedVector2Array &p_array) const;
+ _FORCE_INLINE_ PackedVector2Array xform_inv(const PackedVector2Array &p_array) const;
operator String() const;
- Transform2D(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox, real_t oy) {
+ Transform2D(const real_t xx, const real_t xy, const real_t yx, const real_t yy, const real_t ox, const real_t oy) {
columns[0][0] = xx;
columns[0][1] = xy;
columns[1][0] = yx;
@@ -140,7 +138,10 @@ struct _NO_DISCARD_ Transform2D {
columns[2] = p_origin;
}
- Transform2D(real_t p_rot, const Vector2 &p_pos);
+ Transform2D(const real_t p_rot, const Vector2 &p_pos);
+
+ Transform2D(const real_t p_rot, const Size2 &p_scale, const real_t p_skew, const Vector2 &p_pos);
+
Transform2D() {
columns[0][0] = 1.0;
columns[1][1] = 1.0;
@@ -163,7 +164,7 @@ Vector2 Transform2D::xform(const Vector2 &p_vec) const {
return Vector2(
tdotx(p_vec),
tdoty(p_vec)) +
- columns[2];
+ columns[2];
}
Vector2 Transform2D::xform_inv(const Vector2 &p_vec) const {
@@ -187,14 +188,14 @@ Rect2 Transform2D::xform(const Rect2 &p_rect) const {
return new_rect;
}
-void Transform2D::set_rotation_and_scale(real_t p_rot, const Size2 &p_scale) {
+void Transform2D::set_rotation_and_scale(const real_t p_rot, const Size2 &p_scale) {
columns[0][0] = Math::cos(p_rot) * p_scale.x;
columns[1][1] = Math::cos(p_rot) * p_scale.y;
columns[1][0] = -Math::sin(p_rot) * p_scale.y;
columns[0][1] = Math::sin(p_rot) * p_scale.x;
}
-void Transform2D::set_rotation_scale_and_skew(real_t p_rot, const Size2 &p_scale, float p_skew) {
+void Transform2D::set_rotation_scale_and_skew(const real_t p_rot, const Size2 &p_scale, const real_t p_skew) {
columns[0][0] = Math::cos(p_rot) * p_scale.x;
columns[1][1] = Math::cos(p_rot + p_skew) * p_scale.y;
columns[1][0] = -Math::sin(p_rot + p_skew) * p_scale.y;
@@ -222,8 +223,11 @@ PackedVector2Array Transform2D::xform(const PackedVector2Array &p_array) const {
PackedVector2Array array;
array.resize(p_array.size());
+ const Vector2 *r = p_array.ptr();
+ Vector2 *w = array.ptrw();
+
for (int i = 0; i < p_array.size(); ++i) {
- array[i] = xform(p_array[i]);
+ w[i] = xform(r[i]);
}
return array;
}
@@ -232,8 +236,11 @@ PackedVector2Array Transform2D::xform_inv(const PackedVector2Array &p_array) con
PackedVector2Array array;
array.resize(p_array.size());
+ const Vector2 *r = p_array.ptr();
+ Vector2 *w = array.ptrw();
+
for (int i = 0; i < p_array.size(); ++i) {
- array[i] = xform_inv(p_array[i]);
+ w[i] = xform_inv(r[i]);
}
return array;
}
diff --git a/include/godot_cpp/variant/vector4i.hpp b/include/godot_cpp/variant/vector4i.hpp
index 773198b..4078219 100644
--- a/include/godot_cpp/variant/vector4i.hpp
+++ b/include/godot_cpp/variant/vector4i.hpp
@@ -70,9 +70,6 @@ struct _NO_DISCARD_ Vector4i {
return coord[p_axis];
}
- void set_axis(const int p_axis, const int32_t p_value);
- int32_t get_axis(const int p_axis) const;
-
Vector4i::Axis min_axis_index() const;
Vector4i::Axis max_axis_index() const;