Table of Contents

Struct Rectangle

Namespace
HelixToolkit.Maths
Assembly
HelixToolkit.Maths.dll

Define a Rectangle. This structure is slightly different from System.Drawing.Rectangle as it is internally storing Left,Top,Right,Bottom instead of Left,Top,Width,Height.

public struct Rectangle : IEquatable<Rectangle>
Implements
Inherited Members
Extension Methods

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

Bottom

The bottom.

public int Bottom

Field Value

int

Empty

An empty rectangle.

public static readonly Rectangle Empty

Field Value

Rectangle

Left

The left.

public int Left

Field Value

int

Right

The right.

public int Right

Field Value

int

Top

The top.

public int Top

Field Value

int

Properties

Height

Gets or sets the height.

public int Height { readonly get; set; }

Property Value

int

The height.

IsEmpty

Gets a value that indicates whether the rectangle is empty.

public readonly bool IsEmpty { get; }

Property Value

bool

true if [is empty]; otherwise, false.

Width

Gets or sets the width.

public int Width { readonly get; set; }

Property Value

int

The width.

X

Gets or sets the X position.

public int X { readonly get; set; }

Property Value

int

The X position.

Y

Gets or sets the Y position.

public int Y { readonly get; set; }

Property Value

int

The Y position.

Methods

Contains(Rectangle)

Determines whether this rectangle entirely contains a specified rectangle.

public readonly 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 readonly 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(int, int)

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

public readonly 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 readonly 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 readonly 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(ref Rectangle)

Determines whether the specified Rectangle is equal to this instance.

public readonly bool Equals(ref 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 readonly 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 readonly 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 readonly 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 readonly 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(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 readonly string ToString()

Returns

string

The fully qualified type name.

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.

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.