Table of Contents

Class Rect

Namespace
Sdl3Sharp.Video.Drawing
Assembly
Sdl3Sharp.dll

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

rect Rect<T>

The rectangle to check

point Point<T>

The point to check

_ Math.IDispatchComparable<T>

Please ignore and do not explicitly set this parameter

Returns

bool

true, if the point is contained within the rectangle; otherwise, false

Type Parameters

T

The 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

rect Rect<T>

The rectangle to check

point Point<T>

The point to check

_ Math.IDispatchComparisonOperators<T>

Please ignore and do not explicitly set this parameter

Returns

bool

true, if the point is contained within the rectangle; otherwise, false

Type Parameters

T

The 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

rect Rect<float>

The first rectangle

other Rect<float>

The second rectangle

epsilon float

The tolerance for equality. Defaults to EpsilonF.

Returns

bool

true, if the rectangles are considered equal within the specified epsilon; otherwise, false

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

rect Rect<T>

The first rectangle

other Rect<T>

The second rectangle

epsilon T

The tolerance for equality

_ Math.IDispatchComparable<T>

Please ignore and do not explicitly set this parameter

Returns

bool

true, if the rectangles are considered equal within the specified epsilon; otherwise, false

Type Parameters

T

The 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

rect Rect<T>

The first rectangle

other Rect<T>

The second rectangle

epsilon T

The tolerance for equality

_ Math.IDispatchComparisonOperators<T>

Please ignore and do not explicitly set this parameter

Returns

bool

true, if the rectangles are considered equal within the specified epsilon; otherwise, false

Type Parameters

T

The 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

rect Rect<int>

The first rectangle

other Rect<int>

The second rectangle

Returns

bool

true, if the rectangles intersect; otherwise, false

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

rect Rect<float>

The first rectangle

other Rect<float>

The second rectangle

Returns

bool

true, if the rectangles intersect; otherwise, false

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

rect Rect<T>

The rectangle to check

_ Math.IDispatchComparable<T>

Please ignore and do not explicitly set this parameter

Returns

bool

true, if the rectangle is considered empty; otherwise, false

Type Parameters

T

The 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

rect Rect<T>

The rectangle to check

_ Math.IDispatchComparisonOperators<T>

Please ignore and do not explicitly set this parameter

Returns

bool

true, if the rectangle is considered empty; otherwise, false

Type Parameters

T

The 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

rect Rect<int>

The rectangle to convert

result Rect<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

rect Rect<float>

The rectangle to convert

result Rect<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

points ReadOnlySpan<Point<int>>

The points to enclose

result Rect<int>

The resulting rectangle, if this method returns true

Returns

bool

true, if the rectangle was created successfully; otherwise, false

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

points ReadOnlySpan<Point<int>>

The points to enclose

clip Rect<int>

The clipping rectangle

result Rect<int>

The resulting rectangle, if this method returns true

Returns

bool

true, if the rectangle was created successfully; otherwise, false

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

points ReadOnlySpan<Point<float>>

The points to enclose

result Rect<float>

The resulting rectangle, if this method returns true

Returns

bool

true, if the rectangle was created successfully; otherwise, false

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

points ReadOnlySpan<Point<float>>

The points to enclose

clip Rect<float>

The clipping rectangle

result Rect<float>

The resulting rectangle, if this method returns true

Returns

bool

true, if the rectangle was created successfully; otherwise, false

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

rect Rect<int>

The first rectangle

other Rect<int>

The second rectangle

result Rect<int>

The resulting intersection rectangle, if this method returns true

Returns

bool

true, if the rectangles intersect; otherwise, false

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

rect Rect<float>

The first rectangle

other Rect<float>

The second rectangle

result Rect<float>

The resulting intersection rectangle, if this method returns true

Returns

bool

true, if the rectangles intersect; otherwise, false

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

rect Rect<int>

The rectangle to intersect with

lineStart Point<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.

lineEnd Point<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

bool

true, if the line intersects with the rectangle; otherwise, false

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

rect Rect<int>

The rectangle to intersect with

x1 int

The 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.

y1 int

The 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.

x2 int

The 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.

y2 int

The 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

bool

true, if the line intersects with the rectangle; otherwise, false

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

rect Rect<float>

The rectangle to intersect with

lineStart Point<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.

lineEnd Point<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

bool

true, if the line intersects with the rectangle; otherwise, false

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

rect Rect<float>

The rectangle to intersect with

x1 float

The 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.

y1 float

The 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.

x2 float

The 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.

y2 float

The 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

bool

true, if the line intersects with the rectangle; otherwise, false

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

rect Rect<int>

The first rectangle

other Rect<int>

The second rectangle

result Rect<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

rect Rect<float>

The first rectangle

other Rect<float>

The second rectangle

result Rect<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)