RectangleExtensionMethods

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

Methods

AdjustSides

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

AdjustSides

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

AdjustSides

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

AdjustSides

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

AdjustSides

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

AdjustSides

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

BoundingBox

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

BoundingBox

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

BoundingBox

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

BoundingBox

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

Ceiling

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

Ceiling

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

Centre

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

Centre

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

ClosestPointIn

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

ClosestPointIn

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

ClosestPointOn

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

ClosestPointOn

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

Contains

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

Contains

#Example
public static bool Contains(this RectangleF rectangle, PointF point, float padding)
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.
rectangle (RectangleF)Rectangle.
point (PointF)Point.
padding (float)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
public static bool ContainsInEllipse(this Rectangle rectangle, PointF point)
Test whether the point is inside the ellipse bounded by the rectangle.
rectangle (Rectangle)Bounding rectangle.
point (PointF)Point to test.
True if point is inside ellipse.

ContainsInEllipse

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

Corners

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

Corners

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

DistanceTo

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

DistanceTo

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

DistanceTo

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

DistanceTo

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

FurthestPoint

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

FurthestPoint

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

Interpolate

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

Intersects

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

MakeIncreasing

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

MakeIncreasing

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

MoveInto

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

Offset

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

Perimeter

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

PointAt

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

PointAt

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

Radius

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

Radius

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

RectangleAt

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

SplitHorizontal

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

SplitHorizontal

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

SplitVertical

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

SplitVertical

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

SplitVertical

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

Subdivide

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

ToInnerRectangle

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

ToInnerRectangle

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

ToInnerSquare

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

ToInnerSquare

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

ToOuterRectangle

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

ToOuterRectangle

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

ToOuterSquare

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

ToOuterSquare

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

ToRectangle

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

ToRectangle3d

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

ToRectangle3d

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

ToRounded

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

ToRoundedEdge

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

ToRoundedRectangle

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

ToRoundedRectangle

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

ToRoundedRectangle

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

ToRoundedRectangle

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