Rectangle

class Rectangle(val position: Point = Origin, val size: Size = Size.Empty) : ConvexPolygon

A rectangular ConvexPolygon with 4 sides at right-angles.

            x
(0,0) ──▶

y ▼
┌──────────────────────────┐
│ │
│ │
│ │
│ │ height
│ │
│ │
│ │
└──────────────────────────┘
width

Author

Nicholas Eddy

Constructors

Link copied to clipboard
constructor(width: Int, height: Int = width)

Creates a Rectangle at the Origin: [0, 0, width, height]

constructor(width: Float, height: Float = width)

Creates a Rectangle at the Origin: [0, 0, width, height]

constructor(width: Double, height: Double = width)

Creates a Rectangle at the Origin: [0, 0, width, height]

constructor(size: Size)

Creates a Rectangle at the Origin: [0, 0, size.width, size.height]

constructor(x: Int = 0, y: Int = 0, width: Int = 0, height: Int = 0)

Creates a Rectangle

constructor(x: Double = 0.0, y: Double = 0.0, width: Double = 0.0, height: Double = 0.0)

Creates a Rectangle

constructor(x: Float = 0.0f, y: Float = 0.0f, width: Float = 0.0f, height: Float = 0.0f)

Creates a Rectangle

constructor(position: Point = Origin, size: Size = Size.Empty)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val area: Double
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 override val empty: Boolean
Link copied to clipboard

Vertical extent

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

Points representing the vertices

Link copied to clipboard

The top-left corner (x,y)

Link copied to clipboard

Right edge

Link copied to clipboard
val size: Size

The width-height

Link copied to clipboard

Horizontal extent

Link copied to clipboard
val x: Double

Left edge

Link copied to clipboard
val y: Double

Top edge

Functions

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

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

fun 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
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
infix fun 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 inset(inset: Double): Rectangle

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

Link copied to clipboard
infix fun 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
open override fun toString(): String
Link copied to clipboard
infix fun union(rectangle: Rectangle): Rectangle

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

Inherited functions

Link copied to clipboard

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

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
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
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

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

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.