Table of Contents

Struct Rectangle

Namespace
Stride.Core.Mathematics
Assembly
Stride.Core.Mathematics.dll

A rectangle structure defining X,Y,Width,Height.

[DataContract("Rectangle")]
[DataStyle(DataStyle.Compact)]
public struct Rectangle : IEquatable<Rectangle>
Implements

Constructors

Rectangle(int, int, int, int)

Initializes a new instance of the Rectangle struct.

public Rectangle(int x, int y, int width, int height)

Parameters

x int

The left.

y int

The top.

width int

The width.

height int

The height.

Fields

Empty

An empty rectangle.

public static readonly Rectangle Empty

Field Value

Rectangle

Height

Gets or sets the height.

[DataMember(3)]
public int Height

Field Value

int

The height.

Width

Gets or sets the width.

[DataMember(2)]
public int Width

Field Value

int

The width.

X

Gets or sets the X position.

[DataMember(0)]
public int X

Field Value

int

The X position.

Y

Gets or sets the Y position.

[DataMember(1)]
public int Y

Field Value

int

The Y position.

Properties

Bottom

Gets or sets the bottom.

public int Bottom { get; }

Property Value

int

The bottom.

BottomLeft

Gets the position of the bottom-left corner of the rectangle.

public Point BottomLeft { get; }

Property Value

Point

The bottom-left corner of the rectangle.

BottomRight

Gets the position of the bottom-right corner of the rectangle.

public Point BottomRight { get; }

Property Value

Point

The bottom-right corner of the rectangle.

Center

Gets the Point that specifies the center of the rectangle.

public Point Center { get; }

Property Value

Point

The center.

IsEmpty

Gets a value that indicates whether the rectangle is empty.

public bool IsEmpty { get; }

Property Value

bool

true if [is empty]; otherwise, false.

Left

Gets or sets the left.

public int Left { get; set; }

Property Value

int

The left.

Location

Gets or sets the location.

public Point Location { get; set; }

Property Value

Point

The location.

Right

Gets or sets the right.

public int Right { get; }

Property Value

int

The right.

Size

Gets or sets the size of the rectangle.

public Size2 Size { get; set; }

Property Value

Size2

The size of the rectangle.

Top

Gets or sets the top.

public int Top { get; set; }

Property Value

int

The top.

TopLeft

Gets the position of the top-left corner of the rectangle.

public Point TopLeft { get; }

Property Value

Point

The top-left corner of the rectangle.

TopRight

Gets the position of the top-right corner of the rectangle.

public Point TopRight { get; }

Property Value

Point

The top-right corner of the rectangle.

Methods

Contains(Int2)

Checks, if specified Int2 is inside Rectangle.

public bool Contains(Int2 int2)

Parameters

int2 Int2

Coordinate Int2.

Returns

bool

true if Int2 is inside Rectangle, otherwise false.

Contains(Point)

Determines whether this rectangle contains a specified Point.

public bool Contains(Point value)

Parameters

value Point

The Point to evaluate.

Returns

bool

Contains(ref Point, out bool)

Determines whether this rectangle contains a specified Point.

public void Contains(ref Point value, out bool result)

Parameters

value Point

The Point to evaluate.

result bool

[OutAttribute] true if the specified Point is contained within this rectangle; false otherwise.

Contains(Rectangle)

Determines whether this rectangle entirely contains a specified rectangle.

public bool Contains(Rectangle value)

Parameters

value Rectangle

The rectangle to evaluate.

Returns

bool

Contains(ref Rectangle, out bool)

Determines whether this rectangle entirely contains a specified rectangle.

public void Contains(ref Rectangle value, out bool result)

Parameters

value Rectangle

The rectangle to evaluate.

result bool

[OutAttribute] On exit, is true if this rectangle entirely contains the specified rectangle, or false if not.

Contains(Vector2)

Checks, if specified Vector2 is inside Rectangle.

public bool Contains(Vector2 vector2D)

Parameters

vector2D Vector2

Coordinate Vector2.

Returns

bool

true if Vector2 is inside Rectangle, otherwise false.

Contains(int, int)

Determines whether this rectangle contains a specified point represented by its x- and y-coordinates.

public bool Contains(int x, int y)

Parameters

x int

The x-coordinate of the specified point.

y int

The y-coordinate of the specified point.

Returns

bool

Contains(float, float)

Checks, if specified point is inside Rectangle.

public bool Contains(float x, float y)

Parameters

