Debian Codegraph @

doc/classes/Rect2i.xml

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <class name="Rect2i" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3 <brief_description>
4 A 2D axis-aligned bounding box using integer coordinates.
5 </brief_description>
6 <description>
7 The [Rect2i] built-in [Variant] type represents an axis-aligned rectangle in a 2D space, using integer coordinates. It is defined by its [member position] and [member size], which are [Vector2i]. Because it does not rotate, it is frequently used for fast overlap tests (see [method intersects]).
8 For floating-point coordinates, see [Rect2].
9 [b]Note:[/b] Negative values for [member size] are not supported. With negative size, most [Rect2i] methods do not work correctly. Use [method abs] to get an equivalent [Rect2i] with a non-negative size.
10 [b]Note:[/b] In a boolean context, a [Rect2i] evaluates to [code]false[/code] if both [member position] and [member size] are zero (equal to [constant Vector2i.ZERO]). Otherwise, it always evaluates to [code]true[/code].
11 </description>
12 <tutorials>
13 <link title="Math documentation index">$DOCS_URL/tutorials/math/index.html</link>
14 <link title="Vector math">$DOCS_URL/tutorials/math/vector_math.html</link>
15 </tutorials>
16 <constructors>
17 <constructor name="Rect2i">
18 <return type="Rect2i" />
19 <description>
20 Constructs a [Rect2i] with its [member position] and [member size] set to [constant Vector2i.ZERO].
21 </description>
22 </constructor>
23 <constructor name="Rect2i">
24 <return type="Rect2i" />
25 <param index="0" name="from" type="Rect2i" />
26 <description>
27 Constructs a [Rect2i] as a copy of the given [Rect2i].
28 </description>
29 </constructor>
30 <constructor name="Rect2i">
31 <return type="Rect2i" />
32 <param index="0" name="from" type="Rect2" />
33 <description>
34 Constructs a [Rect2i] from a [Rect2]. The floating-point coordinates are truncated.
35 </description>
36 </constructor>
37 <constructor name="Rect2i">
38 <return type="Rect2i" />
39 <param index="0" name="position" type="Vector2i" />
40 <param index="1" name="size" type="Vector2i" />
41 <description>
42 Constructs a [Rect2i] by [param position] and [param size].
43 </description>
44 </constructor>
45 <constructor name="Rect2i">
46 <return type="Rect2i" />
47 <param index="0" name="x" type="int" />
48 <param index="1" name="y" type="int" />
49 <param index="2" name="width" type="int" />
50 <param index="3" name="height" type="int" />
51 <description>
52 Constructs a [Rect2i] by setting its [member position] to ([param x], [param y]), and its [member size] to ([param width], [param height]).
53 </description>
54 </constructor>
55 </constructors>
56 <methods>
57 <method name="abs" qualifiers="const">
58 <return type="Rect2i" />
59 <description>
60 Returns a [Rect2i] equivalent to this rectangle, with its width and height modified to be non-negative values, and with its [member position] being the top-left corner of the rectangle.
61 [codeblocks]
62 [gdscript]
63 var rect = Rect2i(25, 25, -100, -50)
64 var absolute = rect.abs() # absolute is Rect2i(-75, -25, 100, 50)
65 [/gdscript]
66 [csharp]
67 var rect = new Rect2I(25, 25, -100, -50);
68 var absolute = rect.Abs(); // absolute is Rect2I(-75, -25, 100, 50)
69 [/csharp]
70 [/codeblocks]
71 [b]Note:[/b] It's recommended to use this method when [member size] is negative, as most other methods in Godot assume that the [member position] is the top-left corner, and the [member end] is the bottom-right corner.
72 </description>
73 </method>
74 <method name="encloses" qualifiers="const">
75 <return type="bool" />
76 <param index="0" name="b" type="Rect2i" />
77 <description>
78 Returns [code]true[/code] if this [Rect2i] completely encloses another one.
79 </description>
80 </method>
81 <method name="expand" qualifiers="const">
82 <return type="Rect2i" />
83 <param index="0" name="to" type="Vector2i" />
84 <description>
85 Returns a copy of this rectangle expanded to align the edges with the given [param to] point, if necessary.
86 [codeblocks]
87 [gdscript]
88 var rect = Rect2i(0, 0, 5, 2)
89
90 rect = rect.expand(Vector2i(10, 0)) # rect is Rect2i(0, 0, 10, 2)
91 rect = rect.expand(Vector2i(-5, 5)) # rect is Rect2i(-5, 0, 15, 5)
92 [/gdscript]
93 [csharp]
94 var rect = new Rect2I(0, 0, 5, 2);
95
96 rect = rect.Expand(new Vector2I(10, 0)); // rect is Rect2I(0, 0, 10, 2)
97 rect = rect.Expand(new Vector2I(-5, 5)); // rect is Rect2I(-5, 0, 15, 5)
98 [/csharp]
99 [/codeblocks]
100 </description>
101 </method>
102 <method name="get_area" qualifiers="const">
103 <return type="int" />
104 <description>
105 Returns the rectangle's area. This is equivalent to [code]size.x * size.y[/code]. See also [method has_area].
106 </description>
107 </method>
108 <method name="get_center" qualifiers="const">
109 <return type="Vector2i" />
110 <description>
111 Returns the center point of the rectangle. This is the same as [code]position + (size / 2)[/code].
112 [b]Note:[/b] If the [member size] is odd, the result will be rounded towards [member position].
113 </description>
114 </method>
115 <method name="grow" qualifiers="const">
116 <return type="Rect2i" />
117 <param index="0" name="amount" type="int" />
118 <description>
119 Returns a copy of this rectangle extended on all sides by the given [param amount]. A negative [param amount] shrinks the rectangle instead. See also [method grow_individual] and [method grow_side].
120 [codeblocks]
121 [gdscript]
122 var a = Rect2i(4, 4, 8, 8).grow(4) # a is Rect2i(0, 0, 16, 16)
123 var b = Rect2i(0, 0, 8, 4).grow(2) # b is Rect2i(-2, -2, 12, 8)
124 [/gdscript]
125 [csharp]
126 var a = new Rect2I(4, 4, 8, 8).Grow(4); // a is Rect2I(0, 0, 16, 16)
127 var b = new Rect2I(0, 0, 8, 4).Grow(2); // b is Rect2I(-2, -2, 12, 8)
128 [/csharp]
129 [/codeblocks]
130 </description>
131 </method>
132 <method name="grow_individual" qualifiers="const">
133 <return type="Rect2i" />
134 <param index="0" name="left" type="int" />
135 <param index="1" name="top" type="int" />
136 <param index="2" name="right" type="int" />
137 <param index="3" name="bottom" type="int" />
138 <description>
139 Returns a copy of this rectangle with its [param left], [param top], [param right], and [param bottom] sides extended by the given amounts. Negative values shrink the sides, instead. See also [method grow] and [method grow_side].
140 </description>
141 </method>
142 <method name="grow_side" qualifiers="const">
143 <return type="Rect2i" />
144 <param index="0" name="side" type="int" />
145 <param index="1" name="amount" type="int" />
146 <description>
147 Returns a copy of this rectangle with its [param side] extended by the given [param amount] (see [enum Side] constants). A negative [param amount] shrinks the rectangle, instead. See also [method grow] and [method grow_individual].
148 </description>
149 </method>
150 <method name="has_area" qualifiers="const">
151 <return type="bool" />
152 <description>
153 Returns [code]true[/code] if this rectangle has positive width and height. See also [method get_area].
154 </description>
155 </method>
156 <method name="has_point" qualifiers="const">
157 <return type="bool" />
158 <param index="0" name="point" type="Vector2i" />
159 <description>
160 Returns [code]true[/code] if the rectangle contains the given [param point]. By convention, points on the right and bottom edges are [b]not[/b] included.
161 [b]Note:[/b] This method is not reliable for [Rect2i] with a [i]negative[/i] [member size]. Use [method abs] first to get a valid rectangle.
162 </description>
163 </method>
164 <method name="intersection" qualifiers="const">
165 <return type="Rect2i" />
166 <param index="0" name="b" type="Rect2i" />
167 <description>
168 Returns the intersection between this rectangle and [param b]. If the rectangles do not intersect, returns an empty [Rect2i].
169 [codeblocks]
170 [gdscript]
171 var a = Rect2i(0, 0, 5, 10)
172 var b = Rect2i(2, 0, 8, 4)
173
174 var c = a.intersection(b) # c is Rect2i(2, 0, 3, 4)
175 [/gdscript]
176 [csharp]
177 var a = new Rect2I(0, 0, 5, 10);
178 var b = new Rect2I(2, 0, 8, 4);
179
180 var c = rect1.Intersection(rect2); // c is Rect2I(2, 0, 3, 4)
181 [/csharp]
182 [/codeblocks]
183 [b]Note:[/b] If you only need to know whether two rectangles are overlapping, use [method intersects], instead.
184 </description>
185 </method>
186 <method name="intersects" qualifiers="const">
187 <return type="bool" />
188 <param index="0" name="b" type="Rect2i" />
189 <description>
190 Returns [code]true[/code] if this rectangle overlaps with the [param b] rectangle. The edges of both rectangles are excluded.
191 </description>
192 </method>
193 <method name="merge" qualifiers="const">
194 <return type="Rect2i" />
195 <param index="0" name="b" type="Rect2i" />
196 <description>
197 Returns a [Rect2i] that encloses both this rectangle and [param b] around the edges. See also [method encloses].
198 </description>
199 </method>
200 </methods>
201 <members>
202 <member name="end" type="Vector2i" setter="" getter="" default="Vector2i(0, 0)">
203 The ending point. This is usually the bottom-right corner of the rectangle, and is equivalent to [code]position + size[/code]. Setting this point affects the [member size].
204 </member>
205 <member name="position" type="Vector2i" setter="" getter="" default="Vector2i(0, 0)">
206 The origin point. This is usually the top-left corner of the rectangle.
207 </member>
208 <member name="size" type="Vector2i" setter="" getter="" default="Vector2i(0, 0)">
209 The rectangle's width and height, starting from [member position]. Setting this value also affects the [member end] point.
210 [b]Note:[/b] It's recommended setting the width and height to non-negative values, as most methods in Godot assume that the [member position] is the top-left corner, and the [member end] is the bottom-right corner. To get an equivalent rectangle with non-negative size, use [method abs].
211 </member>
212 </members>
213 <operators>
214 <operator name="operator !=">
215 <return type="bool" />
216 <param index="0" name="right" type="Rect2i" />
217 <description>
218 Returns [code]true[/code] if the [member position] or [member size] of both rectangles are not equal.
219 </description>
220 </operator>
221 <operator name="operator ==">
222 <return type="bool" />
223 <param index="0" name="right" type="Rect2i" />
224 <description>
225 Returns [code]true[/code] if both [member position] and [member size] of the rectangles are equal, respectively.
226 </description>
227 </operator>
228 </operators>
229 </class>