Table of Contents

Struct Rect

Namespace
OpenCvSharp
Assembly
OpenCvSharp.dll

Stores a set of four integers that represent the location and size of a rectangle

[Serializable]
public record struct Rect : IEquatable<Rect>
Implements
Inherited Members

Constructors

Rect(Point, Size)

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

public Rect(Point location, Size size)

Parameters

location Point

A Point that represents the upper-left corner of the rectangular region.

size Size

A Size that represents the width and height of the rectangular region.

Rect(int, int, int, int)

Stores a set of four integers that represent the location and size of a rectangle

public Rect(int X, int Y, int Width, int Height)

Parameters

X int

The x-coordinate of the upper-left corner of the rectangle.

Y int

The y-coordinate of the upper-left corner of the rectangle.

Width int

The width of the rectangle.

Height int

The height of the rectangle.

Fields

Height

The height of the rectangle.

public int Height

Field Value

int

Width

The width of the rectangle.

public int Width

Field Value

int

X

The x-coordinate of the upper-left corner of the rectangle.

public int X

Field Value

int

Y

The y-coordinate of the upper-left corner of the rectangle.

public int Y

Field Value

int

Properties

Bottom

Gets the y-coordinate that is the sum of the Y and Height property values of this Rect structure.

public int Bottom { get; }

Property Value

int

BottomRight

Coordinate of the right-most rectangle corner [Point(X+Width, Y+Height)]

public Point BottomRight { get; }

Property Value

Point

Left

Gets the x-coordinate of the left edge of this Rect structure.

public int Left { get; set; }

Property Value

int

Location

Coordinate of the left-most rectangle corner [Point(X, Y)]

public Point Location { get; set; }

Property Value

Point

Right

Gets the x-coordinate that is the sum of X and Width property values of this Rect structure.

public int Right { get; }

Property Value

int

Size

Size of the rectangle [CvSize(Width, Height)]

public Size Size { get; set; }

Property Value

Size

Top

Gets the y-coordinate of the top edge of this Rect structure.

public int Top { readonly get; set; }

Property Value

int

TopLeft

Coordinate of the left-most rectangle corner [Point(X, Y)]

public Point TopLeft { get; }

Property Value

Point

Methods

Add(Point)

Shifts rectangle by a certain offset

public readonly Rect Add(Point pt)

Parameters

pt Point

Returns

Rect

Add(Size)

Expands or shrinks rectangle by a certain amount

public readonly Rect Add(Size size)

Parameters

size Size

Returns

Rect

Contains(Point)

Determines if the specified point is contained within the rectangular region defined by this Rectangle.

public readonly bool Contains(Point pt)

Parameters

pt Point

point

Returns

bool

Contains(Rect)

Determines if the specified rectangle is contained within the rectangular region defined by this Rectangle.

public readonly bool Contains(Rect rect)

Parameters

rect Rect

rectangle

Returns

bool

Contains(int, int)

Determines if the specified point is contained within the rectangular region defined by this Rectangle.

public readonly bool Contains(int x, int y)

Parameters

x int

x-coordinate of the point

y int

y-coordinate of the point

Returns

bool

FromLTRB(int, int, int, int)

Creates a Rectangle structure with the specified edge locations.

public static Rect FromLTRB(int left, int top, int right, int bottom)

Parameters

left int

The x-coordinate of the upper-left corner of this Rectangle structure.

top int

The y-coordinate of the upper-left corner of this Rectangle structure.

right int

The x-coordinate of the lower-right corner of this Rectangle structure.

bottom int

The y-coordinate of the lower-right corner of this Rectangle structure.

Returns

Rect

Inflate(Rect, int, int)

Creates and returns an inflated copy of the specified Rect structure.

public static Rect Inflate(Rect rect, int x, int y)

Parameters

rect Rect

The Rectangle with which to start. This rectangle is not modified.

x int

The amount to inflate this Rectangle horizontally.

y int

The amount to inflate this Rectangle vertically.

Returns

Rect

Inflate(Size)

Inflates this Rect by the specified amount.

public void Inflate(Size size)

Parameters

size Size

The amount to inflate this rectangle.

Inflate(int, int)

Inflates this Rect by the specified amount.

public void Inflate(int width, int height)

Parameters

width int

The amount to inflate this Rectangle horizontally.

height int

The amount to inflate this Rectangle vertically.

Intersect(Rect)

Determines the Rect structure that represents the intersection of two rectangles.

public readonly Rect Intersect(Rect rect)

Parameters

rect Rect

A rectangle to intersect.

Returns

Rect

Intersect(Rect, Rect)

Determines the Rect structure that represents the intersection of two rectangles.

public static Rect Intersect(Rect a, Rect b)

Parameters

a Rect

A rectangle to intersect.

b Rect

A rectangle to intersect.

Returns

Rect

IntersectsWith(Rect)

Determines if this rectangle intersects with rect.

public readonly bool IntersectsWith(Rect rect)

Parameters

rect Rect

Rectangle

Returns

bool

Subtract(Point)

Shifts rectangle by a certain offset

public readonly Rect Subtract(Point pt)

Parameters

pt Point

Returns

Rect

Subtract(Size)

Expands or shrinks rectangle by a certain amount

public readonly Rect Subtract(Size size)

Parameters

size Size

Returns

Rect

Union(Rect)

Gets a Rect structure that contains the union of two Rect structures.

public readonly Rect Union(Rect rect)

Parameters

rect Rect

A rectangle to union.

Returns

Rect

Union(Rect, Rect)

Gets a Rect structure that contains the union of two Rect structures.

public static Rect Union(Rect a, Rect b)

Parameters

a Rect

A rectangle to union.

b Rect

A rectangle to union.

Returns

Rect

Operators

operator +(Rect, Point)

Shifts rectangle by a certain offset

public static Rect operator +(Rect rect, Point pt)

Parameters

rect Rect
pt Point

Returns

Rect

operator +(Rect, Size)

Expands or shrinks rectangle by a certain amount

public static Rect operator +(Rect rect, Size size)

Parameters

rect Rect
size Size

Returns

Rect

operator &(Rect, Rect)

Determines the Rect structure that represents the intersection of two rectangles.

[SuppressMessage("Microsoft.Design", "CA2225: Operator overloads have named alternates")]
public static Rect operator &(Rect a, Rect b)

Parameters

a Rect

A rectangle to intersect.

b Rect

A rectangle to intersect.

Returns

Rect

operator |(Rect, Rect)

Gets a Rect structure that contains the union of two Rect structures.

[SuppressMessage("Microsoft.Design", "CA2225: Operator overloads have named alternates")]
public static Rect operator |(Rect a, Rect b)

Parameters

a Rect

A rectangle to union.

b Rect

A rectangle to union.

Returns

Rect

operator -(Rect, Point)

Shifts rectangle by a certain offset

public static Rect operator -(Rect rect, Point pt)

Parameters

rect Rect
pt Point

Returns

Rect

operator -(Rect, Size)

Expands or shrinks rectangle by a certain amount

public static Rect operator -(Rect rect, Size size)

Parameters

rect Rect
size Size

Returns

Rect