From ecbf2c023d3aeb1cc6de87941ef6f8f176288cd3 Mon Sep 17 00:00:00 2001 From: Sergey Mashkov Date: Mon, 17 Oct 2016 16:12:17 +0300 Subject: [PATCH] Upgrade example --- .../testData/webDemoCanvasExamples/cases/Creatures.kt | 6 ++++-- .../testData/webDemoCanvasExamples/cases/Traffic light.kt | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/js/js.translator/testData/webDemoCanvasExamples/cases/Creatures.kt b/js/js.translator/testData/webDemoCanvasExamples/cases/Creatures.kt index c0cc8b3836b..5deb59fbcfb 100644 --- a/js/js.translator/testData/webDemoCanvasExamples/cases/Creatures.kt +++ b/js/js.translator/testData/webDemoCanvasExamples/cases/Creatures.kt @@ -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 { diff --git a/js/js.translator/testData/webDemoCanvasExamples/cases/Traffic light.kt b/js/js.translator/testData/webDemoCanvasExamples/cases/Traffic light.kt index 15bfac35bad..9997b6966e6 100644 --- a/js/js.translator/testData/webDemoCanvasExamples/cases/Traffic light.kt +++ b/js/js.translator/testData/webDemoCanvasExamples/cases/Traffic light.kt @@ -61,7 +61,8 @@ fun main(args: Array) { 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)