2017-09-12 22:42:36 +02:00
<?xml version="1.0" encoding="UTF-8" ?>
2023-07-06 10:08:05 +02:00
<class name= "Rect2" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation= "../class.xsd" >
2017-09-12 22:42:36 +02:00
<brief_description >
2023-04-28 01:35:33 +02:00
A 2D axis-aligned bounding box using floating-point coordinates.
2017-09-12 22:42:36 +02:00
</brief_description>
<description >
2022-12-09 10:24:06 +01:00
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.
For integer coordinates, use [Rect2i]. The 3D equivalent to [Rect2] is [AABB].
[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.
[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].
2017-09-12 22:42:36 +02:00
</description>
<tutorials >
2021-11-15 10:43:07 +01:00
<link title= "Math documentation index" > $DOCS_URL/tutorials/math/index.html</link>
<link title= "Vector math" > $DOCS_URL/tutorials/math/vector_math.html</link>
<link title= "Advanced vector math" > $DOCS_URL/tutorials/math/vectors_advanced.html</link>
2017-09-12 22:42:36 +02:00
</tutorials>
2021-09-21 04:49:02 +02:00
<constructors >
<constructor name= "Rect2" >
2021-07-30 15:28:05 +02:00
<return type= "Rect2" />
2020-11-09 17:46:03 +01:00
<description >
2022-12-09 10:24:06 +01:00
Constructs a [Rect2] with its [member position] and [member size] set to [constant Vector2.ZERO].
2020-11-09 17:46:03 +01:00
</description>
2021-09-21 04:49:02 +02:00
</constructor>
<constructor name= "Rect2" >
2021-07-30 15:28:05 +02:00
<return type= "Rect2" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "from" type= "Rect2" />
2020-11-09 17:46:03 +01:00
<description >
Constructs a [Rect2] as a copy of the given [Rect2].
</description>
2021-09-21 04:49:02 +02:00
</constructor>
<constructor name= "Rect2" >
2021-07-30 15:28:05 +02:00
<return type= "Rect2" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "from" type= "Rect2i" />
2020-11-09 17:46:03 +01:00
<description >
Constructs a [Rect2] from a [Rect2i].
</description>
2021-09-21 04:49:02 +02:00
</constructor>
<constructor name= "Rect2" >
2021-07-30 15:28:05 +02:00
<return type= "Rect2" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "position" type= "Vector2" />
<param index= "1" name= "size" type= "Vector2" />
2017-09-12 22:42:36 +02:00
<description >
2022-12-09 10:24:06 +01:00
Constructs a [Rect2] by [param position] and [param size].
2017-09-12 22:42:36 +02:00
</description>
2021-09-21 04:49:02 +02:00
</constructor>
<constructor name= "Rect2" >
2021-07-30 15:28:05 +02:00
<return type= "Rect2" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "x" type= "float" />
<param index= "1" name= "y" type= "float" />
<param index= "2" name= "width" type= "float" />
<param index= "3" name= "height" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2022-12-09 10:24:06 +01:00
Constructs a [Rect2] by setting its [member position] to ([param x], [param y]), and its [member size] to ([param width], [param height]).
2017-09-12 22:42:36 +02:00
</description>
2021-09-21 04:49:02 +02:00
</constructor>
</constructors>
<methods >
2021-03-18 14:44:42 +01:00
<method name= "abs" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "Rect2" />
2017-12-10 00:43:30 +01:00
<description >
2022-12-09 10:24:06 +01:00
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.
[codeblocks]
[gdscript]
var rect = Rect2(25, 25, -100, -50)
var absolute = rect.abs() # absolute is Rect2(-75, -25, 100, 50)
[/gdscript]
[csharp]
var rect = new Rect2(25, 25, -100, -50);
var absolute = rect.Abs(); // absolute is Rect2(-75, -25, 100, 50)
[/csharp]
[/codeblocks]
[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.
2017-12-10 00:43:30 +01:00
</description>
</method>
2021-03-18 14:44:42 +01:00
<method name= "encloses" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "b" type= "Rect2" />
2017-09-12 22:42:36 +02:00
<description >
2022-12-09 10:24:06 +01:00
Returns [code]true[/code] if this rectangle [i]completely[/i] encloses the [param b] rectangle.
2017-09-12 22:42:36 +02:00
</description>
</method>
2021-03-18 14:44:42 +01:00
<method name= "expand" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "Rect2" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "to" type= "Vector2" />
2017-09-12 22:42:36 +02:00
<description >
2023-08-03 14:59:07 +02:00
Returns a copy of this rectangle expanded to align the edges with the given [param to] point, if necessary.
2021-11-11 11:31:30 +01:00
[codeblocks]
[gdscript]
2022-12-09 10:24:06 +01:00
var rect = Rect2(0, 0, 5, 2)
rect = rect.expand(Vector2(10, 0)) # rect is Rect2(0, 0, 10, 2)
rect = rect.expand(Vector2(-5, 5)) # rect is Rect2(-5, 0, 10, 5)
2021-11-11 11:31:30 +01:00
[/gdscript]
[csharp]
2022-12-09 10:24:06 +01:00
var rect = new Rect2(0, 0, 5, 2);
rect = rect.Expand(new Vector2(10, 0)); // rect is Rect2(0, 0, 10, 2)
rect = rect.Expand(new Vector2(-5, 5)); // rect is Rect2(-5, 0, 10, 5)
2021-11-11 11:31:30 +01:00
[/csharp]
[/codeblocks]
2017-09-12 22:42:36 +02:00
</description>
</method>
2021-03-18 14:44:42 +01:00
<method name= "get_area" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2022-12-09 10:24:06 +01:00
Returns the rectangle's area. This is equivalent to [code]size.x * size.y[/code]. See also [method has_area].
2017-09-12 22:42:36 +02:00
</description>
</method>
2021-09-20 20:48:52 +02:00
<method name= "get_center" qualifiers= "const" >
<return type= "Vector2" />
<description >
2022-12-09 10:24:06 +01:00
Returns the center point of the rectangle. This is the same as [code]position + (size / 2.0)[/code].
2021-09-20 20:48:52 +02:00
</description>
</method>
2021-03-18 14:44:42 +01:00
<method name= "grow" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "Rect2" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "amount" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2022-12-09 10:24:06 +01:00
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].
[codeblocks]
[gdscript]
var a = Rect2(4, 4, 8, 8).grow(4) # a is Rect2(0, 0, 16, 16)
var b = Rect2(0, 0, 8, 4).grow(2) # b is Rect2(-2, -2, 12, 8)
[/gdscript]
[csharp]
var a = new Rect2(4, 4, 8, 8).Grow(4); // a is Rect2(0, 0, 16, 16)
var b = new Rect2(0, 0, 8, 4).Grow(2); // b is Rect2(-2, -2, 12, 8)
[/csharp]
[/codeblocks]
2017-09-12 22:42:36 +02:00
</description>
</method>
2021-03-18 14:44:42 +01:00
<method name= "grow_individual" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "Rect2" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "left" type= "float" />
<param index= "1" name= "top" type= "float" />
<param index= "2" name= "right" type= "float" />
<param index= "3" name= "bottom" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2022-12-09 10:24:06 +01:00
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].
2017-09-12 22:42:36 +02:00
</description>
</method>
2021-03-18 14:44:42 +01:00
<method name= "grow_side" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "Rect2" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "side" type= "int" />
<param index= "1" name= "amount" type= "float" />
2017-09-12 22:42:36 +02:00
<description >
2022-12-09 10:24:06 +01:00
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].
2017-09-12 22:42:36 +02:00
</description>
</method>
2022-08-15 04:51:45 +02:00
<method name= "has_area" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
2017-09-12 22:42:36 +02:00
<description >
2022-12-09 10:24:06 +01:00
Returns [code]true[/code] if this rectangle has positive width and height. See also [method get_area].
2017-09-12 22:42:36 +02:00
</description>
</method>
2021-03-18 14:44:42 +01:00
<method name= "has_point" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "point" type= "Vector2" />
2017-09-12 22:42:36 +02:00
<description >
2022-12-09 10:24:06 +01:00
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.
[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.
2017-09-12 22:42:36 +02:00
</description>
</method>
2021-03-18 14:44:42 +01:00
<method name= "intersection" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "Rect2" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "b" type= "Rect2" />
2021-01-04 14:33:44 +01:00
<description >
2022-12-09 10:24:06 +01:00
Returns the intersection between this rectangle and [param b]. If the rectangles do not intersect, returns an empty [Rect2].
[codeblocks]
[gdscript]
var rect1 = Rect2(0, 0, 5, 10)
var rect2 = Rect2(2, 0, 8, 4)
var a = rect1.intersection(rect2) # a is Rect2(2, 0, 3, 4)
[/gdscript]
[csharp]
var rect1 = new Rect2(0, 0, 5, 10);
var rect2 = new Rect2(2, 0, 8, 4);
var a = rect1.Intersection(rect2); // a is Rect2(2, 0, 3, 4)
[/csharp]
[/codeblocks]
[b]Note:[/b] If you only need to know whether two rectangles are overlapping, use [method intersects], instead.
2021-01-04 14:33:44 +01:00
</description>
</method>
2021-03-18 14:44:42 +01:00
<method name= "intersects" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "b" type= "Rect2" />
<param index= "1" name= "include_borders" type= "bool" default= "false" />
2017-09-12 22:42:36 +02:00
<description >
2022-12-09 10:24:06 +01:00
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].
2017-09-12 22:42:36 +02:00
</description>
</method>
2021-03-18 14:44:42 +01:00
<method name= "is_equal_approx" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "rect" type= "Rect2" />
2019-11-08 08:33:48 +01:00
<description >
2022-12-09 10:24:06 +01:00
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].
2019-11-08 08:33:48 +01:00
</description>
</method>
2022-08-11 10:12:27 +02:00
<method name= "is_finite" qualifiers= "const" >
<return type= "bool" />
<description >
2022-12-09 10:24:06 +01:00
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].
2022-08-11 10:12:27 +02:00
</description>
</method>
2021-03-18 14:44:42 +01:00
<method name= "merge" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "Rect2" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "b" type= "Rect2" />
2017-09-12 22:42:36 +02:00
<description >
2022-12-09 10:24:06 +01:00
Returns a [Rect2] that encloses both this rectangle and [param b] around the edges. See also [method encloses].
2017-09-12 22:42:36 +02:00
</description>
</method>
2021-09-21 04:49:02 +02:00
</methods>
<members >
<member name= "end" type= "Vector2" setter= "" getter= "" default= "Vector2(0, 0)" >
2022-12-09 10:24:06 +01:00
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].
2021-09-21 04:49:02 +02:00
</member>
<member name= "position" type= "Vector2" setter= "" getter= "" default= "Vector2(0, 0)" >
2022-12-09 10:24:06 +01:00
The origin point. This is usually the top-left corner of the rectangle.
2021-09-21 04:49:02 +02:00
</member>
<member name= "size" type= "Vector2" setter= "" getter= "" default= "Vector2(0, 0)" >
2022-12-09 10:24:06 +01:00
The rectangle's width and height, starting from [member position]. Setting this value also affects the [member end] point.
[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].
2021-09-21 04:49:02 +02:00
</member>
</members>
<operators >
<operator name= "operator !=" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "right" type= "Rect2" />
2020-11-10 14:16:20 +01:00
<description >
2022-12-09 10:24:06 +01:00
Returns [code]true[/code] if the [member position] or [member size] of both rectangles are not equal.
2021-11-04 16:58:20 +01:00
[b]Note:[/b] Due to floating-point precision errors, consider using [method is_equal_approx] instead, which is more reliable.
2020-11-10 14:16:20 +01:00
</description>
2021-09-21 04:49:02 +02:00
</operator>
<operator name= "operator *" >
2021-07-30 15:28:05 +02:00
<return type= "Rect2" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "right" type= "Transform2D" />
2020-11-10 14:16:20 +01:00
<description >
2021-11-04 16:58:20 +01:00
Inversely transforms (multiplies) the [Rect2] by the given [Transform2D] transformation matrix.
2020-11-10 14:16:20 +01:00
</description>
2021-09-21 04:49:02 +02:00
</operator>
<operator name= "operator ==" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "right" type= "Rect2" />
2020-11-10 14:16:20 +01:00
<description >
2022-12-09 10:24:06 +01:00
Returns [code]true[/code] if both [member position] and [member size] of the rectangles are exactly equal, respectively.
2021-11-04 16:58:20 +01:00
[b]Note:[/b] Due to floating-point precision errors, consider using [method is_equal_approx] instead, which is more reliable.
2020-11-10 14:16:20 +01:00
</description>
2021-09-21 04:49:02 +02:00
</operator>
</operators>
2017-09-12 22:42:36 +02:00
</class>