[orx-shapes] Implement RoundedRectangle using circular rounding
This commit is contained in:
@@ -8,8 +8,19 @@ import org.openrndr.shape.ShapeContour
|
|||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
class RoundedRectangle(val corner: Vector2, val width: Double, val height: Double, val radius: Double) {
|
class RoundedRectangle(val corner: Vector2, val width: Double, val height: Double, val radius: Double) {
|
||||||
constructor(x: Double, y: Double, width: Double, height: Double, radius: Double) : this(Vector2(x, y), width, height, radius)
|
constructor(x: Double, y: Double, width: Double, height: Double, radius: Double) : this(
|
||||||
constructor(rectangle: Rectangle, radius: Double) : this(rectangle.corner, rectangle.width, rectangle.height, radius)
|
Vector2(x, y),
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
radius
|
||||||
|
)
|
||||||
|
|
||||||
|
constructor(rectangle: Rectangle, radius: Double) : this(
|
||||||
|
rectangle.corner,
|
||||||
|
rectangle.width,
|
||||||
|
rectangle.height,
|
||||||
|
radius
|
||||||
|
)
|
||||||
|
|
||||||
/** the center of the rounded rectangle */
|
/** the center of the rounded rectangle */
|
||||||
val center: Vector2
|
val center: Vector2
|
||||||
@@ -27,16 +38,16 @@ class RoundedRectangle(val corner: Vector2, val width: Double, val height: Doubl
|
|||||||
moveTo(x + r, y)
|
moveTo(x + r, y)
|
||||||
lineTo(x + width - r, y)
|
lineTo(x + width - r, y)
|
||||||
|
|
||||||
curveTo(Vector2(x + width, y), Vector2(x + width, y + r))
|
arcTo(r, r, 90.0, false, true, Vector2(x + width, y + r))
|
||||||
lineTo(x + width, y + height - r)
|
lineTo(x + width, y + height - r)
|
||||||
|
|
||||||
curveTo(Vector2(x + width, y + height), Vector2(x + width - r, y + height))
|
arcTo(r, r, 90.0, false, true, Vector2(x + width - r, y + height))
|
||||||
lineTo(x + r, y + height)
|
lineTo(x + r, y + height)
|
||||||
|
|
||||||
curveTo(Vector2(x, y + height), Vector2(x, y + height - r))
|
arcTo(r, r, 90.0, false, true, Vector2(x, y + height - r))
|
||||||
lineTo(x, y + r)
|
lineTo(x, y + r)
|
||||||
|
|
||||||
curveTo(Vector2(x, y), Vector2(x + r, y))
|
arcTo(r, r, 90.0, false, true, Vector2(x + r, y))
|
||||||
close()
|
close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user