RectangleExtensionMethods

public static class RectangleExtensionMethods
Extension methods for Eto.Drawing.Rectangle and Eto.Drawing.RectangleF

Methods

AdjustSides

#Example
Adjust the sides of a rectangle.
public static Rectangle AdjustSides(
this Rectangle
rectangle,
Rectangle to adjust.
amount
Adjustment amount. Positive distances mean outwards growth.
)
Adjusted rectangle.

AdjustSides

#Example
Adjust the sides of a rectangle.
public static Rectangle AdjustSides(
this Rectangle
rectangle,
Rectangle to adjust.
horizontal,
Horizontal adjustment amount. Positive distances mean outwards growth.
vertical
Vertical adjustment amount. Positive distances mean outwards growth.
)
Adjusted rectangle.

AdjustSides

#Example
Adjust the sides of a rectangle.
public static Rectangle AdjustSides(
this Rectangle
rectangle,
Rectangle to adjust.
left,
Leftwards adjustment amount. Positive distances mean outwards growth.
top,
Upwards adjustment amount. Positive distances mean outwards growth.
right,
Rightwards adjustment amount. Positive distances mean outwards growth.
bottom
Downwards adjustment amount. Positive distances mean outwards growth.
)
Adjusted rectangle.

AdjustSides

#Example
Adjust the sides of a rectangle.
public static RectangleF AdjustSides(
this RectangleF
rectangle,
Rectangle to adjust.
amount
Offset distance. Positive distances mean outwards offset.
)
Adjusted rectangle.

AdjustSides

#Example
Adjust the sides of a rectangle.
public static RectangleF AdjustSides(
this RectangleF
rectangle,
Rectangle to adjust.
horizontal,
Horizontal adjustment amount. Positive distances mean outwards growth.
vertical
Vertical adjustment amount. Positive distances mean outwards growth.
)
Adjusted rectangle.

AdjustSides

#Example
Adjust the sides of a rectangle.
public static RectangleF AdjustSides(
this RectangleF
rectangle,
Rectangle to adjust.
left,
Leftwards adjustment amount. Positive distances mean outwards growth.
top,
Upwards adjustment amount. Positive distances mean outwards growth.
right,
Rightwards adjustment amount. Positive distances mean outwards growth.
bottom
Downwards adjustment amount. Positive distances mean outwards growth.
)
Adjusted rectangle.
Move a rectangle so that the indicated edge aligns with the given coordinate.
public static RectangleF Align(
this RectangleF
rectangle,
Rectangle to move.
edge,
Edge to align.
coordinate
Edge coordinate.
)
Gets the (unsigned) area of a rectangle.
public static float Area(
this RectangleF
rectangle
)

BoundingBox

#Example
Gets the bounding rectangle for a collection of points.
public static Rectangle BoundingBox(
points
Points to bound.
)
Bounding rectangle.

BoundingBox

#Example
Gets the bounding rectangle for a collection of rectangles.
public static Rectangle BoundingBox(
this IEnumerable<Rectangle>
rectangles
Rectangles to bound.
)
Bounding rectangle.

BoundingBox

#Example
Gets the bounding rectangle for a collection of points.
public static RectangleF BoundingBox(
this IEnumerable<PointF>
points
Points to bound.
)
Bounding rectangle.

BoundingBox

#Example
Gets the bounding rectangle for a collection of rectangles.
public static RectangleF BoundingBox(
this IEnumerable<RectangleF>
rectangles
Rectangles to bound.
)
Bounding rectangle.

Ceiling

#Example
Round a rectangle to the nearest integer coordinates ensuring only ever to grow the rectangle content.
public static RectangleF Ceiling(
this RectangleF
rectangle
Rectangle to round.
)
Adjusted rectangle.

Ceiling

#Example
Round the width and height of a size to the nearest bigger integer.
public static SizeF Ceiling(
this SizeF
size
Size to round.
)
Adjusted size.

