Upgrade example

This commit is contained in:
Sergey Mashkov
2016-10-17 16:12:17 +03:00
parent 3285728391
commit ecbf2c023d
2 changed files with 8 additions and 4 deletions
@@ -306,12 +306,14 @@ class RadialGradientGenerator(val context: CanvasRenderingContext2D) {
}
}
fun v(x: Double, y: Double) = Vector(x, y)
fun v(x: Int, y: Int) = Vector(x, y)
fun v(x: Double, y: Double) = Vector(x.toInt(), y.toInt())
class Vector(val x: Double = 0.0, val y: Double = 0.0) {
class Vector(val x: Int = 0.0, val y: Int = 0.0) {
operator fun plus(v: Vector) = v(x + v.x, y + v.y)
operator fun unaryMinus() = v(-x, -y)
operator fun minus(v: Vector) = v(x - v.x, y - v.y)
operator fun times(koef: Int) = v(x * koef, y * koef)
operator fun times(koef: Double) = v(x * koef, y * koef)
infix fun distanceTo(v: Vector) = Math.sqrt((this - v).sqr)
fun rotatedBy(theta: Double): Vector {
@@ -61,7 +61,8 @@ fun main(args: Array<String>) {
state.addShape(Button(PATH_TO_IMAGES + "ud.png", v(455.0, 120.0), v(50.0, 120.0)))
}
fun v(x: Double, y: Double) = Vector(x, y)
fun v(x: Double, y: Double) = Vector(x.toInt(), y.toInt())
fun v(x: Int, y: Int) = Vector(x, y)
class Image(val src: String, override var pos: Vector, var imageSize: Vector) : Shape() {
override fun draw() {
@@ -481,7 +482,8 @@ abstract class Shape() {
}
class Vector(val x: Double = 0.0, val y: Double = 0.0) {
class Vector(val x: Int = 0, val y: Int = 0) {
constructor(x: Double, y: Double) : this(x.toInt(), y.toInt())
operator fun plus(v: Vector) = v(x + v.x, y + v.y)
operator fun unaryMinus() = v(-x, -y)
operator fun minus(v: Vector) = v(x - v.x, y - v.y)