Skip to content

Commit 1250605

Browse files
committed
Added a new shape class instead of UI.
1 parent a8d9eb0 commit 1250605

2 files changed

Lines changed: 16 additions & 31 deletions

File tree

‎core-kotlin/src/main/kotlin/com/baeldung/operators/Point.kt‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,19 @@ operator fun Point.times(other: Point): Point = Point(x * other.x, y * other.y)
1111
operator fun Point.div(other: Point): Point = Point(x / other.x, y / other.y)
1212
operator fun Point.rem(other: Point): Point = Point(x % other.x, y % other.y)
1313
operator fun Point.times(factor: Int): Point = Point(x * factor, y * factor)
14-
operator fun Int.times(point: Point): Point = Point(point.x * this, point.y * this)
14+
operator fun Int.times(point: Point): Point = Point(point.x * this, point.y * this)
15+
16+
class Shape {
17+
private val points = mutableListOf<Point>()
18+
19+
operator fun Point.unaryPlus() {
20+
points.add(this)
21+
}
22+
}
23+
24+
fun shape(init: Shape.() -> Unit): Shape {
25+
val shape = Shape()
26+
shape.init()
27+
28+
return shape
29+
}

‎core-kotlin/src/main/kotlin/com/baeldung/operators/UI.kt‎

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)