Table of Contents

Class RectangleMathExtensions

Namespace
Splat
Assembly
Splat.dll

Provides extension methods for performing advanced mathematical and geometric operations on RectangleF instances.

public static class RectangleMathExtensions
Inheritance
RectangleMathExtensions

Remarks

This static class includes methods for calculating the center point, dividing rectangles (with or without padding), inverting rectangles within a containing rectangle, and creating modified copies of rectangles. These utilities are intended to simplify common rectangle manipulations in graphical and layout scenarios.

Methods

Center(RectangleF)

Calculates the center point of the specified rectangle.

public static PointF Center(this RectangleF value)

Parameters

value RectangleF

The rectangle for which to determine the center point.

Returns

PointF

A PointF representing the center of the specified rectangle.

Copy(RectangleF, float?, float?, float?, float?, float?, float?)

Creates a copy of the specified rectangle, optionally overriding one or more of its position or size components.

public static RectangleF Copy(this RectangleF value, float? x = null, float? y = null, float? width = null, float? height = null, float? top = null, float? bottom = null)

Parameters

value RectangleF

The rectangle to copy.

x float?

The value to use for the X coordinate of the new rectangle. If null, the original X value is used. Cannot be specified together with top.

y float?

The value to use for the Y coordinate of the new rectangle. If null, the original Y value is used. Cannot be specified together with top.

width float?

The value to use for the width of the new rectangle. If null, the original width is used. Cannot be specified together with bottom.

height float?

The value to use for the height of the new rectangle. If null, the original height is used. Cannot be specified together with bottom.

top float?

The value to use for the top (Y coordinate) of the new rectangle. If specified, y must be null.

bottom float?

The value to use for the bottom edge of the new rectangle, relative to the Y coordinate. If specified, height must be null.

Returns

RectangleF

A new RectangleF instance with the specified components replaced as provided.

Remarks

If both y and top are specified, or both height and bottom are specified, an exception is thrown due to conflicting arguments.

Divide(RectangleF, float, RectEdge)

Divides the specified rectangle into two rectangles by splitting off a region of the given size from one edge.

public static Tuple<RectangleF, RectangleF> Divide(this RectangleF value, float amount, RectEdge fromEdge)

Parameters

value RectangleF

The rectangle to divide.

amount float

The size, in the same units as the rectangle, of the region to split from the specified edge. Must be non-negative and less than or equal to the corresponding dimension of the rectangle.

fromEdge RectEdge

The edge from which to split the region. Specifies which side of the rectangle the split is performed from.

Returns

Tuple<RectangleF, RectangleF>

A tuple containing two rectangles: the first is the region split from the specified edge with the given size, and the second is the remainder of the original rectangle. The sum of their areas equals the area of the original rectangle.

Remarks

If the specified amount is zero, the first rectangle will have zero width or height, depending on the edge, and the second rectangle will be equal to the original. If the amount equals the rectangle's width or height (as appropriate), the second rectangle will have zero width or height. Throws an exception if the amount is negative or exceeds the rectangle's dimension along the specified edge.

DivideWithPadding(RectangleF, float, float, RectEdge)

Divides the specified rectangle into two regions along the given edge, separating them by a specified padding.

public static Tuple<RectangleF, RectangleF> DivideWithPadding(this RectangleF value, float sliceAmount, float padding, RectEdge fromEdge)

Parameters

value RectangleF

The rectangle to be divided.

sliceAmount float

The size, in the same units as the rectangle, of the first region to slice from the specified edge. Must be non-negative.

padding float

The size, in the same units as the rectangle, of the padding to insert between the two resulting regions. Must be non-negative.

fromEdge RectEdge

The edge of the rectangle from which to perform the division.

Returns

Tuple<RectangleF, RectangleF>

A tuple containing two rectangles: the first is the sliced region, and the second is the remaining region after the slice and padding have been removed.

Remarks

If the sum of sliceAmount and padding exceeds the corresponding dimension of the rectangle, the resulting rectangles may have zero or negative size. The method does not modify the original rectangle.

InvertWithin(RectangleF, RectangleF)

Returns a new rectangle that is vertically inverted within the specified containing rectangle.

public static RectangleF InvertWithin(this RectangleF value, RectangleF containingRect)

Parameters

value RectangleF

The rectangle to invert within the containing rectangle.

containingRect RectangleF

The rectangle that defines the bounds within which to invert the position of value.

Returns

RectangleF

A RectangleF representing the vertically inverted position of value within containingRect. The size of the rectangle remains unchanged.

Remarks

The method inverts the Y-coordinate of the rectangle so that its position is mirrored vertically within the containing rectangle. This is commonly used to convert between coordinate systems with different vertical origins.