Skip to content

Commit 396ce1a

Browse files
committed
Merge pull request #80223 from AThousandShips/vec_elem
Expose `Vector*` component-wise and scalar `min/max` to scripting
2 parents a0b0b19 + 0f5e0d1 commit 396ce1a

File tree

17 files changed

+596
-19
lines changed

17 files changed

+596
-19
lines changed

core/variant/variant_call.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,10 @@ static void _register_variant_builtin_methods() {
18071807
bind_method(Vector2, clampf, sarray("min", "max"), varray());
18081808
bind_method(Vector2, snapped, sarray("step"), varray());
18091809
bind_method(Vector2, snappedf, sarray("step"), varray());
1810+
bind_method(Vector2, min, sarray("with"), varray());
1811+
bind_method(Vector2, minf, sarray("with"), varray());
1812+
bind_method(Vector2, max, sarray("with"), varray());
1813+
bind_method(Vector2, maxf, sarray("with"), varray());
18101814

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

@@ -1825,6 +1829,10 @@ static void _register_variant_builtin_methods() {
18251829
bind_method(Vector2i, clampi, sarray("min", "max"), varray());
18261830
bind_method(Vector2i, snapped, sarray("step"), varray());
18271831
bind_method(Vector2i, snappedi, sarray("step"), varray());
1832+
bind_method(Vector2i, min, sarray("with"), varray());
1833+
bind_method(Vector2i, mini, sarray("with"), varray());
1834+
bind_method(Vector2i, max, sarray("with"), varray());
1835+
bind_method(Vector2i, maxi, sarray("with"), varray());
18281836

18291837
/* Rect2 */
18301838

@@ -1905,6 +1913,10 @@ static void _register_variant_builtin_methods() {
19051913
bind_method(Vector3, reflect, sarray("n"), varray());
19061914
bind_method(Vector3, sign, sarray(), varray());
19071915
bind_method(Vector3, octahedron_encode, sarray(), varray());
1916+
bind_method(Vector3, min, sarray("with"), varray());
1917+
bind_method(Vector3, minf, sarray("with"), varray());
1918+
bind_method(Vector3, max, sarray("with"), varray());
1919+
bind_method(Vector3, maxf, sarray("with"), varray());
19081920
bind_static_method(Vector3, octahedron_decode, sarray("uv"), varray());
19091921

19101922
/* Vector3i */
@@ -1921,6 +1933,10 @@ static void _register_variant_builtin_methods() {
19211933
bind_method(Vector3i, clampi, sarray("min", "max"), varray());
19221934
bind_method(Vector3i, snapped, sarray("step"), varray());
19231935
bind_method(Vector3i, snappedi, sarray("step"), varray());
1936+
bind_method(Vector3i, min, sarray("with"), varray());
1937+
bind_method(Vector3i, mini, sarray("with"), varray());
1938+
bind_method(Vector3i, max, sarray("with"), varray());
1939+
bind_method(Vector3i, maxi, sarray("with"), varray());
19241940

19251941
/* Vector4 */
19261942

@@ -1952,6 +1968,10 @@ static void _register_variant_builtin_methods() {
19521968
bind_method(Vector4, is_equal_approx, sarray("to"), varray());
19531969
bind_method(Vector4, is_zero_approx, sarray(), varray());
19541970
bind_method(Vector4, is_finite, sarray(), varray());
1971+
bind_method(Vector4, min, sarray("with"), varray());
1972+
bind_method(Vector4, minf, sarray("with"), varray());
1973+
bind_method(Vector4, max, sarray("with"), varray());
1974+
bind_method(Vector4, maxf, sarray("with"), varray());
19551975

19561976
/* Vector4i */
19571977

@@ -1965,6 +1985,10 @@ static void _register_variant_builtin_methods() {
19651985
bind_method(Vector4i, clampi, sarray("min", "max"), varray());
19661986
bind_method(Vector4i, snapped, sarray("step"), varray());
19671987
bind_method(Vector4i, snappedi, sarray("step"), varray());
1988+
bind_method(Vector4i, min, sarray("with"), varray());
1989+
bind_method(Vector4i, mini, sarray("with"), varray());
1990+
bind_method(Vector4i, max, sarray("with"), varray());
1991+
bind_method(Vector4i, maxi, sarray("with"), varray());
19681992
bind_method(Vector4i, distance_to, sarray("to"), varray());
19691993
bind_method(Vector4i, distance_squared_to, sarray("to"), varray());
19701994

doc/classes/@GlobalScope.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@
696696
[codeblock]
697697
max(1, 7, 3, -6, 5) # Returns 7
698698
[/codeblock]
699+
[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].
699700
</description>
700701
</method>
701702
<method name="maxf">
@@ -729,6 +730,7 @@
729730
[codeblock]
730731
min(1, 7, 3, -6, 5) # Returns -6
731732
[/codeblock]
733+
[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].
732734
</description>
733735
</method>
734736
<method name="minf">

doc/classes/Vector2.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,18 +273,46 @@
273273
Returns the vector with a maximum length by limiting its length to [param length].
274274
</description>
275275
</method>
276+
<method name="max" qualifiers="const">
277+
<return type="Vector2" />
278+
<param index="0" name="with" type="Vector2" />
279+
<description>
280+
Returns the component-wise maximum of this and [param with], equivalent to [code]Vector2(maxf(x, with.x), maxf(y, with.y))[/code].
281+
</description>
282+
</method>
276283
<method name="max_axis_index" qualifiers="const">
277284
<return type="int" />
278285
<description>
279286
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].
280287
</description>
281288
</method>
289+
<method name="maxf" qualifiers="const">
290+
<return type="Vector2" />
291+
<param index="0" name="with" type="float" />
292+
<description>
293+
Returns the component-wise maximum of this and [param with], equivalent to [code]Vector2(maxf(x, with), maxf(y, with))[/code].
294+
</description>
295+
</method>
296+
<method name="min" qualifiers="const">
297+
<return type="Vector2" />
298+
<param index="0" name="with" type="Vector2" />
299+
<description>
300+
Returns the component-wise minimum of this and [param with], equivalent to [code]Vector2(minf(x, with.x), minf(y, with.y))[/code].
301+
</description>
302+
</method>
282303
<method name="min_axis_index" qualifiers="const">
283304
<return type="int" />
284305
<description>
285306
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].
286307
</description>
287308
</method>
309+
<method name="minf" qualifiers="const">
310+
<return type="Vector2" />
311+
<param index="0" name="with" type="float" />
312+
<description>
313+
Returns the component-wise minimum of this and [param with], equivalent to [code]Vector2(minf(x, with), minf(y, with))[/code].
314+
</description>
315+
</method>
288316
<method name="move_toward" qualifiers="const">
289317
<return type="Vector2" />
290318
<param index="0" name="to" type="Vector2" />

doc/classes/Vector2i.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,46 @@
100100
This method runs faster than [method length], so prefer it if you need to compare vectors or need the squared distance for some formula.
101101
</description>
102102
</method>
103+
<method name="max" qualifiers="const">
104+
<return type="Vector2i" />
105+
<param index="0" name="with" type="Vector2i" />
106+
<description>
107+
Returns the component-wise maximum of this and [param with], equivalent to [code]Vector2i(maxi(x, with.x), maxi(y, with.y))[/code].
108+
</description>
109+
</method>
103110
<method name="max_axis_index" qualifiers="const">
104111
<return type="int" />
105112
<description>
106113
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].
107114
</description>
108115
</method>
116+
<method name="maxi" qualifiers="const">
117+
<return type="Vector2i" />
118+
<param index="0" name="with" type="int" />
119+
<description>
120+
Returns the component-wise maximum of this and [param with], equivalent to [code]Vector2i(maxi(x, with), maxi(y, with))[/code].
121+
</description>
122+
</method>
123+
<method name="min" qualifiers="const">
124+
<return type="Vector2i" />
125+
<param index="0" name="with" type="Vector2i" />
126+
<description>
127+
Returns the component-wise minimum of this and [param with], equivalent to [code]Vector2i(mini(x, with.x), mini(y, with.y))[/code].
128+
</description>
129+
</method>
109130
<method name="min_axis_index" qualifiers="const">
110131
<return type="int" />
111132
<description>
112133
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].
113134
</description>
114135
</method>
136+
<method name="mini" qualifiers="const">
137+
<return type="Vector2i" />
138+
<param index="0" name="with" type="int" />
139+
<description>
140+
Returns the component-wise minimum of this and [param with], equivalent to [code]Vector2i(mini(x, with), mini(y, with))[/code].
141+
</description>
142+
</method>
115143
<method name="sign" qualifiers="const">
116144
<return type="Vector2i" />
117145
<description>

doc/classes/Vector3.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,18 +242,46 @@
242242
Returns the vector with a maximum length by limiting its length to [param length].
243243
</description>
244244
</method>
245+
<method name="max" qualifiers="const">
246+
<return type="Vector3" />
247+
<param index="0" name="with" type="Vector3" />
248+
<description>
249+
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].
250+
</description>
251+
</method>
245252
<method name="max_axis_index" qualifiers="const">
246253
<return type="int" />
247254
<description>
248255
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].
249256
</description>
250257
</method>
258+
<method name="maxf" qualifiers="const">
259+
<return type="Vector3" />
260+
<param index="0" name="with" type="float" />
261+
<description>
262+
Returns the component-wise maximum of this and [param with], equivalent to [code]Vector3(maxf(x, with), maxf(y, with), maxf(z, with))[/code].
263+
</description>
264+
</method>
265+
<method name="min" qualifiers="const">
266+
<return type="Vector3" />
267+
<param index="0" name="with" type="Vector3" />
268+
<description>
269+
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].
270+
</description>
271+
</method>
251272
<method name="min_axis_index" qualifiers="const">
252273
<return type="int" />
253274
<description>
254275
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].
255276
</description>
256277
</method>
278+
<method name="minf" qualifiers="const">
279+
<return type="Vector3" />
280+
<param index="0" name="with" type="float" />
281+
<description>
282+
Returns the component-wise minimum of this and [param with], equivalent to [code]Vector3(minf(x, with), minf(y, with), minf(z, with))[/code].
283+
</description>
284+
</method>
257285
<method name="move_toward" qualifiers="const">
258286
<return type="Vector3" />
259287
<param index="0" name="to" type="Vector3" />

doc/classes/Vector3i.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,46 @@
9595
This method runs faster than [method length], so prefer it if you need to compare vectors or need the squared distance for some formula.
9696
</description>
9797
</method>
98+
<method name="max" qualifiers="const">
99+
<return type="Vector3i" />
100+
<param index="0" name="with" type="Vector3i" />
101+
<description>
102+
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].
103+
</description>
104+
</method>
98105
<method name="max_axis_index" qualifiers="const">
99106
<return type="int" />
100107
<description>
101108
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].
102109
</description>
103110
</method>
111+
<method name="maxi" qualifiers="const">
112+
<return type="Vector3i" />
113+
<param index="0" name="with" type="int" />
114+
<description>
115+
Returns the component-wise maximum of this and [param with], equivalent to [code]Vector3i(maxi(x, with), maxi(y, with), maxi(z, with))[/code].
116+
</description>
117+
</method>
118+
<method name="min" qualifiers="const">
119+
<return type="Vector3i" />
120+
<param index="0" name="with" type="Vector3i" />
121+
<description>
122+
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].
123+
</description>
124+
</method>
104125
<method name="min_axis_index" qualifiers="const">
105126
<return type="int" />
106127
<description>
107128
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].
108129
</description>
109130
</method>
131+
<method name="mini" qualifiers="const">
132+
<return type="Vector3i" />
133+
<param index="0" name="with" type="int" />
134+
<description>
135+
Returns the component-wise minimum of this and [param with], equivalent to [code]Vector3i(mini(x, with), mini(y, with), mini(z, with))[/code].
136+
</description>
137+
</method>
110138
<method name="sign" qualifiers="const">
111139
<return type="Vector3i" />
112140
<description>

