Rectangle

A rectangular ConvexPolygon with 4 sides at right-angles.

            x
(0,0) ──▶
│
y ▼
┌──────────────────────────┐
│ │
│ │
│ │
│ │ height
│ │
│ │
│ │
└──────────────────────────┘
width

Author

Nicholas Eddy

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val area: Double
Link copied to clipboard
Link copied to clipboard

Rectangle with the same width/height but positioned at 0,0

Link copied to clipboard

Bottom edge

Link copied to clipboard
open override val boundingRectangle: Rectangle

Gives the smallest Rectangle that fully contains this Polygon.

Link copied to clipboard

Point at the center of the rectangle

Link copied to clipboard
open val centroid: Point
Link copied to clipboard
Link copied to clipboard
open override val empty: Boolean
Link copied to clipboard

The vertical length

Link copied to clipboard
open override val points: List<Point>

Points representing the vertices

Link copied to clipboard

Top-left corner (x,y)

Link copied to clipboard

Right edge

Link copied to clipboard
Link copied to clipboard
val size: Size

width-height

Link copied to clipboard

The horizontal length

Link copied to clipboard
val x: Double

The left edge

Link copied to clipboard
val y: Double

The top edge

Functions

Link copied to clipboard
infix fun Rectangle.at(position: Point): Rectangle

Returns a rectangle with the same width/height but positioned at the given point

fun Rectangle.at(x: Double = this.x, y: Double = this.y): Rectangle

Returns a rectangle with the same width/height but positioned at the given x,y

Link copied to clipboard

Returns a new Rectangle with the same size as this, but with its center moved to at.

Returns a new Rectangle with the same size as this, but with its center moved to x, y.

Link copied to clipboard
open operator override fun contains(point: Point): Boolean

Checks whether the given point is within the boundaries of this Rectangle

open operator override fun contains(rectangle: Rectangle): Boolean
Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard

Creates a Circle that is inscribed within the rectangle

Link copied to clipboard

Creates an Ellipse that is inscribed within the rectangle

Link copied to clipboard
infix fun Rectangle.inset(inset: Insets): Rectangle

Rectangle that has been adjusted as follows [x + left, y + top, w - (left + right), h - (top + bottom)], where the adjustments are from the inset

infix fun Rectangle.inset(inset: Double): Rectangle

Rectangle that has been adjusted as follows [x + i, y + i, w - 2i, h - 2i], where i is the inset

fun Rectangle.inset(top: Double = 0.0, left: Double = 0.0, right: Double = 0.0, bottom: Double = 0.0): Rectangle

Rectangle that has been adjusted as follows [x + left, y + top, w - (left + right), h - (top + bottom)].

Link copied to clipboard
infix fun Rectangle.intersect(rectangle: Rectangle): Rectangle

Returns a Rectangle that is the intersection of this and the given one. The result is Empty if there is no intersection.

Link copied to clipboard
open infix override fun intersects(rectangle: Rectangle): Boolean

Checks whether the given rectangle intersects this one

Link copied to clipboard
fun ConvexPolygon.map(transform: (Point) -> Point): ConvexPolygon

Create a new ConvexPolygon with each point transformed by transform.

Link copied to clipboard

Create a new ConvexPolygon with the same points, but in reversed order.

Link copied to clipboard
fun Polygon.rounded(config: (index: Int, Point) -> Double): Path
fun Polygon.rounded(radius: Double, filter: (index: Int, Point) -> Boolean = { _,_ -> true }): Path

Creates a rounded shape from a Polygon. The resulting shape is essentially a polygon with the vertices rounded using a semicircular curve.

Link copied to clipboard
fun Rectangle.smooth(curvature: Float): Path

Creates a smooth Path resembling a superellipse based on this Rectangle.

Link copied to clipboard

Converts a Polygon to a Path.

fun Rectangle.toPath(radius: Double): Path

Converts Rectangle with radius to Path.

fun Rectangle.toPath(topLeftRadius: Double = 0.0, topRightRadius: Double = 0.0, bottomRightRadius: Double = 0.0, bottomLeftRadius: Double = 0.0): Path

Converts Rectangle with radii to Path.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
infix fun Rectangle.union(rectangle: Rectangle): Rectangle

Returns a Rectangle that is the union of this and the given one.

Link copied to clipboard

Returns a new Rectangle with the specified size, and all the other dimensions from this one.

fun Rectangle.with(width: Double = this.width, height: Double = this.height): Rectangle

Returns a new Rectangle with the specified width, height, and all the other dimensions from this one.