From c8b5d734d2931eed65e5b1a76733d7f58554cb33 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Fri, 12 Nov 2021 16:38:19 -0800 Subject: [PATCH] Fix inc/dec to follow language conventions --- README.md | 2 +- gradle.properties | 2 +- .../dev/romainguy/kotlin/math/Matrix.kt | 42 +++-------------- .../dev/romainguy/kotlin/math/Vector.kt | 45 +++---------------- 4 files changed, 14 insertions(+), 77 deletions(-) diff --git a/README.md b/README.md index a18c531..9b0470a 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ repositories { } dependencies { - implementation 'dev.romainguy:kotlin-math:1.0.0' + implementation 'dev.romainguy:kotlin-math:1.0.1' } ``` diff --git a/gradle.properties b/gradle.properties index cc2dffb..37ea2c9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ GROUP=dev.romainguy -VERSION_NAME=1.0.0 +VERSION_NAME=1.0.1 POM_DESCRIPTION=Graphics oriented math library for Kotlin diff --git a/src/main/kotlin/dev/romainguy/kotlin/math/Matrix.kt b/src/main/kotlin/dev/romainguy/kotlin/math/Matrix.kt index 699cad7..d669fc7 100644 --- a/src/main/kotlin/dev/romainguy/kotlin/math/Matrix.kt +++ b/src/main/kotlin/dev/romainguy/kotlin/math/Matrix.kt @@ -66,16 +66,8 @@ data class Mat2( } operator fun unaryMinus() = Mat2(-x, -y) - operator fun inc(): Mat2 { - x++ - y++ - return this - } - operator fun dec(): Mat2 { - x-- - y-- - return this - } + operator fun inc() = Mat2(x++, y++) + operator fun dec() = Mat2(x--, y--) operator fun plus(v: Float) = Mat2(x + v, y + v) operator fun minus(v: Float) = Mat2(x - v, y - v) @@ -159,18 +151,8 @@ data class Mat3( } operator fun unaryMinus() = Mat3(-x, -y, -z) - operator fun inc(): Mat3 { - x++ - y++ - z++ - return this - } - operator fun dec(): Mat3 { - x-- - y-- - z-- - return this - } + operator fun inc() = Mat3(x++, y++, z++) + operator fun dec() = Mat3(x--, y--, z--) operator fun plus(v: Float) = Mat3(x + v, y + v, z + v) operator fun minus(v: Float) = Mat3(x - v, y - v, z - v) @@ -309,20 +291,8 @@ data class Mat4( } operator fun unaryMinus() = Mat4(-x, -y, -z, -w) - operator fun inc(): Mat4 { - x++ - y++ - z++ - w++ - return this - } - operator fun dec(): Mat4 { - x-- - y-- - z-- - w-- - return this - } + operator fun inc() = Mat4(x++, y++, z++, w++) + operator fun dec() = Mat4(x--, y--, z--, w--) operator fun plus(v: Float) = Mat4(x + v, y + v, z + v, w + v) operator fun minus(v: Float) = Mat4(x - v, y - v, z - v, w - v) diff --git a/src/main/kotlin/dev/romainguy/kotlin/math/Vector.kt b/src/main/kotlin/dev/romainguy/kotlin/math/Vector.kt index f20a210..ceb8d13 100644 --- a/src/main/kotlin/dev/romainguy/kotlin/math/Vector.kt +++ b/src/main/kotlin/dev/romainguy/kotlin/math/Vector.kt @@ -117,17 +117,8 @@ data class Float2(var x: Float = 0.0f, var y: Float = 0.0f) { } operator fun unaryMinus() = Float2(-x, -y) - operator fun inc(): Float2 { - x += 1.0f - y += 1.0f - return this - } - - operator fun dec(): Float2 { - x -= 1.0f - y -= 1.0f - return this - } + operator fun inc() = Float2(x++, y++) + operator fun dec() = Float2(x--, y--) inline operator fun plus(v: Float) = Float2(x + v, y + v) inline operator fun minus(v: Float) = Float2(x - v, y - v) @@ -291,19 +282,8 @@ data class Float3(var x: Float = 0.0f, var y: Float = 0.0f, var z: Float = 0.0f) } operator fun unaryMinus() = Float3(-x, -y, -z) - operator fun inc(): Float3 { - x += 1.0f - y += 1.0f - z += 1.0f - return this - } - - operator fun dec(): Float3 { - x -= 1.0f - y -= 1.0f - z -= 1.0f - return this - } + operator fun inc() = Float3(x++, y++, z++) + operator fun dec() = Float3(x--, y--, z--) inline operator fun plus(v: Float) = Float3(x + v, y + v, z + v) inline operator fun minus(v: Float) = Float3(x - v, y - v, z - v) @@ -543,21 +523,8 @@ data class Float4( } operator fun unaryMinus() = Float4(-x, -y, -z, -w) - operator fun inc(): Float4 { - x += 1.0f - y += 1.0f - z += 1.0f - w += 1.0f - return this - } - - operator fun dec(): Float4 { - x -= 1.0f - y -= 1.0f - z -= 1.0f - w -= 1.0f - return this - } + operator fun inc() = Float4(x++, y++, z++, w++) + operator fun dec() = Float4(x--, y--, z--, w--) inline operator fun plus(v: Float) = Float4(x + v, y + v, z + v, w + v) inline operator fun minus(v: Float) = Float4(x - v, y - v, z - v, w - v)