2D axis-aligned bounding box.
``````    [Serializable]
public struct Rect2 : IEquatable<Rect2>
``````

Rect2 consists of a position, a size, and several utility functions. It is typically used for fast overlap tests.

Constructors

``````    public Rect2(Vector2 position, Vector2 size)
``````

Constructs a Rect2 by position and size.

``````    public Rect2(Vector2 position, float width, float height)
``````

``````    public Rect2(float x, float y, Vector2 size)
``````

``````    public Rect2(float x, float y, float width, float height)
``````

Constructs a Rect2 by x, y, width, and height.

``````    public Rect2()
``````

Properties

``````    public float Area { get; }
``````

``````    public Vector2 End { get; set; }
``````

Ending corner.

``````    public Vector2 Position { get; set; }
``````

Position (starting corner).

``````    public Vector2 Size { get; set; }
``````

Size from position to end.

Methods

``````    public Rect2 Abs()
``````

Returns a Rect2 with equivalent position and area, modified so that the top-left corner is the origin and `width` and `height` are positive.

``````    public Rect2 Clip(Rect2 b)
``````

Returns the intersection of this Rect2 and b.

``````    public bool Encloses(Rect2 b)
``````

Returns `true` if this Rect2 completely encloses another one.

``````    public override bool Equals(object obj)
``````

``````    public bool Equals(Rect2 other)
``````

``````    public Rect2 Expand(Vector2 to)
``````

Returns this Rect2 expanded to include a given point.

``````    public float GetArea()
``````

Returns the area of the Rect2.

``````    public override int GetHashCode()
``````

``````    public Rect2 Grow(float by)
``````

Returns a copy of the Rect2 grown a given amount of units towards all the sides.

``````    public Rect2 GrowIndividual(float left, float top, float right, float bottom)
``````

Returns a copy of the Rect2 grown a given amount of units towards each direction individually.

``````    public Rect2 GrowMargin(Margin margin, float by)
``````

Returns a copy of the Rect2 grown a given amount of units towards the [enum Margin] direction.

``````    public bool HasNoArea()
``````

Returns `true` if the Rect2 is flat or empty.

``````    public bool HasPoint(Vector2 point)
``````

Returns `true` if the Rect2 contains a point.

``````    public bool Intersects(Rect2 b)
``````

Returns `true` if the Rect2 overlaps with another.

``````    public Rect2 Merge(Rect2 b)
``````

Returns a larger Rect2 that contains this Rect2 and `b`.

``````    public override string ToString()
``````

``````    public string ToString(string format)
``````

Operators

``````    public static bool operator ==(Rect2 left, Rect2 right)
``````

``````    public static bool operator !=(Rect2 left, Rect2 right)
``````
Tags: