Ctrl+K

Rectangle

Declaration

public struct Strawberry.Common.Rectangle

Represents a floating-point rectangle defined by its X, Y, Width, and Height coordinates.

Constructors

Rectangle

Initializes a new instance of the Rectangle struct with the specified location and size.

void Rectangle(float x, float y, float width, float height)

Parameters:

Name Type Description
x System.Single The X-coordinate of the rectangle.
y System.Single The Y-coordinate of the rectangle.
width System.Single The width of the rectangle.
height System.Single The height of the rectangle.

Rectangle

Initializes a new instance of the Rectangle struct using position and size vectors.

void Rectangle(Vector2 pos, Vector2 size)

Parameters:

Name Type Description
pos Strawberry.Math.Vector2 The position of the top-left corner of the rectangle.
size Strawberry.Math.Vector2 The size (width and height) of the rectangle.

Rectangle

Initializes a new instance of the Rectangle struct using a 4D vector.

void Rectangle(Vector4 xywh)

Parameters:

Name Type Description
xywh Strawberry.Math.Vector4 A vector where X and Y represent the position, and Z and W represent the width and height respectively.

Properties

X

Gets or sets the X-coordinate of the rectangle.

float X { get set }

Y

Gets or sets the Y-coordinate of the rectangle.

float Y { get set }

Width

Gets or sets the width of the rectangle.

float Width { get set }

Height

Gets or sets the height of the rectangle.

float Height { get set }

Left

Gets or sets the X-coordinate (left edge) of the rectangle.

float Left { get set }

Top

Gets or sets the Y-coordinate (top edge) of the rectangle.

float Top { get set }

Gets the X-coordinate of the right edge of the rectangle.

float Right { get }

Bottom

Gets the Y-coordinate of the bottom edge of the rectangle.

float Bottom { get }

Methods

IsPointInside

Determines whether the specified point lies inside the rectangle's bounds.

bool IsPointInside(Vector2 point)

Parameters:

Name Type Description
point Strawberry.Math.Vector2 The point to check.

Returns: true if the point is inside the rectangle; otherwise, false.

IsPointInside

Determines whether the specified point lies inside the rectangle's bounds.

bool IsPointInside(float x, float y)

Parameters:

Name Type Description
x System.Single The X-coordinate of the point to check.
y System.Single The Y-coordinate of the point to check.

Returns: true if the point is inside the rectangle; otherwise, false.

Overlap

Determines whether this rectangle overlaps with another rectangle.

bool Overlap(Rectangle rect)

Parameters:

Name Type Description
rect Strawberry.Common.Rectangle The rectangle to check for overlap.

Returns: true if the rectangles overlap; otherwise, false.

IsRectangleInside

Determines whether the specified rectangle is entirely contained within this rectangle.

bool IsRectangleInside(Rectangle rect)

Parameters:

Name Type Description
rect Strawberry.Common.Rectangle The rectangle to check for containment.

Returns: true if the specified rectangle is entirely inside this rectangle; otherwise, false.

IntersectsWith

Determines whether this rectangle intersects with another rectangle.

bool IntersectsWith(Rectangle rect)

Parameters:

Name Type Description
rect Strawberry.Common.Rectangle The rectangle to check for intersection.

Returns: true if the rectangles intersect; otherwise, false.

Equals override

Determines whether the specified Object is equal to this Rectangle.

bool Equals(object obj)

Parameters:

Name Type Description
obj System.Object The object to compare with the current rectangle.

Returns: true if the specified object is a Rectangle and has the same X, Y, Width, and Height values; otherwise, false.

GetHashCode override

Returns a hash code for this Rectangle.

int GetHashCode()

Returns: A hash code for the current rectangle.

ToString override

Converts the numeric values of this Rectangle to its equivalent string representation.

string ToString()

Returns: A string that contains the X, Y, Width, and Height values of this rectangle.