Created
May 19, 2021 02:20
-
-
Save pencelab/f866df007bb5cd46e249436ef074429d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun panel(init: (@ShapeDsl Panel).() -> Unit): Panel { | |
return Panel().apply { init() } | |
} | |
inline fun Panel.square(init: SquareBuilder.() -> Unit): Square { | |
return SquareBuilder().apply { init() }.build().also { this.addShape(it) } | |
} | |
inline fun Panel.triangle(init: TriangleBuilder.() -> Unit): Triangle { | |
return TriangleBuilder().apply { init() }.build().also { this.addShape(it) } | |
} | |
inline fun Panel.rhombus(init: RhombusBuilder.() -> Unit): Rhombus { | |
return RhombusBuilder().apply { init() }.build().also { this.addShape(it) } | |
} | |
inline fun Panel.composed(init: Panel.() -> ComposedShape): ComposedShape { | |
return init().also { this.addShape(it) } | |
} | |
fun Panel.space() { | |
this.addShape(Space) | |
} | |
infix fun Shape.union(shape: Shape): ComposedShape { | |
return ComposedShape(this, shape, ComposedShape.Operation.UNION) | |
} | |
infix fun Shape.intersection(shape: Shape): ComposedShape { | |
return ComposedShape(this, shape, ComposedShape.Operation.INTERSECTION) | |
} | |
operator fun Shape.plus(shape: Shape): ComposedShape = this union shape | |
operator fun Shape.minus(shape: Shape): ComposedShape = this intersection shape | |
@DslMarker | |
@Target(AnnotationTarget.CLASS, AnnotationTarget.TYPE) | |
annotation class ShapeDsl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment