Debian Codegraph @

doc/classes/Vector2i.xml

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <class name="Vector2i" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3 <brief_description>
4 A 2D vector using integer coordinates.
5 </brief_description>
6 <description>
7 A 2-element structure that can be used to represent 2D grid coordinates or any other pair of integers.
8 It uses integer coordinates and is therefore preferable to [Vector2] when exact precision is required. Note that the values are limited to 32 bits, and unlike [Vector2] this cannot be configured with an engine build option. Use [int] or [PackedInt64Array] if 64-bit values are needed.
9 [b]Note:[/b] In a boolean context, a Vector2i will evaluate to [code]false[/code] if it's equal to [code]Vector2i(0, 0)[/code]. Otherwise, a Vector2i will always evaluate to [code]true[/code].
10 </description>
11 <tutorials>
12 <link title="Math documentation index">$DOCS_URL/tutorials/math/index.html</link>
13 <link title="Vector math">$DOCS_URL/tutorials/math/vector_math.html</link>
14 <link title="3Blue1Brown Essence of Linear Algebra">https://www.youtube.com/playlist?list=PLZHQObOWTQDPD3MizzM2xVFitgF8hE_ab</link>
15 </tutorials>
16 <constructors>
17 <constructor name="Vector2i">
18 <return type="Vector2i" />
19 <description>
20 Constructs a default-initialized [Vector2i] with all components set to [code]0[/code].
21 </description>
22 </constructor>
23 <constructor name="Vector2i">
24 <return type="Vector2i" />
25 <param index="0" name="from" type="Vector2i" />
26 <description>
27 Constructs a [Vector2i] as a copy of the given [Vector2i].
28 </description>
29 </constructor>
30 <constructor name="Vector2i">
31 <return type="Vector2i" />
32 <param index="0" name="from" type="Vector2" />
33 <description>
34 Constructs a new [Vector2i] from the given [Vector2] by truncating components' fractional parts (rounding towards zero). For a different behavior consider passing the result of [method Vector2.ceil], [method Vector2.floor] or [method Vector2.round] to this constructor instead.
35 </description>
36 </constructor>
37 <constructor name="Vector2i">
38 <return type="Vector2i" />
39 <param index="0" name="x" type="int" />
40 <param index="1" name="y" type="int" />
41 <description>
42 Constructs a new [Vector2i] from the given [param x] and [param y].
43 </description>
44 </constructor>
45 </constructors>
46 <methods>
47 <method name="abs" qualifiers="const">
48 <return type="Vector2i" />
49 <description>
50 Returns a new vector with all components in absolute values (i.e. positive).
51 </description>
52 </method>
53 <method name="aspect" qualifiers="const">
54 <return type="float" />
55 <description>
56 Returns the aspect ratio of this vector, the ratio of [member x] to [member y].
57 </description>
58 </method>
59 <method name="clamp" qualifiers="const">
60 <return type="Vector2i" />
61 <param index="0" name="min" type="Vector2i" />
62 <param index="1" name="max" type="Vector2i" />
63 <description>
64 Returns a new vector with all components clamped between the components of [param min] and [param max], by running [method @GlobalScope.clamp] on each component.
65 </description>
66 </method>
67 <method name="clampi" qualifiers="const">
68 <return type="Vector2i" />
69 <param index="0" name="min" type="int" />
70 <param index="1" name="max" type="int" />
71 <description>
72 Returns a new vector with all components clamped between [param min] and [param max], by running [method @GlobalScope.clamp] on each component.
73 </description>
74 </method>
75 <method name="distance_squared_to" qualifiers="const">
76 <return type="int" />
77 <param index="0" name="to" type="Vector2i" />
78 <description>
79 Returns the squared distance between this vector and [param to].
80 This method runs faster than [method distance_to], so prefer it if you need to compare vectors or need the squared distance for some formula.
81 </description>
82 </method>
83 <method name="distance_to" qualifiers="const">
84 <return type="float" />
85 <param index="0" name="to" type="Vector2i" />
86 <description>
87 Returns the distance between this vector and [param to].
88 </description>
89 </method>
90 <method name="length" qualifiers="const" keywords="size">
91 <return type="float" />
92 <description>
93 Returns the length (magnitude) of this vector.
94 </description>
95 </method>
96 <method name="length_squared" qualifiers="const">
97 <return type="int" />
98 <description>
99 Returns the squared length (squared magnitude) of this vector.
100 This method runs faster than [method length], so prefer it if you need to compare vectors or need the squared distance for some formula.
101 </description>
102 </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>
110 <method name="max_axis_index" qualifiers="const">
111 <return type="int" />
112 <description>
113 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].
114 </description>
115 </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>
130 <method name="min_axis_index" qualifiers="const">
131 <return type="int" />
132 <description>
133 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].
134 </description>
135 </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>
143 <method name="sign" qualifiers="const">
144 <return type="Vector2i" />
145 <description>
146 Returns a new vector with each component set to [code]1[/code] if it's positive, [code]-1[/code] if it's negative, and [code]0[/code] if it's zero. The result is identical to calling [method @GlobalScope.sign] on each component.
147 </description>
148 </method>
149 <method name="snapped" qualifiers="const">
150 <return type="Vector2i" />
151 <param index="0" name="step" type="Vector2i" />
152 <description>
153 Returns a new vector with each component snapped to the closest multiple of the corresponding component in [param step].
154 </description>
155 </method>
156 <method name="snappedi" qualifiers="const">
157 <return type="Vector2i" />
158 <param index="0" name="step" type="int" />
159 <description>
160 Returns a new vector with each component snapped to the closest multiple of [param step].
161 </description>
162 </method>
163 </methods>
164 <members>
165 <member name="x" type="int" setter="" getter="" default="0">
166 The vector's X component. Also accessible by using the index position [code][0][/code].
167 </member>
168 <member name="y" type="int" setter="" getter="" default="0">
169 The vector's Y component. Also accessible by using the index position [code][1][/code].
170 </member>
171 </members>
172 <constants>
173 <constant name="AXIS_X" value="0" enum="Axis">
174 Enumerated value for the X axis. Returned by [method max_axis_index] and [method min_axis_index].
175 </constant>
176 <constant name="AXIS_Y" value="1" enum="Axis">
177 Enumerated value for the Y axis. Returned by [method max_axis_index] and [method min_axis_index].
178 </constant>
179 <constant name="ZERO" value="Vector2i(0, 0)">
180 Zero vector, a vector with all components set to [code]0[/code].
181 </constant>
182 <constant name="ONE" value="Vector2i(1, 1)">
183 One vector, a vector with all components set to [code]1[/code].
184 </constant>
185 <constant name="MIN" value="Vector2i(-2147483648, -2147483648)">
186 Min vector, a vector with all components equal to [code]INT32_MIN[/code]. Can be used as a negative integer equivalent of [constant Vector2.INF].
187 </constant>
188 <constant name="MAX" value="Vector2i(2147483647, 2147483647)">
189 Max vector, a vector with all components equal to [code]INT32_MAX[/code]. Can be used as an integer equivalent of [constant Vector2.INF].
190 </constant>
191 <constant name="LEFT" value="Vector2i(-1, 0)">
192 Left unit vector. Represents the direction of left.
193 </constant>
194 <constant name="RIGHT" value="Vector2i(1, 0)">
195 Right unit vector. Represents the direction of right.
196 </constant>
197 <constant name="UP" value="Vector2i(0, -1)">
198 Up unit vector. Y is down in 2D, so this vector points -Y.
199 </constant>
200 <constant name="DOWN" value="Vector2i(0, 1)">
201 Down unit vector. Y is down in 2D, so this vector points +Y.
202 </constant>
203 </constants>
204 <operators>
205 <operator name="operator !=">
206 <return type="bool" />
207 <param index="0" name="right" type="Vector2i" />
208 <description>
209 Returns [code]true[/code] if the vectors are not equal.
210 </description>
211 </operator>
212 <operator name="operator %">
213 <return type="Vector2i" />
214 <param index="0" name="right" type="Vector2i" />
215 <description>
216 Gets the remainder of each component of the [Vector2i] with the components of the given [Vector2i]. This operation uses truncated division, which is often not desired as it does not work well with negative numbers. Consider using [method @GlobalScope.posmod] instead if you want to handle negative numbers.
217 [codeblock]
218 print(Vector2i(10, -20) % Vector2i(7, 8)) # Prints (3, -4)
219 [/codeblock]
220 </description>
221 </operator>
222 <operator name="operator %">
223 <return type="Vector2i" />
224 <param index="0" name="right" type="int" />
225 <description>
226 Gets the remainder of each component of the [Vector2i] with the given [int]. This operation uses truncated division, which is often not desired as it does not work well with negative numbers. Consider using [method @GlobalScope.posmod] instead if you want to handle negative numbers.
227 [codeblock]
228 print(Vector2i(10, -20) % 7) # Prints (3, -6)
229 [/codeblock]
230 </description>
231 </operator>
232 <operator name="operator *">
233 <return type="Vector2i" />
234 <param index="0" name="right" type="Vector2i" />
235 <description>
236 Multiplies each component of the [Vector2i] by the components of the given [Vector2i].
237 [codeblock]
238 print(Vector2i(10, 20) * Vector2i(3, 4)) # Prints (30, 80)
239 [/codeblock]
240 </description>
241 </operator>
242 <operator name="operator *">
243 <return type="Vector2" />
244 <param index="0" name="right" type="float" />
245 <description>
246 Multiplies each component of the [Vector2i] by the given [float]. Returns a [Vector2].
247 [codeblock]
248 print(Vector2i(10, 15) * 0.9) # Prints (9.0, 13.5)
249 [/codeblock]
250 </description>
251 </operator>
252 <operator name="operator *">
253 <return type="Vector2i" />
254 <param index="0" name="right" type="int" />
255 <description>
256 Multiplies each component of the [Vector2i] by the given [int].
257 </description>
258 </operator>
259 <operator name="operator +">
260 <return type="Vector2i" />
261 <param index="0" name="right" type="Vector2i" />
262 <description>
263 Adds each component of the [Vector2i] by the components of the given [Vector2i].
264 [codeblock]
265 print(Vector2i(10, 20) + Vector2i(3, 4)) # Prints (13, 24)
266 [/codeblock]
267 </description>
268 </operator>
269 <operator name="operator -">
270 <return type="Vector2i" />
271 <param index="0" name="right" type="Vector2i" />
272 <description>
273 Subtracts each component of the [Vector2i] by the components of the given [Vector2i].
274 [codeblock]
275 print(Vector2i(10, 20) - Vector2i(3, 4)) # Prints (7, 16)
276 [/codeblock]
277 </description>
278 </operator>
279 <operator name="operator /">
280 <return type="Vector2i" />
281 <param index="0" name="right" type="Vector2i" />
282 <description>
283 Divides each component of the [Vector2i] by the components of the given [Vector2i].
284 [codeblock]
285 print(Vector2i(10, 20) / Vector2i(2, 5)) # Prints (5, 4)
286 [/codeblock]
287 </description>
288 </operator>
289 <operator name="operator /">
290 <return type="Vector2" />
291 <param index="0" name="right" type="float" />
292 <description>
293 Divides each component of the [Vector2i] by the given [float]. Returns a [Vector2].
294 [codeblock]
295 print(Vector2i(1, 2) / 2.5) # Prints (0.4, 0.8)
296 [/codeblock]
297 </description>
298 </operator>
299 <operator name="operator /">
300 <return type="Vector2i" />
301 <param index="0" name="right" type="int" />
302 <description>
303 Divides each component of the [Vector2i] by the given [int].
304 </description>
305 </operator>
306 <operator name="operator &lt;">
307 <return type="bool" />
308 <param index="0" name="right" type="Vector2i" />
309 <description>
310 Compares two [Vector2i] vectors by first checking if the X value of the left vector is less than the X value of the [param right] vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors. This operator is useful for sorting vectors.
311 </description>
312 </operator>
313 <operator name="operator &lt;=">
314 <return type="bool" />
315 <param index="0" name="right" type="Vector2i" />
316 <description>
317 Compares two [Vector2i] vectors by first checking if the X value of the left vector is less than or equal to the X value of the [param right] vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors. This operator is useful for sorting vectors.
318 </description>
319 </operator>
320 <operator name="operator ==">
321 <return type="bool" />
322 <param index="0" name="right" type="Vector2i" />
323 <description>
324 Returns [code]true[/code] if the vectors are equal.
325 </description>
326 </operator>
327 <operator name="operator &gt;">
328 <return type="bool" />
329 <param index="0" name="right" type="Vector2i" />
330 <description>
331 Compares two [Vector2i] vectors by first checking if the X value of the left vector is greater than the X value of the [param right] vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors. This operator is useful for sorting vectors.
332 </description>
333 </operator>
334 <operator name="operator &gt;=">
335 <return type="bool" />
336 <param index="0" name="right" type="Vector2i" />
337 <description>
338 Compares two [Vector2i] vectors by first checking if the X value of the left vector is greater than or equal to the X value of the [param right] vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors. This operator is useful for sorting vectors.
339 </description>
340 </operator>
341 <operator name="operator []">
342 <return type="int" />
343 <param index="0" name="index" type="int" />
344 <description>
345 Access vector components using their [param index]. [code]v[0][/code] is equivalent to [code]v.x[/code], and [code]v[1][/code] is equivalent to [code]v.y[/code].
346 </description>
347 </operator>
348 <operator name="operator unary+">
349 <return type="Vector2i" />
350 <description>
351 Returns the same value as if the [code]+[/code] was not there. Unary [code]+[/code] does nothing, but sometimes it can make your code more readable.
352 </description>
353 </operator>
354 <operator name="operator unary-">
355 <return type="Vector2i" />
356 <description>
357 Returns the negative value of the [Vector2i]. This is the same as writing [code]Vector2i(-v.x, -v.y)[/code]. This operation flips the direction of the vector while keeping the same magnitude.
358 </description>
359 </operator>
360 </operators>
361 </class>