Skip to content

Instantly share code, notes, and snippets.

@pencelab
Created May 19, 2021 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pencelab/f866df007bb5cd46e249436ef074429d to your computer and use it in GitHub Desktop.
Save pencelab/f866df007bb5cd46e249436ef074429d to your computer and use it in GitHub Desktop.
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