Debian Codegraph @

doc/classes/Rect2.xml

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <class name="Rect2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3 <brief_description>
4 A 2D axis-aligned bounding box using floating-point coordinates.
5 </brief_description>
6 <description>
7 The [Rect2] built-in [Variant] type represents an axis-aligned rectangle in a 2D space. It is defined by its [member position] and [member size], which are [Vector2]. It is frequently used for fast overlap tests (see [method intersects]). Although [Rect2] itself is axis-aligned, it can be combined with [Transform2D] to represent a rotated or skewed rectangle.
8 For integer coordinates, use [Rect2i]. The 3D equivalent to [Rect2] is [AABB].
9 [b]Note:[/b] Negative values for [member size] are not supported. With negative size, most [Rect2] methods do not work correctly. Use [method abs] to get an equivalent [Rect2] with a non-negative size.
10 [b]Note:[/b] In a boolean context, a [Rect2] evaluates to [code]false[/code] if both [member position] and [member size] are zero (equal to [constant Vector2.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 <link title="Advanced vector math">$DOCS_URL/tutorials/math/vectors_advanced.html</link>
16 </tutorials>
17 <constructors>
18 <constructor name="Rect2">
19 <return type="Rect2" />
20 <description>
21 Constructs a [Rect2] with its [member position] and [member size] set to [constant Vector2.ZERO].
22 </description>
23 </constructor>
24 <constructor name="Rect2">
25 <return type="Rect2" />
26 <param index="0" name="from" type="Rect2" />
27 <description>
28 Constructs a [Rect2] as a copy of the given [Rect2].
29 </description>
30 </constructor>
31 <constructor name="Rect2">
32 <return type="Rect2" />
33 <param index="0" name="from" type="Rect2i" />
34 <description>
35 Constructs a [Rect2] from a [Rect2i].
36 </description>
37 </constructor>
38 <constructor name="Rect2">
39 <return type="Rect2" />
40 <param index="0" name="position" type="Vector2" />
41 <param index="1" name="size" type="Vector2" />
42 <description>
43 Constructs a [Rect2] by [param position] and [param size].
44 </description>
45 </constructor>
46 <constructor name="Rect2">
47 <return type="Rect2" />
48 <param index="0" name="x" type="float" />
49 <param index="1" name="y" type="float" />
50 <param index="2" name="width" type="float" />
51 <param index="3" name="height" type="float" />
52 <description>
53 Constructs a [Rect2] by setting its [member position] to ([param x], [param y]), and its [member size] to ([param width], [param height]).
54 </description>
55 </constructor>
56 </constructors>
57 <methods>
58 <method name="abs" qualifiers="const">
59 <return type="Rect2" />
60 <description>
61 Returns a [Rect2] 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.
62 [codeblocks]
63 [gdscript]
64 var rect = Rect2(25, 25, -100, -50)
65 var absolute = rect.abs() # absolute is Rect2(-75, -25, 100, 50)
66 [/gdscript]
67 [csharp]
68 var rect = new Rect2(25, 25, -100, -50);
69 var absolute = rect.Abs(); // absolute is Rect2(-75, -25, 100, 50)
70 [/csharp]
71 [/codeblocks]
72 [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.
73 </description>
74 </method>
75 <method name="encloses" qualifiers="const">
76 <return type="bool" />
77 <param index="0" name="b" type="Rect2" />
78 <description>
79 Returns [code]true[/code] if this rectangle [i]completely[/i] encloses the [param b] rectangle.
80 </description>
81 </method>
82 <method name="expand" qualifiers="const">
83 <return type="Rect2" />
84 <param index="0" name="to" type="Vector2" />
85 <description>
86 Returns a copy of this rectangle expanded to align the edges with the given [param to] point, if necessary.
87 [codeblocks]
88 [gdscript]
89 var rect = Rect2(0, 0, 5, 2)
90
91 rect = rect.expand(Vector2(10, 0)) # rect is Rect2(0, 0, 10, 2)
92 rect = rect.expand(Vector2(-5, 5)) # rect is Rect2(-5, 0, 15, 5)
93 [/gdscript]
94 [csharp]
95 var rect = new Rect2(0, 0, 5, 2);
96
97 rect = rect.Expand(new Vector2(10, 0)); // rect is Rect2(0, 0, 10, 2)
98 rect = rect.Expand(new Vector2(-5, 5)); // rect is Rect2(-5, 0, 15, 5)
99 [/csharp]
100 [/codeblocks]
101 </description>
102 </method>
103 <method name="get_area" qualifiers="const">
104 <return type="float" />
105 <description>
106 Returns the rectangle's area. This is equivalent to [code]size.x * size.y[/code]. See also [method has_area].
107 </description>
108 </method>
109 <method name="get_center" qualifiers="const">
110 <return type="Vector2" />
111 <description>
112 Returns the center point of the rectangle. This is the same as [code]position + (size / 2.0)[/code].
113 </description>
114 </method>
115 <method name="get_support" qualifiers="const">
116 <return type="Vector2" />
117 <param index="0" name="direction" type="Vector2" />
118 <description>
119 Returns the vertex's position of this rect that's the farthest in the given direction. This point is commonly known as the support point in collision detection algorithms.
120 </description>
121 </method>
122 <method name="grow" qualifiers="const">
123 <return type="Rect2" />
124 <param index="0" name="amount" type="float" />
125 <description>
126 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].
127 [codeblocks]
128 [gdscript]
129 var a = Rect2(4, 4, 8, 8).grow(4) # a is Rect2(0, 0, 16, 16)
130 var b = Rect2(0, 0, 8, 4).grow(2) # b is Rect2(-2, -2, 12, 8)
131 [/gdscript]
132 [csharp]
133 var a = new Rect2(4, 4, 8, 8).Grow(4); // a is Rect2(0, 0, 16, 16)
134 var b = new Rect2(0, 0, 8, 4).Grow(2); // b is Rect2(-2, -2, 12, 8)
135 [/csharp]
136 [/codeblocks]
137 </description>
138 </method>
139 <method name="grow_individual" qualifiers="const">
140 <return type="Rect2" />
141 <param index="0" name="left" type="float" />
142 <param index="1" name="top" type="float" />
143 <param index="2" name="right" type="float" />
144 <param index="3" name="bottom" type="float" />
145 <description>
146 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].
147 </description>
148 </method>
149 <method name="grow_side" qualifiers="const">
150 <return type="Rect2" />
151 <param index="0" name="side" type="int" />
152 <param index="1" name="amount" type="float" />
153 <description>
154 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].
155 </description>
156 </method>
157 <method name="has_area" qualifiers="const">
158 <return type="bool" />
159 <description>
160 Returns [code]true[/code] if this rectangle has positive width and height. See also [method get_area].
161 </description>
162 </method>
163 <method name="has_point" qualifiers="const">
164 <return type="bool" />
165 <param index="0" name="point" type="Vector2" />
166 <description>
167 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.
168 [b]Note:[/b] This method is not reliable for [Rect2] with a [i]negative[/i] [member size]. Use [method abs] first to get a valid rectangle.
169 </description>
170 </method>
171 <method name="intersection" qualifiers="const">
172 <return type="Rect2" />
173 <param index="0" name="b" type="Rect2" />
174 <description>
175 Returns the intersection between this rectangle and [param b]. If the rectangles do not intersect, returns an empty [Rect2].
176 [codeblocks]
177 [gdscript]
178 var rect1 = Rect2(0, 0, 5, 10)
179 var rect2 = Rect2(2, 0, 8, 4)
180
181 var a = rect1.intersection(rect2) # a is Rect2(2, 0, 3, 4)
182 [/gdscript]
183 [csharp]
184 var rect1 = new Rect2(0, 0, 5, 10);
185 var rect2 = new Rect2(2, 0, 8, 4);
186
187 var a = rect1.Intersection(rect2); // a is Rect2(2, 0, 3, 4)
188 [/csharp]
189 [/codeblocks]
190 [b]Note:[/b] If you only need to know whether two rectangles are overlapping, use [method intersects], instead.
191 </description>
192 </method>
193 <method name="intersects" qualifiers="const">
194 <return type="bool" />
195 <param index="0" name="b" type="Rect2" />
196 <param index="1" name="include_borders" type="bool" default="false" />
197 <description>
198 Returns [code]true[/code] if this rectangle overlaps with the [param b] rectangle. The edges of both rectangles are excluded, unless [param include_borders] is [code]true[/code].
199 </description>
200 </method>
201 <method name="is_equal_approx" qualifiers="const">
202 <return type="bool" />
203 <param index="0" name="rect" type="Rect2" />
204 <description>
205 Returns [code]true[/code] if this rectangle and [param rect] are approximately equal, by calling [method Vector2.is_equal_approx] on the [member position] and the [member size].
206 </description>
207 </method>
208 <method name="is_finite" qualifiers="const">
209 <return type="bool" />
210 <description>
211 Returns [code]true[/code] if this rectangle's values are finite, by calling [method Vector2.is_finite] on the [member position] and the [member size].
212 </description>
213 </method>
214 <method name="merge" qualifiers="const">
215 <return type="Rect2" />
216 <param index="0" name="b" type="Rect2" />
217 <description>
218 Returns a [Rect2] that encloses both this rectangle and [param b] around the edges. See also [method encloses].
219 </description>
220 </method>
221 </methods>
222 <members>
223 <member name="end" type="Vector2" setter="" getter="" default="Vector2(0, 0)">
224 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].
225 </member>
226 <member name="position" type="Vector2" setter="" getter="" default="Vector2(0, 0)">
227 The origin point. This is usually the top-left corner of the rectangle.
228 </member>
229 <member name="size" type="Vector2" setter="" getter="" default="Vector2(0, 0)">
230 The rectangle's width and height, starting from [member position]. Setting this value also affects the [member end] point.
231 [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].
232 </member>
233 </members>
234 <operators>
235 <operator name="operator !=">
236 <return type="bool" />
237 <param index="0" name="right" type="Rect2" />
238 <description>
239 Returns [code]true[/code] if the [member position] or [member size] of both rectangles are not equal.
240 [b]Note:[/b] Due to floating-point precision errors, consider using [method is_equal_approx] instead, which is more reliable.
241 </description>
242 </operator>
243 <operator name="operator *">
244 <return type="Rect2" />
245 <param index="0" name="right" type="Transform2D" />
246 <description>
247 Inversely transforms (multiplies) the [Rect2] by the given [Transform2D] transformation matrix, under the assumption that the transformation basis is orthonormal (i.e. rotation/reflection is fine, scaling/skew is not).
248 [code]rect * transform[/code] is equivalent to [code]transform.inverse() * rect[/code]. See [method Transform2D.inverse].
249 For transforming by inverse of an affine transformation (e.g. with scaling) [code]transform.affine_inverse() * rect[/code] can be used instead. See [method Transform2D.affine_inverse].
250 </description>
251 </operator>
252 <operator name="operator ==">
253 <return type="bool" />
254 <param index="0" name="right" type="Rect2" />
255 <description>
256 Returns [code]true[/code] if both [member position] and [member size] of the rectangles are exactly equal, respectively.
257 [b]Note:[/b] Due to floating-point precision errors, consider using [method is_equal_approx] instead, which is more reliable.
258 </description>
259 </operator>
260 </operators>
261 </class>