x float

X point coordinate.

y float

Y point coordinate.

Returns

bool

true if point is inside Rectangle, otherwise false.

Equals(Rectangle)

Determines whether the specified Rectangle is equal to this instance.

public bool Equals(Rectangle other)

Parameters

other Rectangle

The Rectangle to compare with this instance.

Returns

bool

true if the specified Rectangle is equal to this instance; otherwise, false.

Equals(object)

Determines whether the specified object is equal to this instance.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with this instance.

Returns

bool

true if the specified object is equal to this instance; otherwise, false.

GetHashCode()

Returns a hash code for this instance.

public override int GetHashCode()

Returns

int

A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.

Inflate(int, int)

Pushes the edges of the rectangle out by the horizontal and vertical values specified.

public void Inflate(int horizontalAmount, int verticalAmount)

Parameters

horizontalAmount int

Value to push the sides out by.

verticalAmount int

Value to push the top and bottom out by.

Intersect(Rectangle, Rectangle)

Creates a rectangle defining the area where one rectangle overlaps with another rectangle.

public static Rectangle Intersect(Rectangle value1, Rectangle value2)

Parameters

value1 Rectangle

The first rectangle to compare.

value2 Rectangle

The second rectangle to compare.

Returns

Rectangle

The intersection rectangle.

Intersect(ref Rectangle, ref Rectangle, out Rectangle)

Creates a rectangle defining the area where one rectangle overlaps with another rectangle.

public static void Intersect(ref Rectangle value1, ref Rectangle value2, out Rectangle result)

Parameters

value1 Rectangle

The first rectangle to compare.

value2 Rectangle

The second rectangle to compare.

result Rectangle

[OutAttribute] The area where the two first parameters overlap.

Intersects(Rectangle)

Determines whether a specified rectangle intersects with this rectangle.

public bool Intersects(Rectangle value)

Parameters

value Rectangle

The rectangle to evaluate.

Returns

bool

Intersects(ref Rectangle, out bool)

Determines whether a specified rectangle intersects with this rectangle.

public void Intersects(ref Rectangle value, out bool result)

Parameters

value Rectangle

The rectangle to evaluate

result bool

[OutAttribute] true if the specified rectangle intersects with this one; false otherwise.

Offset(Point)

Changes the position of the rectangle.

public void Offset(Point amount)

Parameters

amount Point

The values to adjust the position of the rectangle by.

Offset(int, int)

Changes the position of the rectangle.

public void Offset(int offsetX, int offsetY)

Parameters

offsetX int

Change in the x-position.

offsetY int

Change in the y-position.

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string

The fully qualified type name.

Union(Rectangle, Int2)

Creates a new rectangle that incorporate the provided point to the given rectangle.

public static Rectangle Union(Rectangle rectangle, Int2 point)

Parameters

rectangle Rectangle

The original rectangle.

point Int2

The point to incorporate.

Returns

Rectangle

The union rectangle.

Union(Rectangle, Rectangle)

Creates a new rectangle that exactly contains two other rectangles.

public static Rectangle Union(Rectangle value1, Rectangle value2)

Parameters

value1 Rectangle

The first rectangle to contain.

value2 Rectangle

The second rectangle to contain.

Returns

Rectangle

The union rectangle.

Union(ref Rectangle, ref Rectangle, out Rectangle)

Creates a new rectangle that exactly contains two other rectangles.

public static void Union(ref Rectangle value1, ref Rectangle value2, out Rectangle result)

Parameters

value1 Rectangle

The first rectangle to contain.

value2 Rectangle

The second rectangle to contain.

result Rectangle

[OutAttribute] The rectangle that must be the union of the first two rectangles.

Operators

operator ==(Rectangle, Rectangle)

Implements the operator ==.

public static bool operator ==(Rectangle left, Rectangle right)

Parameters

left Rectangle

The left.

right Rectangle

The right.

Returns

bool

The result of the operator.

implicit operator RectangleF(Rectangle)

Performs an implicit conversion to the RectangleF structure.

public static implicit operator RectangleF(Rectangle value)

Parameters

value Rectangle

The source Rectangle value.

Returns

RectangleF

The converted structure.

Remarks

Performs direct converstion from int to float.

operator !=(Rectangle, Rectangle)

Implements the operator !=.

public static bool operator !=(Rectangle left, Rectangle right)

Parameters

left Rectangle

The left.

right Rectangle

The right.

Returns

bool

The result of the operator.