Centre

#Example
Gets the point that best describes the centre of a rectangle.
public static Point Centre(
this Rectangle
rectangle
Rectangle.
)
Centre point.

Centre

#Example
Gets the point that best describes the centre of a rectangle.
public static PointF Centre(
this RectangleF
rectangle
Rectangle.
)
Centre point.

ClosestPointIn

#Example
Project a point onto the interior of a rectangle.
public static Point ClosestPointIn(
this Rectangle
rectangle,
Rectangle to project onto.
point
Point to project.
)
Point on rectangle closest to the point.

ClosestPointIn

#Example
Project a point onto the interior of a rectangle.
public static PointF ClosestPointIn(
this RectangleF
rectangle,
Rectangle to project onto.
PointF
point
Point to project.
)
Point on rectangle closest to the point.

ClosestPointOn

#Example
Project a point onto the boundary of a rectangle.
public static Point ClosestPointOn(
this Rectangle
rectangle,
Rectangle to project onto.
point
Point to project.
)
Point on rectangle boundary closest to the point.

ClosestPointOn

#Example
Project a point onto the boundary of a rectangle.
public static PointF ClosestPointOn(
this RectangleF
rectangle,
Rectangle to project onto.
PointF
point
Point to project.
)
Point on rectangle closest to the point.

Contains

#Example
Test whether a point is inside a rectangle.
public static bool Contains(
this Rectangle
rectangle,
Rectangle.
PointF
point
Point.
)
True if the point is inside the rectangle.

Contains

#Example
Test whether a point is contained within a rectangle. This method is better than the Eto standard RectangleF.Contains as it correctly checks all edges.
public static bool Contains(
this RectangleF
rectangle,
Rectangle.
PointF
point,
Point.
padding
Amount of padding to add to outside of rectangle. I.e. if the padding is 2, then the point is 'inside' the rectangle when it's within 2 units of the boundary.
)

ContainsInEllipse

#Example
Test whether the point is inside the ellipse bounded by the rectangle.
public static bool ContainsInEllipse(
this Rectangle
rectangle,
Bounding rectangle.
PointF
point
Point to test.
)
True if point is inside ellipse.

ContainsInEllipse

#Example
Test whether the point is inside the ellipse bounded by the rectangle.
public static bool ContainsInEllipse(
this RectangleF
rectangle,
Bounding rectangle.
PointF
point
Point to test.
)
True if point is inside ellipse.

Corners

#Example
Gets the rectangle corners, ordered counter-clockwise starting from the lower left corner.
public static Point[] Corners(
this Rectangle
rectangle
)
An array of 4 points representing the corners of the rectangle.

Corners

#Example
Gets the rectangle corners, ordered counter-clockwise starting from the lower left corner.
public static PointF[] Corners(
this RectangleF
rectangle
)
An array of 4 points representing the corners of the rectangle.

DistanceTo

#Example
Gets the distance from this rectangle to a point. Any point in or on the rectangle has a distance of zero.
public static double DistanceTo(
this Rectangle
rectangle,
Rectangle.
point
Point.
)
Distance between point and rectangle.

DistanceTo

#Example
Gets the distance from this rectangle to a point. Any point in or on the rectangle has a distance of zero.
public static double DistanceTo(
this Rectangle
rectangle,
Rectangle.
PointF
point
Point.
)
Distance between point and rectangle.

DistanceTo

#Example
Gets the distance from this rectangle to a point. Any point in or on the rectangle has a distance of zero.
public static double DistanceTo(
this RectangleF
rectangle,
Rectangle.
PointF
point
Point.
)
Distance between point and rectangle.

DistanceTo

