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

Expose Vector* component-wise and scalar min/max to scripting #80223

Merged
merged 1 commit into from
May 2, 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
24 changes: 24 additions & 0 deletions core/variant/variant_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,10 @@ static void _register_variant_builtin_methods() {
bind_method(Vector2, clampf, sarray("min", "max"), varray());
bind_method(Vector2, snapped, sarray("step"), varray());
bind_method(Vector2, snappedf, sarray("step"), varray());
bind_method(Vector2, min, sarray("with"), varray());
bind_method(Vector2, minf, sarray("with"), varray());
bind_method(Vector2, max, sarray("with"), varray());
bind_method(Vector2, maxf, sarray("with"), varray());

bind_static_method(Vector2, from_angle, sarray("angle"), varray());

Expand All @@ -1825,6 +1829,10 @@ static void _register_variant_builtin_methods() {
bind_method(Vector2i, clampi, sarray("min", "max"), varray());
bind_method(Vector2i, snapped, sarray("step"), varray());
bind_method(Vector2i, snappedi, sarray("step"), varray());
bind_method(Vector2i, min, sarray("with"), varray());
bind_method(Vector2i, mini, sarray("with"), varray());
bind_method(Vector2i, max, sarray("with"), varray());
bind_method(Vector2i, maxi, sarray("with"), varray());

/* Rect2 */

Expand Down Expand Up @@ -1905,6 +1913,10 @@ static void _register_variant_builtin_methods() {
bind_method(Vector3, reflect, sarray("n"), varray());
bind_method(Vector3, sign, sarray(), varray());
bind_method(Vector3, octahedron_encode, sarray(), varray());
bind_method(Vector3, min, sarray("with"), varray());
bind_method(Vector3, minf, sarray("with"), varray());
bind_method(Vector3, max, sarray("with"), varray());
bind_method(Vector3, maxf, sarray("with"), varray());
bind_static_method(Vector3, octahedron_decode, sarray("uv"), varray());

/* Vector3i */
Expand All @@ -1921,6 +1933,10 @@ static void _register_variant_builtin_methods() {
bind_method(Vector3i, clampi, sarray("min", "max"), varray());
bind_method(Vector3i, snapped, sarray("step"), varray());
bind_method(Vector3i, snappedi, sarray("step"), varray());
bind_method(Vector3i, min, sarray("with"), varray());
bind_method(Vector3i, mini, sarray("with"), varray());
bind_method(Vector3i, max, sarray("with"), varray());
bind_method(Vector3i, maxi, sarray("with"), varray());

/* Vector4 */

Expand Down Expand Up @@ -1952,6 +1968,10 @@ static void _register_variant_builtin_methods() {
bind_method(Vector4, is_equal_approx, sarray("to"), varray());
bind_method(Vector4, is_zero_approx, sarray(), varray());
bind_method(Vector4, is_finite, sarray(), varray());
bind_method(Vector4, min, sarray("with"), varray());
bind_method(Vector4, minf, sarray("with"), varray());
bind_method(Vector4, max, sarray("with"), varray());
bind_method(Vector4, maxf, sarray("with"), varray());

/* Vector4i */

Expand All @@ -1965,6 +1985,10 @@ static void _register_variant_builtin_methods() {
bind_method(Vector4i, clampi, sarray("min", "max"), varray());
bind_method(Vector4i, snapped, sarray("step"), varray());
bind_method(Vector4i, snappedi, sarray("step"), varray());
bind_method(Vector4i, min, sarray("with"), varray());
bind_method(Vector4i, mini, sarray("with"), varray());
bind_method(Vector4i, max, sarray("with"), varray());
bind_method(Vector4i, maxi, sarray("with"), varray());
bind_method(Vector4i, distance_to, sarray("to"), varray());
bind_method(Vector4i, distance_squared_to, sarray("to"), varray());

Expand Down
2 changes: 2 additions & 0 deletions doc/classes/@GlobalScope.xml
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@
[codeblock]
max(1, 7, 3, -6, 5) # Returns 7
[/codeblock]
[b]Note:[/b] When using this on vectors it will [i]not[/i] perform component-wise maximum, and will pick the largest value when compared using [code]x < y[/code]. To perform component-wise maximum, use [method Vector2.max], [method Vector2i.max], [method Vector3.max], [method Vector3i.max], [method Vector4.max], and [method Vector4i.max].
</description>
</method>
<method name="maxf">
Expand Down Expand Up @@ -729,6 +730,7 @@
[codeblock]
min(1, 7, 3, -6, 5) # Returns -6
[/codeblock]
[b]Note:[/b] When using this on vectors it will [i]not[/i] perform component-wise minimum, and will pick the smallest value when compared using [code]x &lt; y[/code]. To perform component-wise minimum, use [method Vector2.min], [method Vector2i.min], [method Vector3.min], [method Vector3i.min], [method Vector4.min], and [method Vector4i.min].
</description>
</method>
<method name="minf">
Expand Down
28 changes: 28 additions & 0 deletions doc/classes/Vector2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,46 @@
Returns the vector with a maximum length by limiting its length to [param length].
</description>
</method>
<method name="max" qualifiers="const">
<return type="Vector2" />
<param index="0" name="with" type="Vector2" />
<description>
Returns the component-wise maximum of this and [param with], equivalent to [code]Vector2(maxf(x, with.x), maxf(y, with.y))[/code].
</description>
</method>
<method name="max_axis_index" qualifiers="const">
<return type="int" />
<description>
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].
</description>
</method>
<method name="maxf" qualifiers="const">
<return type="Vector2" />
<param index="0" name="with" type="float" />
<description>
Returns the component-wise maximum of this and [param with], equivalent to [code]Vector2(maxf(x, with), maxf(y, with))[/code].
</description>
</method>
<method name="min" qualifiers="const">
<return type="Vector2" />
<param index="0" name="with" type="Vector2" />
<description>
Returns the component-wise minimum of this and [param with], equivalent to [code]Vector2(minf(x, with.x), minf(y, with.y))[/code].
</description>
</method>
<method name="min_axis_index" qualifiers="const">
<return type="int" />
<description>
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].
</description>
</method>
<method name="minf" qualifiers="const">
<return type="Vector2" />
<param index="0" name="with" type="float" />
<description>
Returns the component-wise minimum of this and [param with], equivalent to [code]Vector2(minf(x, with), minf(y, with))[/code].
</description>
</method>
<method name="move_toward" qualifiers="const">
<return type="Vector2" />
<param index="0" name="to" type="Vector2" />
Expand Down
28 changes: 28 additions & 0 deletions doc/classes/Vector2i.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,46 @@
This method runs faster than [method length], so prefer it if you need to compare vectors or need the squared distance for some formula.
</description>
</method>
<method name="max" qualifiers="const">
<return type="Vector2i" />
<param index="0" name="with" type="Vector2i" />
<description>
Returns the component-wise maximum of this and [param with], equivalent to [code]Vector2i(maxi(x, with.x), maxi(y, with.y))[/code].
</description>
</method>
<method name="max_axis_index" qualifiers="const">
<return type="int" />
<description>
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].
</description>
</method>
<method name="maxi" qualifiers="const">
<return type="Vector2i" />
<param index="0" name="with" type="int" />
<description>
Returns the component-wise maximum of this and [param with], equivalent to [code]Vector2i(maxi(x, with), maxi(y, with))[/code].
</description>
</method>
<method name="min" qualifiers="const">
<return type="Vector2i" />
<param index="0" name="with" type="Vector2i" />
<description>
Returns the component-wise minimum of this and [param with], equivalent to [code]Vector2i(mini(x, with.x), mini(y, with.y))[/code].
</description>
</method>
<method name="min_axis_index" qualifiers="const">
<return type="int" />
<description>
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].
</description>
</method>
<method name="mini" qualifiers="const">
<return type="Vector2i" />
<param index="0" name="with" type="int" />
<description>
Returns the component-wise minimum of this and [param with], equivalent to [code]Vector2i(mini(x, with), mini(y, with))[/code].
</description>
</method>
<method name="sign" qualifiers="const">
<return type="Vector2i" />
<description>
Expand Down
28 changes: 28 additions & 0 deletions doc/classes/Vector3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,18 +242,46 @@
Returns the vector with a maximum length by limiting its length to [param length].
</description>
</method>
<method name="max" qualifiers="const">
<return type="Vector3" />
<param index="0" name="with" type="Vector3" />
<description>
Returns the component-wise maximum of this and [param with], equivalent to [code]Vector3(maxf(x, with.x), maxf(y, with.y), maxf(z, with.z))[/code].
</description>
</method>
<method name="max_axis_index" qualifiers="const">
<return type="int" />
<description>
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].
</description>
</method>
<method name="maxf" qualifiers="const">
<return type="Vector3" />
<param index="0" name="with" type="float" />
<description>
Returns the component-wise maximum of this and [param with], equivalent to [code]Vector3(maxf(x, with), maxf(y, with), maxf(z, with))[/code].
</description>
</method>
<method name="min" qualifiers="const">
<return type="Vector3" />
<param index="0" name="with" type="Vector3" />
<description>
Returns the component-wise minimum of this and [param with], equivalent to [code]Vector3(minf(x, with.x), minf(y, with.y), minf(z, with.z))[/code].
</description>
</method>
<method name="min_axis_index" qualifiers="const">
<return type="int" />
<description>
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].
</description>
</method>
<method name="minf" qualifiers="const">
<return type="Vector3" />
<param index="0" name="with" type="float" />
<description>
Returns the component-wise minimum of this and [param with], equivalent to [code]Vector3(minf(x, with), minf(y, with), minf(z, with))[/code].
</description>
</method>
<method name="move_toward" qualifiers="const">
<return type="Vector3" />
<param index="0" name="to" type="Vector3" />
Expand Down
28 changes: 28 additions & 0 deletions doc/classes/Vector3i.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,46 @@
This method runs faster than [method length], so prefer it if you need to compare vectors or need the squared distance for some formula.
</description>
</method>
<method name="max" qualifiers="const">
<return type="Vector3i" />
<param index="0" name="with" type="Vector3i" />
<description>
Returns the component-wise maximum of this and [param with], equivalent to [code]Vector3i(maxi(x, with.x), maxi(y, with.y), maxi(z, with.z))[/code].
</description>
</method>
<method name="max_axis_index" qualifiers="const">
<return type="int" />
<description>
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].
</description>
</method>
<method name="maxi" qualifiers="const">
<return type="Vector3i" />
<param index="0" name="with" type="int" />
<description>
Returns the component-wise maximum of this and [param with], equivalent to [code]Vector3i(maxi(x, with), maxi(y, with), maxi(z, with))[/code].
</description>
</method>
<method name="min" qualifiers="const">
<return type="Vector3i" />
<param index="0" name="with" type="Vector3i" />
<description>
Returns the component-wise minimum of this and [param with], equivalent to [code]Vector3i(mini(x, with.x), mini(y, with.y), mini(z, with.z))[/code].
</description>
</method>
<method name="min_axis_index" qualifiers="const">
<return type="int" />
<description>
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].
</description>
</method>
<method name="mini" qualifiers="const">
<return type="Vector3i" />
<param index="0" name="with" type="int" />
<description>
Returns the component-wise minimum of this and [param with], equivalent to [code]Vector3i(mini(x, with), mini(y, with), mini(z, with))[/code].
</description>
</method>
<method name="sign" qualifiers="const">
<return type="Vector3i" />
<description>
Expand Down
28 changes: 28 additions & 0 deletions doc/classes/Vector4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,46 @@
Returns the result of the linear interpolation between this vector and [param to] by amount [param weight]. [param weight] is on the range of [code]0.0[/code] to [code]1.0[/code], representing the amount of interpolation.
</description>
</method>
<method name="max" qualifiers="const">
<return type="Vector4" />
<param index="0" name="with" type="Vector4" />
<description>
Returns the component-wise maximum of this and [param with], equivalent to [code]Vector4(maxf(x, with.x), maxf(y, with.y), maxf(z, with.z), maxf(w, with.w))[/code].
</description>
</method>
<method name="max_axis_index" qualifiers="const">
<return type="int" />
<description>
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].
</description>
</method>
<method name="maxf" qualifiers="const">
<return type="Vector4" />
<param index="0" name="with" type="float" />
<description>
Returns the component-wise maximum of this and [param with], equivalent to [code]Vector4(maxf(x, with), maxf(y, with), maxf(z, with), maxf(w, with))[/code].
</description>
</method>
<method name="min" qualifiers="const">
<return type="Vector4" />
<param index="0" name="with" type="Vector4" />
<description>
Returns the component-wise minimum of this and [param with], equivalent to [code]Vector4(minf(x, with.x), minf(y, with.y), minf(z, with.z), minf(w, with.w))[/code].
</description>
</method>
<method name="min_axis_index" qualifiers="const">
<return type="int" />
<description>
Returns the axis of the vector's lowest value. See [code]AXIS_*[/code] constants. If all components are equal, this method returns [constant AXIS_W].
</description>
</method>
<method name="minf" qualifiers="const">
<return type="Vector4" />
<param index="0" name="with" type="float" />
<description>
Returns the component-wise minimum of this and [param with], equivalent to [code]Vector4(minf(x, with), minf(y, with), minf(z, with), minf(w, with))[/code].
</description>
</method>
<method name="normalized" qualifiers="const">
<return type="Vector4" />
<description>
Expand Down
28 changes: 28 additions & 0 deletions doc/classes/Vector4i.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,46 @@
This method runs faster than [method length], so prefer it if you need to compare vectors or need the squared distance for some formula.
</description>
</method>
<method name="max" qualifiers="const">
<return type="Vector4i" />
<param index="0" name="with" type="Vector4i" />
<description>
Returns the component-wise maximum of this and [param with], equivalent to [code]Vector4i(maxi(x, with.x), maxi(y, with.y), maxi(z, with.z), maxi(w, with.w))[/code].
</description>
</method>
<method name="max_axis_index" qualifiers="const">
<return type="int" />
<description>
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].
</description>
</method>
<method name="maxi" qualifiers="const">
<return type="Vector4i" />
<param index="0" name="with" type="int" />
<description>
Returns the component-wise maximum of this and [param with], equivalent to [code]Vector4i(maxi(x, with), maxi(y, with), maxi(z, with), maxi(w, with))[/code].
</description>
</method>
<method name="min" qualifiers="const">
<return type="Vector4i" />
<param index="0" name="with" type="Vector4i" />
<description>
Returns the component-wise minimum of this and [param with], equivalent to [code]Vector4i(mini(x, with.x), mini(y, with.y), mini(z, with.z), mini(w, with.w))[/code].
</description>
</method>
<method name="min_axis_index" qualifiers="const">
<return type="int" />
<description>
Returns the axis of the vector's lowest value. See [code]AXIS_*[/code] constants. If all components are equal, this method returns [constant AXIS_W].
</description>
</method>
<method name="mini" qualifiers="const">
<return type="Vector4i" />
<param index="0" name="with" type="int" />
<description>
Returns the component-wise minimum of this and [param with], equivalent to [code]Vector4i(mini(x, with), mini(y, with), mini(z, with), mini(w, with))[/code].
</description>
</method>
<method name="sign" qualifiers="const">
<return type="Vector4i" />
<description>
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/glue/GodotSharp/GodotSharp/Core/Aabb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public readonly real_t Volume
public readonly Aabb Abs()
{
Vector3 end = End;
Vector3 topLeft = new Vector3(Mathf.Min(_position.X, end.X), Mathf.Min(_position.Y, end.Y), Mathf.Min(_position.Z, end.Z));
Vector3 topLeft = end.Min(_position);
return new Aabb(topLeft, _size.Abs());
}

Expand Down
Loading
Loading