Search Results for

    Show / Hide Table of Contents

    Struct Rectangle

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

    Implements
    IEquatable<Rectangle>
    Inherited Members
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Evergine.Mathematics
    Assembly: Evergine.Mathematics.dll
    Syntax
    public struct Rectangle : IEquatable<Rectangle>

    Constructors

    Rectangle(int, int, int, int)

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

    Declaration
    public Rectangle(int x, int y, int width, int height)
    Parameters
    Type Name Description
    int x

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

    int y

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

    int width

    The width of the rectangle.

    int height

    The height of the rectangle.

    Fields

    Height

    Gets or sets the height of this Rectangle structure. The default is 0.

    Declaration
    public int Height
    Field Value
    Type Description
    int

    Width

    Gets or sets the width of this Rectangle structure. The default is 0.

    Declaration
    public int Width
    Field Value
    Type Description
    int

    X

    Gets or sets the x-coordinate of the upper-left corner of this Rectangle structure. The default is 0.

    Declaration
    public int X
    Field Value
    Type Description
    int

    Y

    Gets or sets the y-coordinate of the upper-left corner of this Rectangle structure. The default is 0.

    Declaration
    public int Y
    Field Value
    Type Description
    int

    Properties

    Bottom

    Gets the y-coordinate that is the sum of Y and Height of this Rectangle structure.

    Declaration
    public int Bottom { get; }
    Property Value
    Type Description
    int

    Center

    Gets the coordinates of the center of this Rectangle structure.

    Declaration
    public Point Center { get; }
    Property Value
    Type Description
    Point

    A Point that represents the center of this Rectangle structure.

    Empty

    Gets an instance of the Rectangle class with its members uninitialized.

    Declaration
    public static Rectangle Empty { get; }
    Property Value
    Type Description
    Rectangle
    Remarks

    The members of the new Rectangle are left uninitialized.

    IsEmpty

    Gets a value indicating whether the Width or Height property of this Rectangle has a value of zero.

    Declaration
    public bool IsEmpty { get; }
    Property Value
    Type Description
    bool

    . This property returns true if the Width or Height property of this Rectangle has a value of zero; otherwise, false.

    Left

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

    Declaration
    public int Left { get; }
    Property Value
    Type Description
    int

    Location

    Gets or sets the coordinates of the upper-left corner of this Rectangle structure.

    Declaration
    public Point Location { get; set; }
    Property Value
    Type Description
    Point

    A Point that represents the upper-left corner of this Rectangle structure.

    Right

    Gets the x-coordinate that is the sum of X and Width of this Rectangle structure.

    Declaration
    public int Right { get; }
    Property Value
    Type Description
    int

    Top

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

    Declaration
    public int Top { get; }
    Property Value
    Type Description
    int

    Methods

    Contains(Point)

    Determines if the specified point is contained within this Rectangle structure.

    Declaration
    public bool Contains(Point pt)
    Parameters
    Type Name Description
    Point pt

    The Point to test.

    Returns
    Type Description
    bool

    This method returns true if the point represented by the pt parameter is contained within this Rectangle structure; otherwise false.

    Contains(ref Point, out bool)

    Determines if the specified point is contained within this Rectangle structure.

    Declaration
    public void Contains(ref Point pt, out bool result)
    Parameters
    Type Name Description
    Point pt

    The Point to test.

    bool result

    if set to true the point represented by the pt parameter is contained within this Rectangle structure; otherwise false.

    Contains(Rectangle)

    Determines if the rectangular region represented by rect is entirely contained within this Rectangle structure.

    Declaration
    public bool Contains(Rectangle rect)
    Parameters
    Type Name Description
    Rectangle rect

    The Rectangle to test.

    Returns
    Type Description
    bool

    This method returns true if the rectangular region represented by rect is entirely contained within the rectangular region represented by this Rectangle; otherwise false.

    Contains(ref Rectangle, out bool)

    Determines if the rectangular region represented by rect is entirely contained within this Rectangle structure.

    Declaration
    public void Contains(ref Rectangle rect, out bool result)
    Parameters
    Type Name Description
    Rectangle rect

    The Rectangle to test.

    bool result

    if set to true the rectangular region represented by rect is entirely contained within this Rectangle structure.

    Contains(int, int)

    Determines if the specified point is contained within this Rectangle structure.

    Declaration
    public bool Contains(int x, int y)
    Parameters
    Type Name Description
    int x

    The x-coordinate of the point to test.

    int y

    The y-coordinate of the point to test.

    Returns
    Type Description
    bool

    This method returns true if the point defined by x and y is contained within this Rectangle structure; otherwise false.

    Equals(Rectangle)

    Tests whether other has the same location and size of this Rectangle.

    Declaration
    public bool Equals(Rectangle other)
    Parameters
    Type Name Description
    Rectangle other

    The Rectangle to test.

    Returns
    Type Description
    bool

    This method returns true if other has its X, Y, Width, and Height properties equal to the corresponding properties of this Rectangle; otherwise, false.

    Equals(ref Rectangle)

    Equalses the specified other.

    Declaration
    public bool Equals(ref Rectangle other)
    Parameters
    Type Name Description
    Rectangle other

    The other.

    Returns
    Type Description
    bool

    The result.

    Equals(object)

    Tests whether obj is a Rectangle with the same location and size of this Rectangle.

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    object obj

    The object to test.

    Returns
    Type Description
    bool

    This method returns true if obj is a Rectangle and its X, Y, Width, and Height properties are equal to the corresponding properties of this Rectangle; otherwise, false.

    Overrides
    ValueType.Equals(object)

    GetHashCode()

    Gets the hash code for this Rectangle structure. For information about the use of hash codes, see GetHashCode().

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int

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

    Overrides
    ValueType.GetHashCode()

    Inflate(int, int)

    Enlarges this Rectangle structure by the specified amount.

    Declaration
    public void Inflate(int horizontalAmount, int verticalAmount)
    Parameters
    Type Name Description
    int horizontalAmount

    The amount to inflate this Rectangle structure horizontally.

    int verticalAmount

    The amount to inflate this Rectangle structure vertically.

    Remarks

    This method enlarges this rectangle, not a copy of it. The rectangle is enlarged in both directions along an axis. For example, if a 50 by 50 rectangle is inflated by 50 in the x-axis, the resultant rectangle will be 150 units long (the original 50, the 50 in the minus direction, and the 50 in the plus direction) maintaining the rectangle's geometric center. If either x or y is negative, the Rectangle is deflated in the corresponding direction.

    Intersect(Rectangle, Rectangle)

    Returns a Rectangle structure that represents the intersection of two rectangles. If there is no intersection, and empty Rectangle is returned.

    Declaration
    public static Rectangle Intersect(Rectangle a, Rectangle b)
    Parameters
    Type Name Description
    Rectangle a

    A rectangle to intersect.

    Rectangle b

    The second rectangle to intersect.

    Returns
    Type Description
    Rectangle

    A third Rectangle structure the size of which represents the overlapped area of the two specified rectangles.

    Intersect(ref Rectangle, ref Rectangle, out Rectangle)

    Calculates a Rectangle structure that represents the intersection of two rectangles. If there is no intersection, and empty Rectangle is returned.

    Declaration
    public static void Intersect(ref Rectangle a, ref Rectangle b, out Rectangle result)
    Parameters
    Type Name Description
    Rectangle a

    A rectangle to intersect.

    Rectangle b

    The second rectangle to intersect.

    Rectangle result

    A rectangle that represents the intersection of two rectangles.

    Intersects(Rectangle)

    Determines if this rectangle intersects with rect.

    Declaration
    public bool Intersects(Rectangle rect)
    Parameters
    Type Name Description
    Rectangle rect

    The rectangle to test.

    Returns
    Type Description
    bool

    This method returns true if there is any intersection.

    Intersects(ref Rectangle, out bool)

    Determines if this rectangle intersects with rect.

    Declaration
    public void Intersects(ref Rectangle rect, out bool result)
    Parameters
    Type Name Description
    Rectangle rect

    The rectangle to test.

    bool result

    if set to true there is any intersection.

    Offset(Point)

    Adjusts the location of this rectangle by the specified amount.

    Declaration
    public void Offset(Point amount)
    Parameters
    Type Name Description
    Point amount

    The amount to offset the location.

    Offset(int, int)

    Adjusts the location of this rectangle by the specified amount.

    Declaration
    public void Offset(int offsetX, int offsetY)
    Parameters
    Type Name Description
    int offsetX

    The amount to offset the location horizontally.

    int offsetY

    The amount to offset the location vertically.

    Round(RectangleF)

    Converts the specified RectangleF to a Rectangle by rounding the RectangleF values to the nearest integer values.

    Declaration
    public static Rectangle Round(RectangleF value)
    Parameters
    Type Name Description
    RectangleF value

    The Rectangle value.

    Returns
    Type Description
    Rectangle

    The rounded interger value of the Rectangle.

    ToString()

    Converts the Location and Size of this Rectangle to a human-readable string.

    Declaration
    public override string ToString()
    Returns
    Type Description
    string

    A string that contains the position, width, and height of this Rectangle structure. For example, "{X:20, Y:20, Width:100, Height:50}".

    Overrides
    ValueType.ToString()

    ToVector4()

    Converts the X, Y, Width and Height of this Rectangle to a Vector4 structure.

    Declaration
    public Vector4 ToVector4()
    Returns
    Type Description
    Vector4

    A Vector4 that contains the X, Y, Width, Height, of this Rectangle to a Vector4 structure.

    ToVector4(ref Vector4)

    Converts the X, Y, Width and Height of this Rectangle to a Vector4 structure.

    Declaration
    public void ToVector4(ref Vector4 vector)
    Parameters
    Type Name Description
    Vector4 vector

    Vector4 reference to pass Rectangle values.

    Truncate(RectangleF)

    Converts the specified RectangleF to a Rectangle by truncating the RectangleF values.

    Declaration
    public static Rectangle Truncate(RectangleF value)
    Parameters
    Type Name Description
    RectangleF value

    The RectangleF to be converted.

    Returns
    Type Description
    Rectangle

    The truncated value of the Rectangle.

    Union(Rectangle, Rectangle)

    Creates the smallest possible third rectangle that can contain both of two rectangles that form a union.

    Declaration
    public static Rectangle Union(Rectangle a, Rectangle b)
    Parameters
    Type Name Description
    Rectangle a

    A rectangle to union.

    Rectangle b

    The second rectangle to union.

    Returns
    Type Description
    Rectangle

    A third Rectangle structure that contains both of the two rectangles that form the union.

    Union(ref Rectangle, ref Rectangle, out Rectangle)

    Calculates the smallest possible third rectangle that can contain both of two rectangles that form a union.

    Declaration
    public static void Union(ref Rectangle a, ref Rectangle b, out Rectangle result)
    Parameters
    Type Name Description
    Rectangle a

    A rectangle to union.

    Rectangle b

    The second rectangle to union.

    Rectangle result

    The smallest possible third rectangle that can contain both of two rectangles that form a union.

    Operators

    operator ==(Rectangle, Rectangle)

    Tests whether two Rectangle structures have equal location and size.

    Declaration
    public static bool operator ==(Rectangle left, Rectangle right)
    Parameters
    Type Name Description
    Rectangle left

    The Rectangle structure that is to the left of the inequality operator.

    Rectangle right

    The Rectangle structure that is to the right of the inequality operator.

    Returns
    Type Description
    bool

    This operator returns true the two specified Rectangle structures have equal X , Y, Width, and Height properties; otherwise false.

    operator !=(Rectangle, Rectangle)

    Tests whether two Rectangle structures differ in location or size.

    Declaration
    public static bool operator !=(Rectangle left, Rectangle right)
    Parameters
    Type Name Description
    Rectangle left

    The Rectangle structure that is to the left of the inequality operator.

    Rectangle right

    The Rectangle structure that is to the right of the inequality operator.

    Returns
    Type Description
    bool

    This operator returns true if any of the X , Y, Width, or Height properties of the two Rectangle structures are unequal; otherwise false.

    Implements

    IEquatable<T>

    Extension Methods

    ReflectionHelper.GetMemberAssembly(object)
    ReflectionHelper.GetTypeName(object)
    In This Article
    Back to top
    Generated by DocFX