#Example
Gets the distance between two rectangles.
public static double DistanceTo(
this RectangleF
rectangle,
Rectangle.
RectangleF
other
Rectangle.
)
Distance between both rectangles.
Move a rectangle down so that the new top lines up with the old bottom.
public static RectangleF Down(
this RectangleF
rectangle
)
Gets the edge of a rectangle.
public static LineF Edge(
this RectangleF
rectangle,
Rectangle.
edge,
Edge.
clockwise
Clockwise direction.
)
Round a rectangle to the nearest integer coordinates ensuring only ever to shrink the rectangle content.
public static RectangleF Floor(
this RectangleF
rectangle
Rectangle to round.
)
Adjusted rectangle.
Round the width and height of a size to the nearest smaller integer.
public static SizeF Floor(
this SizeF
size
Size to round.
)
Adjusted size.

FurthestPoint

#Example
Find the point on the rectangle that is furthest from some base point.
public static Point FurthestPoint(
this Rectangle
rectangle,
Rectangle.
point
Point to search from.
)
Point on rectangle furthest from base point.

FurthestPoint

#Example
Find the point on the rectangle that is furthest from some base point.
public static PointF FurthestPoint(
this RectangleF
rectangle,
Rectangle.
PointF
point
Point to search from.
)
Point on rectangle furthest from base point.
Grow a rectangle until it contains a given point.
public static Rectangle Grow(
this Rectangle
rectangle,
Rectangle to grow.
point
Point to include.
)
Grown rectangle.
Grow a rectangle until it contains a given point.
public static RectangleF Grow(
this RectangleF
rectangle,
Rectangle to grow.
PointF
point
Point to include.
)
Grown rectangle.

Interpolate

#Example
Interpolate between two rectangles.
public static RectangleF Interpolate(
this RectangleF
rectangle,
Starting rectangle.
RectangleF
target,
Final rectangle.
motion
Normalised interpolation factor.
)

Intersects

#Example
Test whether two boxes intersect within tolerance.
public static bool Intersects(
boxA,
boxB,
tolerance
)
Move a rectangle left so that the new right lines up with the old left.
public static RectangleF Left(
this RectangleF
rectangle
)

MakeIncreasing

#Example
Make sure the width and height of a rectangle are increasing.
public static Rectangle MakeIncreasing(
this Rectangle
rectangle
)

MakeIncreasing

#Example
Make sure the width and height of a rectangle are increasing.
public static RectangleF MakeIncreasing(
this RectangleF
rectangle
)
Move a rectangle.
public static Rectangle Move(
this Rectangle
rectangle,
Rectangle to move.
dx,
Motion in X.
dy
Motion in Y.
)
Moved rectangle.
Move a rectangle.
public static RectangleF Move(
this RectangleF
rectangle,
Rectangle to move.
dx,
Motion in X.
dy
Motion in Y.
)
Moved rectangle.

MoveInto

#Example
Move this rectangle such that it is entirely within another one, whenever possible.
public static Rectangle MoveInto(
this Rectangle
rectangle,
Rectangle to move.
Rectangle
boundary
Bounding rectangle.
)

Offset

#Example
Offset a rectangle.
public static Rectangle3d Offset(
rectangle,
Rectangle.
offset
Offset distance. Positive values offset towards the outside.
)

Perimeter

#Example
Gets the (unsigned) perimeter or circumference of a rectangle.
public static float Perimeter(
this RectangleF
rectangle
)

PointAt

#Example
Gets the point at a rectangle parameter.
public static PointF PointAt(
this Rectangle
rectangle,
Rectangle.
tx,
X parameter (tx=0 means the left edge, tx=1 means the right edge).
ty
Y parameter (ty=0 means the top edge, ty=1 means the bottom edge).
)
Point at the given coordinates.

PointAt

#Example
Gets the point at a rectangle parameter.
public static PointF PointAt(
this RectangleF
rectangle,
Rectangle.
tx,
X parameter (tx=0 means the left edge, tx=1 means the right edge).
ty
Y parameter (ty=0 means the top edge, ty=1 means the bottom edge).
)
Point at the given coordinates.

Radius

