diff --git a/core/math/bvh_split.inc b/core/math/bvh_split.inc index 6f54d06ce78b..f19ee8a7daab 100644 --- a/core/math/bvh_split.inc +++ b/core/math/bvh_split.inc @@ -30,8 +30,8 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u int order[Point::AXIS_COUNT]; - order[0] = size.min_axis(); - order[Point::AXIS_COUNT - 1] = size.max_axis(); + order[0] = size.min_axis_index(); + order[Point::AXIS_COUNT - 1] = size.max_axis_index(); static_assert(Point::AXIS_COUNT <= 3); if (Point::AXIS_COUNT == 3) { diff --git a/core/math/convex_hull.cpp b/core/math/convex_hull.cpp index 2956e0cf09c5..6f551319dfd0 100644 --- a/core/math/convex_hull.cpp +++ b/core/math/convex_hull.cpp @@ -606,9 +606,9 @@ class ConvexHullInternal { PagedAllocator face_pool; LocalVector original_vertices; int32_t merge_stamp = 0; - int32_t min_axis = 0; - int32_t med_axis = 0; - int32_t max_axis = 0; + Vector3::Axis min_axis = Vector3::Axis::AXIS_X; + Vector3::Axis med_axis = Vector3::Axis::AXIS_X; + Vector3::Axis max_axis = Vector3::Axis::AXIS_X; int32_t used_edge_pairs = 0; int32_t max_used_edge_pairs = 0; @@ -1585,12 +1585,12 @@ void ConvexHullInternal::compute(const Vector3 *p_coords, int32_t p_count) { } Vector3 s = aabb.size; - max_axis = s.max_axis(); - min_axis = s.min_axis(); + max_axis = s.max_axis_index(); + min_axis = s.min_axis_index(); if (min_axis == max_axis) { - min_axis = (max_axis + 1) % 3; + min_axis = Vector3::Axis((max_axis + 1) % 3); } - med_axis = 3 - max_axis - min_axis; + med_axis = Vector3::Axis(3 - max_axis - min_axis); s /= real_t(10216); if (((med_axis + 1) % 3) != max_axis) { diff --git a/core/math/vector2.h b/core/math/vector2.h index 0a7b9d3faf09..c0a189e040fc 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -70,12 +70,12 @@ struct Vector2 { x = y = p_value; } - _FORCE_INLINE_ int min_axis() const { - return x < y ? 0 : 1; + _FORCE_INLINE_ Vector2::Axis min_axis_index() const { + return x < y ? Vector2::AXIS_X : Vector2::AXIS_Y; } - _FORCE_INLINE_ int max_axis() const { - return x < y ? 1 : 0; + _FORCE_INLINE_ Vector2::Axis max_axis_index() const { + return x < y ? Vector2::AXIS_Y : Vector2::AXIS_X; } void normalize(); @@ -301,12 +301,12 @@ struct Vector2i { return p_idx ? y : x; } - _FORCE_INLINE_ int min_axis() const { - return x < y ? 0 : 1; + _FORCE_INLINE_ Vector2i::Axis min_axis_index() const { + return x < y ? Vector2i::AXIS_X : Vector2i::AXIS_Y; } - _FORCE_INLINE_ int max_axis() const { - return x < y ? 1 : 0; + _FORCE_INLINE_ Vector2i::Axis max_axis_index() const { + return x < y ? Vector2i::AXIS_Y : Vector2i::AXIS_X; } Vector2i min(const Vector2i &p_vector2i) const { diff --git a/core/math/vector3.h b/core/math/vector3.h index 6c21968aae17..c0f80e8f1134 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -71,12 +71,12 @@ struct Vector3 { x = y = z = p_value; } - _FORCE_INLINE_ int min_axis() const { - return x < y ? (x < z ? 0 : 2) : (y < z ? 1 : 2); + _FORCE_INLINE_ Vector3::Axis min_axis_index() const { + return x < y ? (x < z ? Vector3::AXIS_X : Vector3::AXIS_Z) : (y < z ? Vector3::AXIS_Y : Vector3::AXIS_Z); } - _FORCE_INLINE_ int max_axis() const { - return x < y ? (y < z ? 2 : 1) : (x < z ? 2 : 0); + _FORCE_INLINE_ Vector3::Axis max_axis_index() const { + return x < y ? (y < z ? Vector3::AXIS_Z : Vector3::AXIS_Y) : (x < z ? Vector3::AXIS_Z : Vector3::AXIS_X); } _FORCE_INLINE_ real_t length() const; diff --git a/core/math/vector3i.cpp b/core/math/vector3i.cpp index d3a57af77c13..7812a0b41c2f 100644 --- a/core/math/vector3i.cpp +++ b/core/math/vector3i.cpp @@ -40,12 +40,12 @@ int32_t Vector3i::get_axis(const int p_axis) const { return operator[](p_axis); } -int Vector3i::min_axis() const { - return x < y ? (x < z ? 0 : 2) : (y < z ? 1 : 2); +Vector3i::Axis Vector3i::min_axis_index() const { + return x < y ? (x < z ? Vector3i::AXIS_X : Vector3i::AXIS_Z) : (y < z ? Vector3i::AXIS_Y : Vector3i::AXIS_Z); } -int Vector3i::max_axis() const { - return x < y ? (y < z ? 2 : 1) : (x < z ? 2 : 0); +Vector3i::Axis Vector3i::max_axis_index() const { + return x < y ? (y < z ? Vector3i::AXIS_Z : Vector3i::AXIS_Y) : (x < z ? Vector3i::AXIS_Z : Vector3i::AXIS_X); } Vector3i Vector3i::clamp(const Vector3i &p_min, const Vector3i &p_max) const { diff --git a/core/math/vector3i.h b/core/math/vector3i.h index 10c28a5bb940..fba29a1f8df6 100644 --- a/core/math/vector3i.h +++ b/core/math/vector3i.h @@ -62,8 +62,8 @@ struct Vector3i { void set_axis(const int p_axis, const int32_t p_value); int32_t get_axis(const int p_axis) const; - int min_axis() const; - int max_axis() const; + Vector3i::Axis min_axis_index() const; + Vector3i::Axis max_axis_index() const; _FORCE_INLINE_ void zero(); diff --git a/core/variant/binder_common.h b/core/variant/binder_common.h index 98be62391f07..3f9f7e02b263 100644 --- a/core/variant/binder_common.h +++ b/core/variant/binder_common.h @@ -87,7 +87,10 @@ struct VariantCaster { // Object enum casts must go here VARIANT_ENUM_CAST(Object::ConnectFlags); +VARIANT_ENUM_CAST(Vector2::Axis); +VARIANT_ENUM_CAST(Vector2i::Axis); VARIANT_ENUM_CAST(Vector3::Axis); +VARIANT_ENUM_CAST(Vector3i::Axis); VARIANT_ENUM_CAST(Basis::EulerOrder); VARIANT_ENUM_CAST(Error); diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index b586757dcd0d..75f986bdf59b 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1486,6 +1486,8 @@ static void _register_variant_builtin_methods() { bind_method(Vector2, lerp, sarray("to", "weight"), varray()); bind_method(Vector2, slerp, sarray("to", "weight"), varray()); bind_method(Vector2, cubic_interpolate, sarray("b", "pre_a", "post_b", "weight"), varray()); + bind_method(Vector2, max_axis_index, sarray(), varray()); + bind_method(Vector2, min_axis_index, sarray(), varray()); bind_method(Vector2, move_toward, sarray("to", "delta"), varray()); bind_method(Vector2, rotated, sarray("phi"), varray()); bind_method(Vector2, orthogonal, sarray(), varray()); @@ -1508,6 +1510,8 @@ static void _register_variant_builtin_methods() { /* Vector2i */ bind_method(Vector2i, aspect, sarray(), varray()); + bind_method(Vector2i, max_axis_index, sarray(), varray()); + bind_method(Vector2i, min_axis_index, sarray(), varray()); bind_method(Vector2i, sign, sarray(), varray()); bind_method(Vector2i, abs, sarray(), varray()); bind_method(Vector2i, clamp, sarray("min", "max"), varray()); @@ -1547,8 +1551,8 @@ static void _register_variant_builtin_methods() { /* Vector3 */ - bind_method(Vector3, min_axis, sarray(), varray()); - bind_method(Vector3, max_axis, sarray(), varray()); + bind_method(Vector3, min_axis_index, sarray(), varray()); + bind_method(Vector3, max_axis_index, sarray(), varray()); bind_method(Vector3, angle_to, sarray("to"), varray()); bind_method(Vector3, signed_angle_to, sarray("to", "axis"), varray()); bind_method(Vector3, direction_to, sarray("to"), varray()); @@ -1587,8 +1591,8 @@ static void _register_variant_builtin_methods() { /* Vector3i */ - bind_method(Vector3i, min_axis, sarray(), varray()); - bind_method(Vector3i, max_axis, sarray(), varray()); + bind_method(Vector3i, min_axis_index, sarray(), varray()); + bind_method(Vector3i, max_axis_index, sarray(), varray()); bind_method(Vector3i, sign, sarray(), varray()); bind_method(Vector3i, abs, sarray(), varray()); bind_method(Vector3i, clamp, sarray("min", "max"), varray()); diff --git a/core/variant/variant_internal.h b/core/variant/variant_internal.h index 2ba24b5af853..d24f3e90f5d2 100644 --- a/core/variant/variant_internal.h +++ b/core/variant/variant_internal.h @@ -753,8 +753,14 @@ VARIANT_ACCESSOR_NUMBER(uint32_t) VARIANT_ACCESSOR_NUMBER(int64_t) VARIANT_ACCESSOR_NUMBER(uint64_t) VARIANT_ACCESSOR_NUMBER(char32_t) + +// Bind enums to allow using them as return types. VARIANT_ACCESSOR_NUMBER(Error) VARIANT_ACCESSOR_NUMBER(Side) +VARIANT_ACCESSOR_NUMBER(Vector2::Axis) +VARIANT_ACCESSOR_NUMBER(Vector2i::Axis) +VARIANT_ACCESSOR_NUMBER(Vector3::Axis) +VARIANT_ACCESSOR_NUMBER(Vector3i::Axis) template <> struct VariantInternalAccessor { @@ -1020,6 +1026,10 @@ INITIALIZER_INT(int64_t) INITIALIZER_INT(char32_t) INITIALIZER_INT(Error) INITIALIZER_INT(ObjectID) +INITIALIZER_INT(Vector2::Axis) +INITIALIZER_INT(Vector2i::Axis) +INITIALIZER_INT(Vector3::Axis) +INITIALIZER_INT(Vector3i::Axis) template <> struct VariantInitializer { diff --git a/doc/classes/Vector2.xml b/doc/classes/Vector2.xml index 15f7d2f9e34c..49ada6602081 100644 --- a/doc/classes/Vector2.xml +++ b/doc/classes/Vector2.xml @@ -214,6 +214,18 @@ Returns the vector with a maximum length by limiting its length to [code]length[/code]. + + + + Returns the axis of the vector's highest value. See [code]AXIS_*[/code] constants. If all components are equal, this method returns [constant AXIS_X]. + + + + + + Returns the axis of the vector's lowest value. See [code]AXIS_*[/code] constants. If all components are equal, this method returns [constant AXIS_Y]. + + @@ -315,10 +327,10 @@ - Enumerated value for the X axis. + Enumerated value for the X axis. Returned by [method max_axis_index] and [method min_axis_index]. - Enumerated value for the Y axis. + Enumerated value for the Y axis. Returned by [method max_axis_index] and [method min_axis_index]. Zero vector, a vector with all components set to [code]0[/code]. diff --git a/doc/classes/Vector2i.xml b/doc/classes/Vector2i.xml index 62362409a52a..a9334d924f10 100644 --- a/doc/classes/Vector2i.xml +++ b/doc/classes/Vector2i.xml @@ -64,6 +64,18 @@ Returns a new vector with all components clamped between the components of [code]min[/code] and [code]max[/code], by running [method @GlobalScope.clamp] on each component. + + + + Returns the axis of the vector's highest value. See [code]AXIS_*[/code] constants. If all components are equal, this method returns [constant AXIS_X]. + + + + + + Returns the axis of the vector's lowest value. See [code]AXIS_*[/code] constants. If all components are equal, this method returns [constant AXIS_Y]. + + @@ -81,10 +93,10 @@ - Enumerated value for the X axis. + Enumerated value for the X axis. Returned by [method max_axis_index] and [method min_axis_index]. - Enumerated value for the Y axis. + Enumerated value for the Y axis. Returned by [method max_axis_index] and [method min_axis_index]. Zero vector, a vector with all components set to [code]0[/code]. diff --git a/doc/classes/Vector3.xml b/doc/classes/Vector3.xml index 6d87ce9ea85d..5174cec02dca 100644 --- a/doc/classes/Vector3.xml +++ b/doc/classes/Vector3.xml @@ -184,16 +184,16 @@ Returns the vector with a maximum length by limiting its length to [code]length[/code]. - + - Returns the axis of the vector's largest value. See [code]AXIS_*[/code] constants. If all components are equal, this method returns [constant AXIS_X]. + Returns the axis of the vector's highest value. See [code]AXIS_*[/code] constants. If all components are equal, this method returns [constant AXIS_X]. - + - Returns the axis of the vector's smallest value. See [code]AXIS_*[/code] constants. If all components are equal, this method returns [constant AXIS_Z]. + Returns the axis of the vector's lowest value. See [code]AXIS_*[/code] constants. If all components are equal, this method returns [constant AXIS_Z]. @@ -321,13 +321,13 @@ - Enumerated value for the X axis. Returned by [method max_axis] and [method min_axis]. + Enumerated value for the X axis. Returned by [method max_axis_index] and [method min_axis_index]. - Enumerated value for the Y axis. Returned by [method max_axis] and [method min_axis]. + Enumerated value for the Y axis. Returned by [method max_axis_index] and [method min_axis_index]. - Enumerated value for the Z axis. Returned by [method max_axis] and [method min_axis]. + Enumerated value for the Z axis. Returned by [method max_axis_index] and [method min_axis_index]. Zero vector, a vector with all components set to [code]0[/code]. diff --git a/doc/classes/Vector3i.xml b/doc/classes/Vector3i.xml index 17febdea83d8..9b952292b632 100644 --- a/doc/classes/Vector3i.xml +++ b/doc/classes/Vector3i.xml @@ -58,16 +58,16 @@ Returns a new vector with all components clamped between the components of [code]min[/code] and [code]max[/code], by running [method @GlobalScope.clamp] on each component. - + - Returns the axis of the vector's largest value. See [code]AXIS_*[/code] constants. If all components are equal, this method returns [constant AXIS_X]. + Returns the axis of the vector's highest value. See [code]AXIS_*[/code] constants. If all components are equal, this method returns [constant AXIS_X]. - + - Returns the axis of the vector's smallest value. See [code]AXIS_*[/code] constants. If all components are equal, this method returns [constant AXIS_Z]. + Returns the axis of the vector's lowest value. See [code]AXIS_*[/code] constants. If all components are equal, this method returns [constant AXIS_Z]. @@ -90,13 +90,13 @@ - Enumerated value for the X axis. + Enumerated value for the X axis. Returned by [method max_axis_index] and [method min_axis_index]. - Enumerated value for the Y axis. + Enumerated value for the Y axis. Returned by [method max_axis_index] and [method min_axis_index]. - Enumerated value for the Z axis. + Enumerated value for the Z axis. Returned by [method max_axis_index] and [method min_axis_index]. Zero vector, a vector with all components set to [code]0[/code]. diff --git a/editor/plugins/tiles/tile_map_editor.cpp b/editor/plugins/tiles/tile_map_editor.cpp index 37d52174f923..fd2648a46920 100644 --- a/editor/plugins/tiles/tile_map_editor.cpp +++ b/editor/plugins/tiles/tile_map_editor.cpp @@ -3786,7 +3786,7 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { } // Draw the warning icon. - int min_axis = missing_tile_texture->get_size().min_axis(); + Vector2::Axis min_axis = missing_tile_texture->get_size().min_axis_index(); Vector2 icon_size; icon_size[min_axis] = tile_set->get_tile_size()[min_axis] / 3; icon_size[(min_axis + 1) % 2] = (icon_size[min_axis] * missing_tile_texture->get_size()[(min_axis + 1) % 2] / missing_tile_texture->get_size()[min_axis]); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs index 30ecd22db7b0..1f5282e88f8d 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs @@ -17,7 +17,7 @@ public struct Vector2 : IEquatable { /// /// Enumerated index values for the axes. - /// Returned by and . + /// Returned by and . /// public enum Axis { @@ -365,21 +365,21 @@ public Vector2 LimitLength(real_t length = 1.0f) } /// - /// Returns the axis of the vector's largest value. See . + /// Returns the axis of the vector's highest value. See . /// If both components are equal, this method returns . /// - /// The index of the largest axis. - public Axis MaxAxis() + /// The index of the highest axis. + public Axis MaxAxisIndex() { return x < y ? Axis.Y : Axis.X; } /// - /// Returns the axis of the vector's smallest value. See . + /// Returns the axis of the vector's lowest value. See . /// If both components are equal, this method returns . /// - /// The index of the smallest axis. - public Axis MinAxis() + /// The index of the lowest axis. + public Axis MinAxisIndex() { return x < y ? Axis.X : Axis.Y; } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs index 3bbc2ae2ba2f..9b51de5c8c93 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs @@ -17,7 +17,7 @@ public struct Vector2i : IEquatable { /// /// Enumerated index values for the axes. - /// Returned by and . + /// Returned by and . /// public enum Axis { @@ -218,21 +218,21 @@ public int LengthSquared() } /// - /// Returns the axis of the vector's largest value. See . + /// Returns the axis of the vector's highest value. See . /// If both components are equal, this method returns . /// - /// The index of the largest axis. - public Axis MaxAxis() + /// The index of the highest axis. + public Axis MaxAxisIndex() { return x < y ? Axis.Y : Axis.X; } /// - /// Returns the axis of the vector's smallest value. See . + /// Returns the axis of the vector's lowest value. See . /// If both components are equal, this method returns . /// - /// The index of the smallest axis. - public Axis MinAxis() + /// The index of the lowest axis. + public Axis MinAxisIndex() { return x < y ? Axis.X : Axis.Y; } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs index 15acf88f6217..433a5d9dc9c4 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs @@ -17,7 +17,7 @@ public struct Vector3 : IEquatable { /// /// Enumerated index values for the axes. - /// Returned by and . + /// Returned by and . /// public enum Axis { @@ -364,21 +364,21 @@ public Vector3 LimitLength(real_t length = 1.0f) } /// - /// Returns the axis of the vector's largest value. See . + /// Returns the axis of the vector's highest value. See . /// If all components are equal, this method returns . /// - /// The index of the largest axis. - public Axis MaxAxis() + /// The index of the highest axis. + public Axis MaxAxisIndex() { return x < y ? (y < z ? Axis.Z : Axis.Y) : (x < z ? Axis.Z : Axis.X); } /// - /// Returns the axis of the vector's smallest value. See . + /// Returns the axis of the vector's lowest value. See . /// If all components are equal, this method returns . /// - /// The index of the smallest axis. - public Axis MinAxis() + /// The index of the lowest axis. + public Axis MinAxisIndex() { return x < y ? (x < z ? Axis.X : Axis.Z) : (y < z ? Axis.Y : Axis.Z); } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs index 562f653fa8b5..eb06d2b87e0d 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs @@ -17,7 +17,7 @@ public struct Vector3i : IEquatable { /// /// Enumerated index values for the axes. - /// Returned by and . + /// Returned by and . /// public enum Axis { @@ -186,21 +186,21 @@ public int LengthSquared() } /// - /// Returns the axis of the vector's largest value. See . + /// Returns the axis of the vector's highest value. See . /// If all components are equal, this method returns . /// - /// The index of the largest axis. - public Axis MaxAxis() + /// The index of the highest axis. + public Axis MaxAxisIndex() { return x < y ? (y < z ? Axis.Z : Axis.Y) : (x < z ? Axis.Z : Axis.X); } /// - /// Returns the axis of the vector's smallest value. See . + /// Returns the axis of the vector's lowest value. See . /// If all components are equal, this method returns . /// - /// The index of the smallest axis. - public Axis MinAxis() + /// The index of the lowest axis. + public Axis MinAxisIndex() { return x < y ? (x < z ? Axis.X : Axis.Z) : (y < z ? Axis.Y : Axis.Z); }