41 lines
861 B
Kotlin
41 lines
861 B
Kotlin
|
package net.shadowfacts.cacao.geometry
|
||
|
|
||
|
/**
|
||
|
* Helper class for defining rectangles. Provides helper values for calculating perpendicular components of a rectangle based on X/Y/W/H.
|
||
|
*
|
||
|
* @author shadowfacts
|
||
|
*/
|
||
|
data class Rect(val left: Double, val top: Double, val width: Double, val height: Double) {
|
||
|
|
||
|
constructor(origin: Point, size: Size): this(origin.x, origin.y, size.width, size.height)
|
||
|
|
||
|
val right: Double by lazy {
|
||
|
left + width
|
||
|
}
|
||
|
val bottom: Double by lazy {
|
||
|
top + height
|
||
|
}
|
||
|
|
||
|
val midX: Double by lazy {
|
||
|
left + width / 2
|
||
|
}
|
||
|
val midY: Double by lazy {
|
||
|
top + height / 2
|
||
|
}
|
||
|
|
||
|
val origin: Point by lazy {
|
||
|
Point(left, top)
|
||
|
}
|
||
|
val center: Point by lazy {
|
||
|
Point(midX, midY)
|
||
|
}
|
||
|
|
||
|
val size: Size by lazy {
|
||
|
Size(width, height)
|
||
|
}
|
||
|
|
||
|
operator fun contains(point: Point): Boolean {
|
||
|
return point.x in left..right && point.y in top..bottom
|
||
|
}
|
||
|
|
||
|
}
|