#Example
Gets the radius of the rectangle (distance from the centre to a corner).
public static float Radius(
this Rectangle
rectangle
Rectangle to measure.
)
Radius of rectangle.

Radius

#Example
Gets the radius of the rectangle (distance from the centre to a corner).
public static float Radius(
this RectangleF
rectangle
Rectangle to measure.
)
Radius of rectangle.

RectangleAt

#Example
Create a rectangle from normalised coordinates.
public static RectangleF RectangleAt(
this RectangleF
rectangle,
Base rectangle.
x0,
Sub rectangle x0 parameter.
x1,
Sub rectangle x1 parameter.
y0,
Sub rectangle y0 parameter.
y1
Sub rectangle y1 parameter.
)
Sub rectangle.
Move a rectangle left so that the new left lines up with the old right.
public static RectangleF Right(
this RectangleF
rectangle
)
Round the coordinates of a rectangle.
public static RectangleF Round(
this RectangleF
rectangle,
Rectangle to modify.
decimals
Number of decimals.
)
Rectangle with coordinates rounded to a specific number of decimal places.
Round a rectangle to integer coordinates.
public static RectangleF Round(
this RectangleF
rectangle
Rectangle to modify.
)
Rectangle with coordinates rounded to nearest integers.
Round the coordinates of a rectangle.
public static SizeF Round(
this SizeF
size,
Size to modify.
decimals
Number of decimals.
)
Size with rounded dimensions.
Round a size to integer coordinates.
public static SizeF Round(
this SizeF
size
Size to modify.
)
Size with rounded dimensions.
Scale a rectangle around its centre by a specific factor.
public static RectangleF Scale(
this RectangleF
rectangle,
Rectangle to scale.
factor
Scaling factor.
)
Scaled rectangle.

SplitHorizontal

#Example
Split a rectangle into two.
public static void SplitHorizontal(
this Rectangle
rectangle,
Rectangle to split.
x,
X coordinate to split at.
out Rectangle
left,
Rectangle to left of split.
out Rectangle
right
Rectangle to right of split.
)

SplitHorizontal

#Example
Split a rectangle into two.
public static void SplitHorizontal(
this RectangleF
rectangle,
Rectangle to split.
x,
X coordinate to split at.
out RectangleF
left,
Rectangle to left of split.
out RectangleF
right
Rectangle to right of split.
)

SplitVertical

#Example
Split a rectangle into two.
public static void SplitVertical(
this Rectangle
rectangle,
Rectangle to split.
y,
Y coordinate to split at.
out Rectangle
above,
Rectangle above split.
out Rectangle
below
Rectangle below split.
)

SplitVertical

#Example
Split a rectangle into two.
public static void SplitVertical(
this RectangleF
rectangle,
Rectangle to split.
y,
Y coordinate to split at.
out RectangleF
above,
Rectangle above split.
out RectangleF
below
Rectangle below split.
)

SplitVertical

#Example
Split a rectangle into three.
public static void SplitVertical(
this RectangleF
rectangle,
Rectangle to split.
y0,
First Y coordinate to split at.
y1,
Second Y coordinate to split at.
out RectangleF
above,
Rectangle above split.
out RectangleF
middle,
Rectangle in between splits.
out RectangleF
below
Rectangle below split.
)

Subdivide

#Example
Create an array (row-by-row) of division rectangles.
public static RectangleF[] Subdivide(
this RectangleF
rectangle,
Base rectangle.
columns,
Number of columns.
rows
Number of rows.
)
Array of rectangles.

ToInnerRectangle

#Example
Create the largest possible rectangle inside another rectangle with a specific width/height ratio.
public static Rectangle ToInnerRectangle(
this Rectangle
rectangle,
Rectangle to fit into.
Size
ratio
Ratio of fitted rectangle.
)
Fitted rectangle.

ToInnerRectangle

