Struct Rect<T>
Represents a rectangle defined by a position (Left, Top) in a two-dimensional coordinate system and sizes (Width, Height)
public readonly struct Rect<T> : IEquatable<Rect<T>>, ISpanFormattable, IFormattable, IEqualityOperators<Rect<T>, Rect<T>, bool> where T : unmanaged, IEquatable<T>, IFormattable, ISpanFormattable, IEqualityOperators<T, T, bool>
Type Parameters
TThe type of the rectangle's coordinates and dimensions
- Implements
-
IEquatable<Rect<T>>
- Inherited Members
Constructors
Rect(in T, in T, in T, in T)
Represents a rectangle defined by a position (Left, Top) in a two-dimensional coordinate system and sizes (Width, Height)
[SetsRequiredMembers]
public Rect(in T left, in T top, in T width, in T height)
Parameters
leftTThe left position of the rectangle
topTThe top position of the rectangle
widthTThe width of the rectangle
heightTThe height of the rectangle
Properties
Height
Gets or initializes the height of the rectangle
public required T Height { get; init; }
Property Value
- T
The height of the rectangle
Left
Gets or initializes the left position of the rectangle
public required T Left { get; init; }
Property Value
- T
The left position of the rectangle
Top
Gets or initializes the top position of the rectangle
public required T Top { get; init; }
Property Value
- T
The top position of the rectangle
Width
Gets or initializes the width of the rectangle
public required T Width { get; init; }
Property Value
- T
The width of the rectangle
Methods
Deconstruct(out T, out T, out T, out T)
Deconstructs the rectangle into its Left, Top, Width and Height components
public void Deconstruct(out T left, out T top, out T width, out T height)
Parameters
leftTThe left position of the rectangle
topTThe top position of the rectangle
widthTThe width of the rectangle
heightTThe height of the rectangle
Equals(in Rect<T>)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(in Rect<T> other)
Parameters
otherRect<T>An object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
ToString()
Returns the fully qualified type name of this instance.
public override string ToString()
Returns
- string
The fully qualified type name.
ToString(IFormatProvider?)
Formats the value of the current instance using the specified format.
public string ToString(IFormatProvider? formatProvider)
Parameters
formatProviderIFormatProviderThe provider to use to format the value.
-or-
A null reference (
Nothingin Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.
Returns
- string
The value of the current instance in the specified format.
ToString(string?)
Formats the value of the current instance using the specified format.
public string ToString(string? format)
Parameters
formatstringThe format to use.
-or-
A null reference (
Nothingin Visual Basic) to use the default format defined for the type of the IFormattable implementation.
Returns
- string
The value of the current instance in the specified format.
ToString(string?, IFormatProvider?)
Formats the value of the current instance using the specified format.
public string ToString(string? format, IFormatProvider? formatProvider)
Parameters
formatstringThe format to use.
-or-
A null reference (
Nothingin Visual Basic) to use the default format defined for the type of the IFormattable implementation.formatProviderIFormatProviderThe provider to use to format the value.
-or-
A null reference (
Nothingin Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.
Returns
- string
The value of the current instance in the specified format.
TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)
Tries to format the value of the current instance into the provided span of characters.
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)
Parameters
destinationSpan<char>The span in which to write this instance's value formatted as a span of characters.
charsWrittenintWhen this method returns, contains the number of characters that were written in
destination.formatReadOnlySpan<char>A span containing the characters that represent a standard or custom format string that defines the acceptable format for
destination.providerIFormatProviderAn optional object that supplies culture-specific formatting information for
destination.
Returns
Operators
operator ==(in Rect<T>, in Rect<T>)
Compares two values to determine equality.
public static bool operator ==(in Rect<T> left, in Rect<T> right)
Parameters
Returns
implicit operator (T Left, T Top, T Width, T Height)(in Rect<T>)
Converts a Rect<T> to a (Left, Top, Width, Height) tuple
public static implicit operator (T Left, T Top, T Width, T Height)(in Rect<T> rect)
Parameters
rectRect<T>The rectangle to convert
Returns
implicit operator Rect<T>(in (T Left, T Top, T Width, T Height))
Converts a (Left, Top, Width, Height) tuple to a Rect<T>
public static implicit operator Rect<T>(in (T Left, T Top, T Width, T Height) ltwh)
Parameters
Returns
- Rect<T>
operator !=(in Rect<T>, in Rect<T>)
Compares two values to determine inequality.
public static bool operator !=(in Rect<T> left, in Rect<T> right)