doc/classes/Vector4.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,46 @@
184184
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.
185185
</description>
186186
</method>
187+
<method name="max" qualifiers="const">
188+
<return type="Vector4" />
189+
<param index="0" name="with" type="Vector4" />
190+
<description>
191+
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].
192+
</description>
193+
</method>
187194
<method name="max_axis_index" qualifiers="const">
188195
<return type="int" />
189196
<description>
190197
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].
191198
</description>
192199
</method>
200+
<method name="maxf" qualifiers="const">
201+
<return type="Vector4" />
202+
<param index="0" name="with" type="float" />
203+
<description>
204+
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].
205+
</description>
206+
</method>
207+
<method name="min" qualifiers="const">
208+
<return type="Vector4" />
209+
<param index="0" name="with" type="Vector4" />
210+
<description>
211+
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].
212+
</description>
213+
</method>
193214
<method name="min_axis_index" qualifiers="const">
194215
<return type="int" />
195216
<description>
196217
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].
197218
</description>
198219
</method>
220+
<method name="minf" qualifiers="const">
221+
<return type="Vector4" />
222+
<param index="0" name="with" type="float" />
223+
<description>
224+
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].
225+
</description>
226+
</method>
199227
<method name="normalized" qualifiers="const">
200228
<return type="Vector4" />
201229
<description>