#Example
Create the largest possible rectangle inside another rectangle with a specific width/height ratio.
public static RectangleF ToInnerRectangle(
this RectangleF
rectangle,
Rectangle to fit into.
SizeF
ratio
Ratio of fitted rectangle.
)
Fitted rectangle.

ToInnerSquare

#Example
Convert a rectangle to the biggest square that fits inside it.
public static Rectangle ToInnerSquare(
this Rectangle
rectangle
Rectangle to square.
)
Biggest square that fits inside rectangle.

ToInnerSquare

#Example
Convert a rectangle to the smallest square containing it.
public static RectangleF ToInnerSquare(
this RectangleF
rectangle
Rectangle to square.
)
Biggest square that fits inside rectangle.

ToOuterRectangle

#Example
Create the smallest possible rectangle outside another rectangle with a specific width/height ratio.
public static Rectangle ToOuterRectangle(
this Rectangle
rectangle,
Rectangle to wrap around.
Size
ratio
Ratio of wrapped rectangle.
)
Wrapped rectangle.

ToOuterRectangle

#Example
Create the smallest possible rectangle outside another rectangle with a specific width/height ratio.
public static RectangleF ToOuterRectangle(
this RectangleF
rectangle,
Rectangle to wrap around.
SizeF
ratio
Ratio of wrapped rectangle.
)
Wrapped rectangle.

ToOuterSquare

#Example
Convert a rectangle to the smallest square containing it.
public static Rectangle ToOuterSquare(
this Rectangle
rectangle
Rectangle to square.
)
Smallest square containing rectangle.

ToOuterSquare

#Example
Convert a rectangle to the smallest square containing it.
public static RectangleF ToOuterSquare(
this RectangleF
rectangle
Rectangle to square.
)
Smallest square containing rectangle.

ToRectangle

#Example
Convert a RectangleF into a Rectangle.
public static Rectangle ToRectangle(
this RectangleF
rectangle
Rectangle to convert.
)
Rectangle.

ToRectangle3d

#Example
Convert an Eto rectangle into a Rhino rectangle.
public static Rectangle3d ToRectangle3d(
this Rectangle
rectangle
Rectangle to convert.
)
Rhino rectangle.

ToRectangle3d

#Example
Convert an Eto rectangle into a Rhino rectangle.
public static Rectangle3d ToRectangle3d(
this RectangleF
rectangle
Rectangle to convert.
)
Rhino rectangle.

ToRounded

#Example
Fillet the corners of a rectangle. The radius is automatically shrunk to avoid self-intersections.
public static Curve ToRounded(
rectangle,
radius
)

ToRoundedEdge

#Example
Create a graphicspath that describes slab edges within a rounded rectangle.
public static GraphicsPath ToRoundedEdge(
this RectangleF
rectangle,
Bounding rectangle.
radius,
Radius of edge.
thickness,
Thickness of edge.
edge
Edges.
)
Graphicspath describing the edges or null if no edges could be solved.

ToRoundedRectangle

#Example
Create a graphics path that represents a rounded rectangle.
public static GraphicsPath ToRoundedRectangle(
this Rectangle
rectangle,
Rectangle.
radii
Corner radii.
)

ToRoundedRectangle

#Example
Create a graphics path that represents a rounded rectangle.
public static GraphicsPath ToRoundedRectangle(
this Rectangle
rectangle,
Rectangle.
radii
Corner radii.
)
Graphics path.

ToRoundedRectangle

#Example
Create a graphics path that represents a rounded rectangle.
public static GraphicsPath ToRoundedRectangle(
this RectangleF
rectangle,
Rectangle.
radii
Corner radii.
)
Graphics path.

ToRoundedRectangle

#Example
Create a graphics path that represents a rounded rectangle.
public static GraphicsPath ToRoundedRectangle(
this RectangleF
rectangle,
Rectangle.
radii
Corner radii.
)
Graphics path.
Move a rectangle up so that the new bottom lines up with the old top.
public static RectangleF Up(
this RectangleF
rectangle
)