2017-09-12 20:42:36 +00:00
<?xml version="1.0" encoding="UTF-8" ?>
2023-07-05 20:07:03 +00:00
<class name= "Rect2" version= "4.2" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation= "../class.xsd" >
2017-09-12 20:42:36 +00:00
<brief_description >
2023-04-27 23:35:33 +00:00
A 2D axis-aligned bounding box using floating-point coordinates.
2017-09-12 20:42:36 +00:00
</brief_description>
<description >
2020-02-24 16:00:40 +00:00
[Rect2] consists of a position, a size, and several utility functions. It is typically used for fast overlap tests.
2020-09-21 12:27:50 +00:00
It uses floating-point coordinates. If you need integer coordinates, use [Rect2i] instead.
The 3D counterpart to [Rect2] is [AABB].
2020-04-06 08:34:18 +00:00
Negative values for [member size] are not supported and will not work for most methods. Use [method abs] to get a Rect2 with a positive size.
2017-09-12 20:42:36 +00:00
</description>
<tutorials >
2021-11-15 09:43:07 +00: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 20:42:36 +00:00
</tutorials>
2021-09-21 02:49:02 +00:00
<constructors >
<constructor name= "Rect2" >
2021-07-30 13:28:05 +00:00
<return type= "Rect2" />
2020-11-09 16:46:03 +00:00
<description >
Constructs a default-initialized [Rect2] with default (zero) values of [member position] and [member size].
</description>
2021-09-21 02:49:02 +00:00
</constructor>
<constructor name= "Rect2" >
2021-07-30 13:28:05 +00:00
<return type= "Rect2" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "from" type= "Rect2" />
2020-11-09 16:46:03 +00:00
<description >
Constructs a [Rect2] as a copy of the given [Rect2].
</description>
2021-09-21 02:49:02 +00:00
</constructor>
<constructor name= "Rect2" >
2021-07-30 13:28:05 +00:00
<return type= "Rect2" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "from" type= "Rect2i" />
2020-11-09 16:46:03 +00:00
<description >
Constructs a [Rect2] from a [Rect2i].
</description>
2021-09-21 02:49:02 +00:00
</constructor>
<constructor name= "Rect2" >
2021-07-30 13:28:05 +00:00
<return type= "Rect2" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "position" type= "Vector2" />
<param index= "1" name= "size" type= "Vector2" />
2017-09-12 20:42:36 +00:00
<description >
2019-03-29 22:37:35 +00:00
Constructs a [Rect2] by position and size.
2017-09-12 20:42:36 +00:00
</description>
2021-09-21 02:49:02 +00:00
</constructor>
<constructor name= "Rect2" >
2021-07-30 13:28:05 +00:00
<return type= "Rect2" />
2022-08-06 18:11:48 +00: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 20:42:36 +00:00
<description >
2019-03-29 22:37:35 +00:00
Constructs a [Rect2] by x, y, width, and height.
2017-09-12 20:42:36 +00:00
</description>
2021-09-21 02:49:02 +00:00
</constructor>
</constructors>
<methods >
2021-03-18 13:44:42 +00:00
<method name= "abs" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "Rect2" />
2017-12-09 23:43:30 +00:00
<description >
2019-03-29 22:37:35 +00:00
Returns a [Rect2] with equivalent position and area, modified so that the top-left corner is the origin and [code]width[/code] and [code]height[/code] are positive.
2017-12-09 23:43:30 +00:00
</description>
</method>
2021-03-18 13:44:42 +00:00
<method name= "encloses" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "bool" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "b" type= "Rect2" />
2017-09-12 20:42:36 +00:00
<description >
2019-03-29 22:37:35 +00:00
Returns [code]true[/code] if this [Rect2] completely encloses another one.
2017-09-12 20:42:36 +00:00
</description>
</method>
2021-03-18 13:44:42 +00:00
<method name= "expand" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "Rect2" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "to" type= "Vector2" />
2017-09-12 20:42:36 +00:00
<description >
2021-11-11 10:31:30 +00:00
Returns a copy of this [Rect2] expanded to include a given point.
[b]Example:[/b]
[codeblocks]
[gdscript]
# position (-3, 2), size (1, 1)
var rect = Rect2(Vector2(-3, 2), Vector2(1, 1))
# position (-3, -1), size (3, 4), so we fit both rect and Vector2(0, -1)
var rect2 = rect.expand(Vector2(0, -1))
[/gdscript]
[csharp]
2022-11-18 14:41:44 +00:00
// position (-3, 2), size (1, 1)
2021-11-11 10:31:30 +00:00
var rect = new Rect2(new Vector2(-3, 2), new Vector2(1, 1));
2022-11-18 14:41:44 +00:00
// position (-3, -1), size (3, 4), so we fit both rect and Vector2(0, -1)
2021-11-11 10:31:30 +00:00
var rect2 = rect.Expand(new Vector2(0, -1));
[/csharp]
[/codeblocks]
2017-09-12 20:42:36 +00:00
</description>
</method>
2021-03-18 13:44:42 +00:00
<method name= "get_area" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "float" />
2017-09-12 20:42:36 +00:00
<description >
2022-08-15 02:51:45 +00:00
Returns the area of the [Rect2]. See also [method has_area].
2017-09-12 20:42:36 +00:00
</description>
</method>
2021-09-20 18:48:52 +00:00
<method name= "get_center" qualifiers= "const" >
<return type= "Vector2" />
<description >
Returns the center of the [Rect2], which is equal to [member position] + ([member size] / 2).
</description>
</method>
2021-03-18 13:44:42 +00:00
<method name= "grow" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "Rect2" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "amount" type= "float" />
2017-09-12 20:42:36 +00:00
<description >
2022-08-11 17:52:19 +00:00
Returns a copy of the [Rect2] grown by the specified [param amount] on all sides.
2017-09-12 20:42:36 +00:00
</description>
</method>
2021-03-18 13:44:42 +00:00
<method name= "grow_individual" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "Rect2" />
2022-08-06 18:11:48 +00: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 20:42:36 +00:00
<description >
2020-12-28 09:11:58 +00:00
Returns a copy of the [Rect2] grown by the specified amount on each side individually.
2017-09-12 20:42:36 +00:00
</description>
</method>
2021-03-18 13:44:42 +00:00
<method name= "grow_side" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "Rect2" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "side" type= "int" />
<param index= "1" name= "amount" type= "float" />
2017-09-12 20:42:36 +00:00
<description >
2022-08-11 17:52:19 +00:00
Returns a copy of the [Rect2] grown by the specified [param amount] on the specified [enum Side].
2017-09-12 20:42:36 +00:00
</description>
</method>
2022-08-15 02:51:45 +00:00
<method name= "has_area" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "bool" />
2017-09-12 20:42:36 +00:00
<description >
2022-08-15 02:51:45 +00:00
Returns [code]true[/code] if the [Rect2] has area, and [code]false[/code] if the [Rect2] is linear, empty, or has a negative [member size]. See also [method get_area].
2017-09-12 20:42:36 +00:00
</description>
</method>
2021-03-18 13:44:42 +00:00
<method name= "has_point" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "bool" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "point" type= "Vector2" />
2017-09-12 20:42:36 +00:00
<description >
2021-11-11 10:31:30 +00:00
Returns [code]true[/code] if the [Rect2] contains a point. By convention, the right and bottom edges of the [Rect2] are considered exclusive, so points on these edges are [b]not[/b] included.
[b]Note:[/b] This method is not reliable for [Rect2] with a [i]negative size[/i]. Use [method abs] to get a positive sized equivalent rectangle to check for contained points.
2017-09-12 20:42:36 +00:00
</description>
</method>
2021-03-18 13:44:42 +00:00
<method name= "intersection" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "Rect2" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "b" type= "Rect2" />
2021-01-04 13:33:44 +00:00
<description >
2022-08-11 17:52:19 +00:00
Returns the intersection of this [Rect2] and [param b].
2021-01-04 13:33:44 +00:00
If the rectangles do not intersect, an empty [Rect2] is returned.
</description>
</method>
2021-03-18 13:44:42 +00:00
<method name= "intersects" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "bool" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "b" type= "Rect2" />
<param index= "1" name= "include_borders" type= "bool" default= "false" />
2017-09-12 20:42:36 +00:00
<description >
2023-04-26 19:36:04 +00:00
Returns [code]true[/code] if the [Rect2] overlaps with [param b] (i.e. they have at least one point in common).
2022-08-11 17:52:19 +00:00
If [param include_borders] is [code]true[/code], they will also be considered overlapping if their borders touch, even without intersection.
2017-09-12 20:42:36 +00:00
</description>
</method>
2021-03-18 13:44:42 +00:00
<method name= "is_equal_approx" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "bool" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "rect" type= "Rect2" />
2019-11-08 07:33:48 +00:00
<description >
2022-08-11 17:52:19 +00:00
Returns [code]true[/code] if this [Rect2] and [param rect] are approximately equal, by calling [code]is_equal_approx[/code] on each component.
2019-11-08 07:33:48 +00:00
</description>
</method>
2022-08-11 08:12:27 +00:00
<method name= "is_finite" qualifiers= "const" >
<return type= "bool" />
<description >
Returns [code]true[/code] if this [Rect2] is finite, by calling [method @GlobalScope.is_finite] on each component.
</description>
</method>
2021-03-18 13:44:42 +00:00
<method name= "merge" qualifiers= "const" >
2021-07-30 13:28:05 +00:00
<return type= "Rect2" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "b" type= "Rect2" />
2017-09-12 20:42:36 +00:00
<description >
2022-08-11 17:52:19 +00:00
Returns a larger [Rect2] that contains this [Rect2] and [param b].
2017-09-12 20:42:36 +00:00
</description>
</method>
2021-09-21 02:49:02 +00:00
</methods>
<members >
<member name= "end" type= "Vector2" setter= "" getter= "" default= "Vector2(0, 0)" >
Ending corner. This is calculated as [code]position + size[/code]. Setting this value will change the size.
</member>
<member name= "position" type= "Vector2" setter= "" getter= "" default= "Vector2(0, 0)" >
Beginning corner. Typically has values lower than [member end].
</member>
<member name= "size" type= "Vector2" setter= "" getter= "" default= "Vector2(0, 0)" >
Size from [member position] to [member end]. Typically, all components are positive.
If the size is negative, you can use [method abs] to fix it.
</member>
</members>
<operators >
<operator name= "operator !=" >
2021-07-30 13:28:05 +00:00
<return type= "bool" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "Rect2" />
2020-11-10 13:16:20 +00:00
<description >
2021-11-04 15:58:20 +00:00
Returns [code]true[/code] if the rectangles are not equal.
[b]Note:[/b] Due to floating-point precision errors, consider using [method is_equal_approx] instead, which is more reliable.
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator *" >
2021-07-30 13:28:05 +00:00
<return type= "Rect2" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "Transform2D" />
2020-11-10 13:16:20 +00:00
<description >
2021-11-04 15:58:20 +00:00
Inversely transforms (multiplies) the [Rect2] by the given [Transform2D] transformation matrix.
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator ==" >
2021-07-30 13:28:05 +00:00
<return type= "bool" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "Rect2" />
2020-11-10 13:16:20 +00:00
<description >
2021-11-04 15:58:20 +00:00
Returns [code]true[/code] if the rectangles are exactly equal.
[b]Note:[/b] Due to floating-point precision errors, consider using [method is_equal_approx] instead, which is more reliable.
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
</operators>
2017-09-12 20:42:36 +00:00
</class>