doc/classes/Vector4i.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,46 @@
9393
This method runs faster than [method length], so prefer it if you need to compare vectors or need the squared distance for some formula.
9494
</description>
9595
</method>
96+
<method name="max" qualifiers="const">
97+
<return type="Vector4i" />
98+
<param index="0" name="with" type="Vector4i" />
99+
<description>
100+
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].
101+
</description>
102+
</method>
96103
<method name="max_axis_index" qualifiers="const">
97104
<return type="int" />
98105
<description>
99106
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].
100107
</description>
101108
</method>
109+
<method name="maxi" qualifiers="const">
110+
<return type="Vector4i" />
111+
<param index="0" name="with" type="int" />
112+
<description>
113+
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].
114+
</description>
115+
</method>
116+
<method name="min" qualifiers="const">
117+
<return type="Vector4i" />
118+
<param index="0" name="with" type="Vector4i" />
119+
<description>
120+
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].
121+
</description>
122+
</method>
102123
<method name="min_axis_index" qualifiers="const">
103124
<return type="int" />
104125
<description>
105126
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].
106127
</description>
107128
</method>
129+
<method name="mini" qualifiers="const">
130+
<return type="Vector4i" />
131+
<param index="0" name="with" type="int" />
132+
<description>
133+
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].
134+
</description>
135+
</method>
108136
<method name="sign" qualifiers="const">
109137
<return type="Vector4i" />
110138
<description>

modules/mono/glue/GodotSharp/GodotSharp/Core/Aabb.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public readonly real_t Volume
6969
public readonly Aabb Abs()
7070
{
7171
Vector3 end = End;
72-
Vector3 topLeft = new Vector3(Mathf.Min(_position.X, end.X), Mathf.Min(_position.Y, end.Y), Mathf.Min(_position.Z, end.Z));
72+
Vector3 topLeft = end.Min(_position);
7373
return new Aabb(topLeft, _size.Abs());
7474
}
7575

0 commit comments

Comments
 (0)