Class Rect
Provides extension methods for Rect<T>
public static class Rect
- Inheritance
-
Rect
- Inherited Members
Methods
ContainsPoint<T>(in Rect<T>, in Point<T>, IDispatchComparable<T>?)
Indicates whether the specified point is contained within the rectangle
public static bool ContainsPoint<T>(this in Rect<T> rect, in Point<T> point, Math.IDispatchComparable<T>? _ = null) where T : unmanaged, IEquatable<T>, IFormattable, ISpanFormattable, IEqualityOperators<T, T, bool>, IComparable<T>, IAdditionOperators<T, T, T>
Parameters
rectRect<T>The rectangle to check
pointPoint<T>The point to check
_Math.IDispatchComparable<T>Please ignore and do not explicitly set this parameter
Returns
Type Parameters
TThe type of the rectangle's coordinates and dimensions
Remarks
A point is considered part of a rectangle if the point's X and Y coordinates are ≥ to the rectangle's Top-Left corner,
and < to the rectangle's Left + Width and Top + Height coordinates.
So a 1⨯1 rectangle with it's origin at (0, 0) would consider a point (0, 0) as "inside" and a point (0, 1) as not.
This method works for types of rect and point T which implement IComparable<T>.
If T implements both IComparable<T> and IComparisonOperators<TSelf, TOther, TResult>,
overload resolution prioritizes ContainsPoint<T>(in Rect<T>, in Point<T>, IDispatchComparisonOperators<T>?) instead.
Please ignore and do not explicitly set the _ parameter. This parameter is just used in the method's signature to dispatch calls to this method for types of rect and point T which implement IComparable<T>.
ContainsPoint<T>(in Rect<T>, in Point<T>, IDispatchComparisonOperators<T>?)
Indicates whether the specified point is contained within the rectangle
public static bool ContainsPoint<T>(this in Rect<T> rect, in Point<T> point, Math.IDispatchComparisonOperators<T>? _ = null) where T : unmanaged, IEquatable<T>, IFormattable, ISpanFormattable, IEqualityOperators<T, T, bool>, IComparisonOperators<T, T, bool>, IAdditionOperators<T, T, T>
Parameters
rectRect<T>The rectangle to check
pointPoint<T>The point to check
_Math.IDispatchComparisonOperators<T>Please ignore and do not explicitly set this parameter
Returns
Type Parameters
TThe type of the rectangle's coordinates and dimensions
Remarks
A point is considered part of a rectangle if the point's X and Y coordinates are ≥ to the rectangle's Top-Left corner,
and < to the rectangle's Left + Width and Top + Height coordinates.
So a 1⨯1 rectangle with it's origin at (0, 0) would consider a point (0, 0) as "inside" and a point (0, 1) as not.
This method works for types of rect and point T which implement IComparisonOperators<TSelf, TOther, TResult>.
If T implements both IComparisonOperators<TSelf, TOther, TResult> and IComparable<T>,
overload resolution prioritizes this method.
Please ignore and do not explicitly set the _ parameter. This parameter is just used in the method's signature to dispatch calls to this method for types of rect and point T which implement IComparisonOperators<TSelf, TOther, TResult>.
EqualsWithinEpsilon(in Rect<float>, in Rect<float>, in float)
Indicates whether two rectangles are equal within a specified epsilon
public static bool EqualsWithinEpsilon(this in Rect<float> rect, in Rect<float> other, in float epsilon = 1.1920929E-07)
Parameters
rectRect<float>The first rectangle
otherRect<float>The second rectangle
epsilonfloatThe tolerance for equality. Defaults to EpsilonF.
Returns
Remarks
Two rectangles are considered equal if their Left and Top coordinates, and their Width and Height dimensions are within epsilon of each other.
The parameter epsilon defaults to EpsilonF.
This is often a reasonable way to compare two floating point rectangles and deal with the slight precision variations in floating point calculations that tend to pop up.
EqualsWithinEpsilon<T>(in Rect<T>, in Rect<T>, in T, IDispatchComparable<T>?)
Indicates whether two rectangles are equal within a specified epsilon
public static bool EqualsWithinEpsilon<T>(this in Rect<T> rect, in Rect<T> other, in T epsilon, Math.IDispatchComparable<T>? _ = null) where T : unmanaged, IEquatable<T>, IFormattable, ISpanFormattable, IEqualityOperators<T, T, bool>, IComparable<T>, INumberBase<T>
Parameters
rectRect<T>The first rectangle
otherRect<T>The second rectangle
epsilonTThe tolerance for equality
_Math.IDispatchComparable<T>Please ignore and do not explicitly set this parameter
Returns
Type Parameters
TThe type of the rectangle's coordinates and dimensions
Remarks
Two rectangles are considered equal if their Left and Top coordinates, and their Width and Height dimensions are within epsilon of each other.
If the type T is float, there's the EqualsWithinEpsilon(in Rect<float>, in Rect<float>, in float) overload which defaults epsilon to EpsilonF.
This method works for types of rect and other T which implement IComparable<T>.
If T implements both IComparable<T> and IComparisonOperators<TSelf, TOther, TResult>,
overload resolution prioritizes EqualsWithinEpsilon<T>(in Rect<T>, in Rect<T>, in T, IDispatchComparisonOperators<T>?) instead.
Please ignore and do not explicitly set the _ parameter. This parameter is just used in the method's signature to dispatch calls to this method for types of rect and other T which implement IComparable<T>.
EqualsWithinEpsilon<T>(in Rect<T>, in Rect<T>, in T, IDispatchComparisonOperators<T>?)
Indicates whether two rectangles are equal within a specified epsilon
public static bool EqualsWithinEpsilon<T>(this in Rect<T> rect, in Rect<T> other, in T epsilon, Math.IDispatchComparisonOperators<T>? _ = null) where T : unmanaged, IEquatable<T>, IFormattable, ISpanFormattable, IEqualityOperators<T, T, bool>, IComparisonOperators<T, T, bool>, INumberBase<T>
Parameters
rectRect<T>The first rectangle
otherRect<T>The second rectangle
epsilonTThe tolerance for equality
_Math.IDispatchComparisonOperators<T>Please ignore and do not explicitly set this parameter
Returns
Type Parameters
TThe type of the rectangle's coordinates and dimensions
Remarks
Two rectangles are considered equal if their Left and Top coordinates, and their Width and Height dimensions are within epsilon of each other.
If the type T is float, there's the EqualsWithinEpsilon(in Rect<float>, in Rect<float>, in float) overload which defaults epsilon to EpsilonF.
This method works for types of rect and other T which implement IComparisonOperators<TSelf, TOther, TResult>.
If T implements both IComparisonOperators<TSelf, TOther, TResult> and IComparable<T>,
overload resolution prioritizes this method.
Please ignore and do not explicitly set the _ parameter. This parameter is just used in the method's signature to dispatch calls to this method for types of rect and other T which implement IComparisonOperators<TSelf, TOther, TResult>.
HasIntersection(in Rect<int>, in Rect<int>)
Determines whether two rectangles intersect
public static bool HasIntersection(this in Rect<int> rect, in Rect<int> other)
Parameters
Returns
HasIntersection(in Rect<float>, in Rect<float>)
Determines whether two rectangles intersect
public static bool HasIntersection(this in Rect<float> rect, in Rect<float> other)
Parameters
Returns
IsEmpty<T>(in Rect<T>, IDispatchComparable<T>?)
Determines whether a rectangle has no area
public static bool IsEmpty<T>(this in Rect<T> rect, Math.IDispatchComparable<T>? _ = null) where T : unmanaged, IEquatable<T>, IFormattable, ISpanFormattable, IEqualityOperators<T, T, bool>, IComparable<T>, INumberBase<T>
Parameters
rectRect<T>The rectangle to check
_Math.IDispatchComparable<T>Please ignore and do not explicitly set this parameter
Returns
Type Parameters
TThe type of the rectangle's coordinates and dimensions
Remarks
A rectangles is considered empty if it's Width and/or it's Height are ≤ 0.
This method works for types of rect T which implement IComparable<T>.
If T implements both IComparable<T> and IComparisonOperators<TSelf, TOther, TResult>,
overload resolution prioritizes IsEmpty<T>(in Rect<T>, IDispatchComparisonOperators<T>?) instead.
Please ignore and do not explicitly set the _ parameter. This parameter is just used in the method's signature to dispatch calls to this method for types of rect T which implement IComparable<T>.
IsEmpty<T>(in Rect<T>, IDispatchComparisonOperators<T>?)
Determines whether a rectangle has no area
public static bool IsEmpty<T>(this in Rect<T> rect, Math.IDispatchComparisonOperators<T>? _ = null) where T : unmanaged, IEquatable<T>, IFormattable, ISpanFormattable, IEqualityOperators<T, T, bool>, IComparisonOperators<T, T, bool>, INumberBase<T>
Parameters
rectRect<T>The rectangle to check
_Math.IDispatchComparisonOperators<T>Please ignore and do not explicitly set this parameter
Returns
Type Parameters
TThe type of the rectangle's coordinates and dimensions
Remarks
A rectangles is considered empty if it's Width and/or it's Height are ≤ 0.
This method works for types of rect T which implement IComparisonOperators<TSelf, TOther, TResult>.
If T implements both IComparisonOperators<TSelf, TOther, TResult> and IComparable<T>,
overload resolution prioritizes this method.
Please ignore and do not explicitly set the _ parameter. This parameter is just used in the method's signature to dispatch calls to this method for types of rect T which implement IComparisonOperators<TSelf, TOther, TResult>.
ToFloatingPoint(in Rect<int>, out Rect<float>)
Converts a rectangle with integer coordinates and dimensions to a rectangle with floating point coordinates and dimensions
public static void ToFloatingPoint(this in Rect<int> rect, out Rect<float> result)
Parameters
rectRect<int>The rectangle to convert
resultRect<float>The resulting rectangle with floating point coordinates and dimensions
ToInteger(in Rect<float>, out Rect<int>)
Converts a rectangle with floating point coordinates and dimensions to a rectangle with integer coordinates and dimensions
public static void ToInteger(this in Rect<float> rect, out Rect<int> result)
Parameters
rectRect<float>The rectangle to convert
resultRect<int>The resulting rectangle with integer coordinates and dimensions
TryGetFromInnerPoints(ReadOnlySpan<Point<int>>, out Rect<int>)
Creates the smallest rectangle that encloses all the specified points
public static bool TryGetFromInnerPoints(ReadOnlySpan<Point<int>> points, out Rect<int> result)
Parameters
pointsReadOnlySpan<Point<int>>The points to enclose
resultRect<int>The resulting rectangle, if this method returns
true
Returns
TryGetFromInnerPoints(ReadOnlySpan<Point<int>>, in Rect<int>, out Rect<int>)
Creates the smallest rectangle that encloses all the specified points within the specified clipping rectangle
public static bool TryGetFromInnerPoints(ReadOnlySpan<Point<int>> points, in Rect<int> clip, out Rect<int> result)
Parameters
pointsReadOnlySpan<Point<int>>The points to enclose
clipRect<int>The clipping rectangle
resultRect<int>The resulting rectangle, if this method returns
true
Returns
Remarks
Only points that are within the specified clip rectangle are considered when creating the enclosing rectangle.
TryGetFromInnerPoints(ReadOnlySpan<Point<float>>, out Rect<float>)
Creates the smallest rectangle that encloses all the specified points
public static bool TryGetFromInnerPoints(ReadOnlySpan<Point<float>> points, out Rect<float> result)
Parameters
pointsReadOnlySpan<Point<float>>The points to enclose
resultRect<float>The resulting rectangle, if this method returns
true
Returns
TryGetFromInnerPoints(ReadOnlySpan<Point<float>>, in Rect<float>, out Rect<float>)
Creates the smallest rectangle that encloses all the specified points within the specified clipping rectangle
public static bool TryGetFromInnerPoints(ReadOnlySpan<Point<float>> points, in Rect<float> clip, out Rect<float> result)
Parameters
pointsReadOnlySpan<Point<float>>The points to enclose
clipRect<float>The clipping rectangle
resultRect<float>The resulting rectangle, if this method returns
true
Returns
Remarks
Only points that are within the specified clip rectangle are considered when creating the enclosing rectangle.
TryGetIntersection(in Rect<int>, in Rect<int>, out Rect<int>)
Determines the intersection of two rectangles, if any
public static bool TryGetIntersection(this in Rect<int> rect, in Rect<int> other, out Rect<int> result)
Parameters
rectRect<int>The first rectangle
otherRect<int>The second rectangle
resultRect<int>The resulting intersection rectangle, if this method returns
true
Returns
TryGetIntersection(in Rect<float>, in Rect<float>, out Rect<float>)
Determines the intersection of two rectangles, if any
public static bool TryGetIntersection(this in Rect<float> rect, in Rect<float> other, out Rect<float> result)
Parameters
rectRect<float>The first rectangle
otherRect<float>The second rectangle
resultRect<float>The resulting intersection rectangle, if this method returns
true
Returns
TryGetLineIntersection(in Rect<int>, ref Point<int>, ref Point<int>)
Determines the intersecting segment of a line and a rectangle, if any
public static bool TryGetLineIntersection(this in Rect<int> rect, ref Point<int> lineStart, ref Point<int> lineEnd)
Parameters
rectRect<int>The rectangle to intersect with
lineStartPoint<int>The start point of the line. If this method returns
true, this value will be updated to the start point of the intersection segment or remain unchanged if the point is contained within the rectangle.lineEndPoint<int>The end point of the line. If this method returns
true, this value will be updated to the end point of the intersection segment or remain unchanged if the point is contained within the rectangle.
Returns
Remarks
This method is used to clip a line segment to a rectangle.
A line segment contained entirely within the rectangle or that does not intersect will remain unchanged.
A line segment that crosses the rectangle at either or both ends will be clipped to the boundary of the rectangle and the new coordinates stored in lineStart and/or lineEnd as necessary.
TryGetLineIntersection(in Rect<int>, ref int, ref int, ref int, ref int)
Determines the intersecting segment of a line and a rectangle, if any
public static bool TryGetLineIntersection(this in Rect<int> rect, ref int x1, ref int y1, ref int x2, ref int y2)
Parameters
rectRect<int>The rectangle to intersect with
x1intThe x-coordinate of the start point of the line. If this method returns
true, this value will be updated to the x-coordinate of the nearer intersection point or remain unchanged if the start point is contained within the rectangle.y1intThe y-coordinate of the start point of the line. If this method returns
true, this value will be updated to the y-coordinate of the nearer intersection point or remain unchanged if the start point is contained within the rectangle.x2intThe x-coordinate of the end point of the line. If this method returns
true, this value will be updated to the x-coordinate of the farther intersection point or remain unchanged if the end point is contained within the rectangle.y2intThe y-coordinate of the end point of the line. If this method returns
true, this value will be updated to the y-coordinate of the farther intersection point or remain unchanged if the end point is contained within the rectangle.
Returns
Remarks
This method is used to clip a line segment to a rectangle.
A line segment contained entirely within the rectangle or that does not intersect will remain unchanged.
A line segment that crosses the rectangle at either or both ends will be clipped to the boundary of the rectangle and the new coordinates stored in x1, y1, x2, and/or y2 as necessary.
TryGetLineIntersection(in Rect<float>, ref Point<float>, ref Point<float>)
Determines the intersecting segment of a line and a rectangle, if any
public static bool TryGetLineIntersection(this in Rect<float> rect, ref Point<float> lineStart, ref Point<float> lineEnd)
Parameters
rectRect<float>The rectangle to intersect with
lineStartPoint<float>The start point of the line. If this method returns
true, this value will be updated to the start point of the intersection segment or remain unchanged if the point is contained within the rectangle.lineEndPoint<float>The end point of the line. If this method returns
true, this value will be updated to the end point of the intersection segment or remain unchanged if the point is contained within the rectangle.
Returns
Remarks
This method is used to clip a line segment to a rectangle.
A line segment contained entirely within the rectangle or that does not intersect will remain unchanged.
A line segment that crosses the rectangle at either or both ends will be clipped to the boundary of the rectangle and the new coordinates stored in lineStart and/or lineEnd as necessary.
TryGetLineIntersection(in Rect<float>, ref float, ref float, ref float, ref float)
Determines the intersecting segment of a line and a rectangle, if any
public static bool TryGetLineIntersection(this in Rect<float> rect, ref float x1, ref float y1, ref float x2, ref float y2)
Parameters
rectRect<float>The rectangle to intersect with
x1floatThe x-coordinate of the start point of the line. If this method returns
true, this value will be updated to the x-coordinate of the nearer intersection point or remain unchanged if the start point is contained within the rectangle.y1floatThe y-coordinate of the start point of the line. If this method returns
true, this value will be updated to the y-coordinate of the nearer intersection point or remain unchanged if the start point is contained within the rectangle.x2floatThe x-coordinate of the end point of the line. If this method returns
true, this value will be updated to the x-coordinate of the farther intersection point or remain unchanged if the end point is contained within the rectangle.y2floatThe y-coordinate of the end point of the line. If this method returns
true, this value will be updated to the y-coordinate of the farther intersection point or remain unchanged if the end point is contained within the rectangle.
Returns
Remarks
This method is used to clip a line segment to a rectangle.
A line segment contained entirely within the rectangle or that does not intersect will remain unchanged.
A line segment that crosses the rectangle at either or both ends will be clipped to the boundary of the rectangle and the new coordinates stored in x1, y1, x2, and/or y2 as necessary.
TryGetUnion(in Rect<int>, in Rect<int>, out Rect<int>)
Determines the union of two rectangles
public static bool TryGetUnion(this in Rect<int> rect, in Rect<int> other, out Rect<int> result)
Parameters
rectRect<int>The first rectangle
otherRect<int>The second rectangle
resultRect<int>The resulting union rectangle, if this method returns
true
Returns
- bool
true, if the rectangles intersect; otherwise,false(check TryGet(out string?) for more information)
TryGetUnion(in Rect<float>, in Rect<float>, out Rect<float>)
Determines the union of two rectangles
public static bool TryGetUnion(this in Rect<float> rect, in Rect<float> other, out Rect<float> result)
Parameters
rectRect<float>The first rectangle
otherRect<float>The second rectangle
resultRect<float>The resulting union rectangle, if this method returns
true
Returns
- bool
true, if the rectangles intersect; otherwise,false(check TryGet(out string?) for more information)