RectangleExtensionMethods
Extension methods for Eto.Drawing.Rectangle and Eto.Drawing.RectangleF
Methods
Adjust the sides of a rectangle.
Parameters:
| rectangle (Rectangle) | Rectangle to adjust. |
| amount (int) | Adjustment amount. Positive distances mean outwards growth. |
Returns: Adjusted rectangle.
Adjust the sides of a rectangle.
Adjust the sides of a rectangle.
Parameters:
| 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. |
Returns: Adjusted rectangle.
Adjust the sides of a rectangle.
Parameters:
| rectangle (RectangleF) | Rectangle to adjust. |
| amount (float) | Offset distance. Positive distances mean outwards offset. |
Returns: Adjusted rectangle.
Adjust the sides of a rectangle.
Adjust the sides of a rectangle.
Parameters:
| 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. |
Returns: Adjusted rectangle.
Move a rectangle so that the indicated edge aligns with the given coordinate.
Parameters:
| rectangle (RectangleF) | Rectangle to move. |
| edge (RectangleEdge) | Edge to align. |
| coordinate (float) | Edge coordinate. |
Gets the (unsigned) area of a rectangle.
Parameters:
| rectangle (RectangleF) |
Gets the bounding rectangle for a collection of points.
Parameters:
| points (IEnumerable<Point>) | Points to bound. |
Returns: Bounding rectangle.
Gets the bounding rectangle for a collection of rectangles.
Parameters:
| rectangles (IEnumerable<Rectangle>) | Rectangles to bound. |
Returns: Bounding rectangle.
Gets the bounding rectangle for a collection of points.
Parameters:
| points (IEnumerable<PointF>) | Points to bound. |
Returns: Bounding rectangle.
Gets the bounding rectangle for a collection of rectangles.
Parameters:
| rectangles (IEnumerable<RectangleF>) | Rectangles to bound. |
Returns: Bounding rectangle.
public static RectangleF Ceiling(this RectangleF rectangle)
Round a rectangle to the nearest integer coordinates ensuring only ever to grow the rectangle content.
Parameters:
| rectangle (RectangleF) | Rectangle to round. |
Returns: Adjusted rectangle.
public static SizeF Ceiling(this SizeF size)
Round the width and height of a size to the nearest bigger integer.
Parameters:
| size (SizeF) | Size to round. |
Returns: Adjusted size.
Gets the point that best describes the centre of a rectangle.
Parameters:
| rectangle (Rectangle) | Rectangle. |
Returns: Centre point.
public static PointF Centre(this RectangleF rectangle)
Gets the point that best describes the centre of a rectangle.
Parameters:
| rectangle (RectangleF) | Rectangle. |
Returns: Centre point.
Project a point onto the interior of a rectangle.
Parameters:
| rectangle (Rectangle) | Rectangle to project onto. |
| point (Point) | Point to project. |
Returns: Point on rectangle closest to the point.
public static PointF ClosestPointIn(this RectangleF rectangle, PointF point)
Project a point onto the interior of a rectangle.
Parameters:
| rectangle (RectangleF) | Rectangle to project onto. |
| point (PointF) | Point to project. |
Returns: Point on rectangle closest to the point.
Project a point onto the boundary of a rectangle.
Parameters:
| rectangle (Rectangle) | Rectangle to project onto. |
| point (Point) | Point to project. |
Returns: Point on rectangle boundary closest to the point.
public static PointF ClosestPointOn(this RectangleF rectangle, PointF point)
Project a point onto the boundary of a rectangle.
Parameters:
| rectangle (RectangleF) | Rectangle to project onto. |
| point (PointF) | Point to project. |
Returns: Point on rectangle closest to the point.
Test whether a point is inside a rectangle.
Parameters:
| rectangle (Rectangle) | Rectangle. |
| point (PointF) | Point. |
Returns: True if the point is inside the rectangle.
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.
Parameters:
| 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. |
Test whether the point is inside the ellipse bounded by the rectangle.
Parameters:
| rectangle (Rectangle) | Bounding rectangle. |
| point (PointF) | Point to test. |
Returns: True if point is inside ellipse.
Test whether the point is inside the ellipse bounded by the rectangle.
Parameters:
| rectangle (RectangleF) | Bounding rectangle. |
| point (PointF) | Point to test. |
Returns: True if point is inside ellipse.
Gets the rectangle corners, ordered counter-clockwise starting from the lower left corner.
Parameters:
| rectangle (Rectangle) |
Returns: An array of 4 points representing the corners of the rectangle.
public static PointF[] Corners(this RectangleF rectangle)
Gets the rectangle corners, ordered counter-clockwise starting from the lower left corner.
Parameters:
| rectangle (RectangleF) |
Returns: An array of 4 points representing the corners of the rectangle.
Gets the distance from this rectangle to a point. Any point in or on the rectangle has a distance of zero.
Parameters:
| rectangle (Rectangle) | Rectangle. |
| point (Point) | Point. |
Returns: Distance between point and rectangle.
Gets the distance from this rectangle to a point. Any point in or on the rectangle has a distance of zero.
Parameters:
| rectangle (Rectangle) | Rectangle. |
| point (PointF) | Point. |
Returns: Distance between point and rectangle.
Gets the distance from this rectangle to a point. Any point in or on the rectangle has a distance of zero.
Parameters:
| rectangle (RectangleF) | Rectangle. |
| point (PointF) | Point. |
Returns: Distance between point and rectangle.
Gets the distance between two rectangles.
Parameters:
| rectangle (RectangleF) | Rectangle. |
| other (RectangleF) | Rectangle. |
Returns: 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.
Parameters:
| rectangle (RectangleF) |
Gets the edge of a rectangle.
Parameters:
| 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.
Parameters:
| rectangle (RectangleF) | Rectangle to round. |
Returns: Adjusted rectangle.
public static SizeF Floor(this SizeF size)
Round the width and height of a size to the nearest smaller integer.
Parameters:
| size (SizeF) | Size to round. |
Returns: Adjusted size.
Find the point on the rectangle that is furthest from some base point.
Parameters:
| rectangle (Rectangle) | Rectangle. |
| point (Point) | Point to search from. |
Returns: Point on rectangle furthest from base point.
public static PointF FurthestPoint(this RectangleF rectangle, PointF point)
Find the point on the rectangle that is furthest from some base point.
Parameters:
| rectangle (RectangleF) | Rectangle. |
| point (PointF) | Point to search from. |
Returns: Point on rectangle furthest from base point.
Grow a rectangle until it contains a given point.
Parameters:
| rectangle (Rectangle) | Rectangle to grow. |
| point (Point) | Point to include. |
Returns: Grown rectangle.
public static RectangleF Grow(this RectangleF rectangle, PointF point)
Grow a rectangle until it contains a given point.
Parameters:
| rectangle (RectangleF) | Rectangle to grow. |
| point (PointF) | Point to include. |
Returns: Grown rectangle.
Interpolate between two rectangles.
Parameters:
| rectangle (RectangleF) | Starting rectangle. |
| target (RectangleF) | Final rectangle. |
| motion (float) | Normalised interpolation factor. |
Test whether two boxes intersect within tolerance.
Parameters:
| 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.
Parameters:
| rectangle (RectangleF) |
public static Rectangle MakeIncreasing(this Rectangle rectangle)
Make sure the width and height of a rectangle are increasing.
Parameters:
| rectangle (Rectangle) |
public static RectangleF MakeIncreasing(this RectangleF rectangle)
Make sure the width and height of a rectangle are increasing.
Parameters:
| rectangle (RectangleF) |
Move a rectangle.
Move a rectangle.
public static Rectangle MoveInto(this Rectangle rectangle, Rectangle boundary)
Move this rectangle such that it is entirely within another one, whenever possible.
Parameters:
| rectangle (Rectangle) | Rectangle to move. |
| boundary (Rectangle) | Bounding rectangle. |
Offset a rectangle.
Parameters:
| rectangle (Rectangle3d) | Rectangle. |
| offset (double) | Offset distance. Positive values offset towards the outside. |
Gets the (unsigned) perimeter or circumference of a rectangle.
Parameters:
| rectangle (RectangleF) |
Gets the point at a rectangle parameter.
Gets the point at a rectangle parameter.
Gets the radius of the rectangle (distance from the centre to a corner).
Parameters:
| rectangle (Rectangle) | Rectangle to measure. |
Returns: Radius of rectangle.
Gets the radius of the rectangle (distance from the centre to a corner).
Parameters:
| rectangle (RectangleF) | Rectangle to measure. |
Returns: Radius of rectangle.
Create a rectangle from normalised coordinates.
public static RectangleF Right(this RectangleF rectangle)
Move a rectangle left so that the new left lines up with the old right.
Parameters:
| rectangle (RectangleF) |
Round the coordinates of a rectangle.
Parameters:
| rectangle (RectangleF) | Rectangle to modify. |
| decimals (int) | Number of decimals. |
Returns: Rectangle with coordinates rounded to a specific number of decimal places.
public static RectangleF Round(this RectangleF rectangle)
Round a rectangle to integer coordinates.
Parameters:
| rectangle (RectangleF) | Rectangle to modify. |
Returns: Rectangle with coordinates rounded to nearest integers.
Round the coordinates of a rectangle.
Parameters:
| size (SizeF) | Size to modify. |
| decimals (int) | Number of decimals. |
Returns: Size with rounded dimensions.
public static SizeF Round(this SizeF size)
Round a size to integer coordinates.
Parameters:
| size (SizeF) | Size to modify. |
Returns: Size with rounded dimensions.
Scale a rectangle around its centre by a specific factor.
Parameters:
| rectangle (RectangleF) | Rectangle to scale. |
| factor (float) | Scaling factor. |
Returns: Scaled rectangle.
public static void SplitHorizontal(this Rectangle rectangle, int x, out Rectangle left, out Rectangle right)
Split a rectangle into two.
Parameters:
| 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. |
public static void SplitHorizontal(this RectangleF rectangle, float x, out RectangleF left, out RectangleF right)
Split a rectangle into two.
Parameters:
| 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. |
public static void SplitVertical(this Rectangle rectangle, int y, out Rectangle above, out Rectangle below)
Split a rectangle into two.
Parameters:
| rectangle (Rectangle) | Rectangle to split. |
| y (int) | Y coordinate to split at. |
| above (out Rectangle) | Rectangle above split. |
| below (out Rectangle) | Rectangle below split. |
public static void SplitVertical(this RectangleF rectangle, float y, out RectangleF above, out RectangleF below)
Split a rectangle into two.
Parameters:
| rectangle (RectangleF) | Rectangle to split. |
| y (float) | Y coordinate to split at. |
| above (out RectangleF) | Rectangle above split. |
| below (out RectangleF) | Rectangle below split. |
Split a rectangle into three.
Create an array (row-by-row) of division rectangles.
public static Rectangle ToInnerRectangle(this Rectangle rectangle, Size ratio)
Create the largest possible rectangle inside another rectangle with a specific width/height ratio.
Parameters:
| rectangle (Rectangle) | Rectangle to fit into. |
| ratio (Size) | Ratio of fitted rectangle. |
Returns: Fitted rectangle.
public static RectangleF ToInnerRectangle(this RectangleF rectangle, SizeF ratio)
Create the largest possible rectangle inside another rectangle with a specific width/height ratio.
Parameters:
| rectangle (RectangleF) | Rectangle to fit into. |
| ratio (SizeF) | Ratio of fitted rectangle. |
Returns: Fitted rectangle.
public static Rectangle ToInnerSquare(this Rectangle rectangle)
Convert a rectangle to the biggest square that fits inside it.
Parameters:
| rectangle (Rectangle) | Rectangle to square. |
Returns: Biggest square that fits inside rectangle.
public static RectangleF ToInnerSquare(this RectangleF rectangle)
Convert a rectangle to the smallest square containing it.
Parameters:
| rectangle (RectangleF) | Rectangle to square. |
Returns: Biggest square that fits inside rectangle.
public static Rectangle ToOuterRectangle(this Rectangle rectangle, Size ratio)
Create the smallest possible rectangle outside another rectangle with a specific width/height ratio.
Parameters:
| rectangle (Rectangle) | Rectangle to wrap around. |
| ratio (Size) | Ratio of wrapped rectangle. |
Returns: Wrapped rectangle.
public static RectangleF ToOuterRectangle(this RectangleF rectangle, SizeF ratio)
Create the smallest possible rectangle outside another rectangle with a specific width/height ratio.
Parameters:
| rectangle (RectangleF) | Rectangle to wrap around. |
| ratio (SizeF) | Ratio of wrapped rectangle. |
Returns: Wrapped rectangle.
public static Rectangle ToOuterSquare(this Rectangle rectangle)
Convert a rectangle to the smallest square containing it.
Parameters:
| rectangle (Rectangle) | Rectangle to square. |
Returns: Smallest square containing rectangle.
public static RectangleF ToOuterSquare(this RectangleF rectangle)
Convert a rectangle to the smallest square containing it.
Parameters:
| rectangle (RectangleF) | Rectangle to square. |
Returns: Smallest square containing rectangle.
public static Rectangle ToRectangle(this RectangleF rectangle)
Convert a RectangleF into a Rectangle.
Parameters:
| rectangle (RectangleF) | Rectangle to convert. |
Returns: Rectangle.
Convert an Eto rectangle into a Rhino rectangle.
Parameters:
| rectangle (Rectangle) | Rectangle to convert. |
Returns: Rhino rectangle.
Convert an Eto rectangle into a Rhino rectangle.
Parameters:
| rectangle (RectangleF) | Rectangle to convert. |
Returns: Rhino rectangle.
Fillet the corners of a rectangle. The radius is automatically shrunk to avoid self-intersections.
Parameters:
| rectangle (Rectangle3d) | |
| radius (double) |
public static GraphicsPath ToRoundedEdge(this RectangleF rectangle, float radius, float thickness, RectangleEdge edge)
Create a graphicspath that describes slab edges within a rounded rectangle.
Parameters:
| rectangle (RectangleF) | Bounding rectangle. |
| radius (float) | Radius of edge. |
| thickness (float) | Thickness of edge. |
| edge (RectangleEdge) | Edges. |
Returns: Graphicspath describing the edges or null if no edges could be solved.
Create a graphics path that represents a rounded rectangle.
Parameters:
| rectangle (Rectangle) | Rectangle. |
| radii (CornerRadii) | Corner radii. |
Create a graphics path that represents a rounded rectangle.
Parameters:
| rectangle (Rectangle) | Rectangle. |
| radii (int) | Corner radii. |
Returns: Graphics path.
Create a graphics path that represents a rounded rectangle.
Parameters:
| rectangle (RectangleF) | Rectangle. |
| radii (CornerRadii) | Corner radii. |
Returns: Graphics path.
Create a graphics path that represents a rounded rectangle.
Parameters:
| rectangle (RectangleF) | Rectangle. |
| radii (float) | Corner radii. |
Returns: Graphics path.