Skip to content

Commit

Permalink
Merge pull request #3 from dwursteisen/fix-rotation
Browse files Browse the repository at this point in the history
Update lint
  • Loading branch information
dwursteisen authored Mar 14, 2021
2 parents e2012c8 + d2c6069 commit 5f41d52
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 61 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ jobs:
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: build
run: ./gradlew ktlintCheck build

Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jobs:
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Publish artifact
run: ./gradlew publishAllPublicationsToSonatypeStagingRepository -Pversion="${{github.event.release.tag_name}}" -Psigning.base64.secretKey="${{secrets.SIGNING_BASE_64_SECRET_KEY}}" -Psigning.password="${{secrets.SIGNING_PASSWORD}}" -Psonatype.username="${{secrets.SONATYPE_USERNAME}}" -Psonatype.password="${{secrets.SONATYPE_PASSWORD}}"
26 changes: 15 additions & 11 deletions src/commonMain/kotlin/com/curiouscreature/kotlin/math/Matrix.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,17 @@ data class Mat2(
}

fun toFloatArray() = floatArrayOf(
x.x, y.x,
x.y, y.y
x.x,
y.x,
x.y,
y.y
)

override fun toString(): String {
return """
|${x.x} ${y.x}|
|${x.y} ${y.y}|
""".trimIndent()
""".trimIndent()
}
}

Expand Down Expand Up @@ -209,7 +211,7 @@ data class Mat3(
|${x.x} ${y.x} ${z.x}|
|${x.y} ${y.y} ${z.y}|
|${x.z} ${y.z} ${z.z}|
""".trimIndent()
""".trimIndent()
}
}

Expand Down Expand Up @@ -282,12 +284,14 @@ data class Mat4(
0f,
1f
)
return transpose(Mat4(
x = mx,
y = my,
z = mz,
w = mw
))
return transpose(
Mat4(
x = mx,
y = my,
z = mz,
w = mw
)
)
}
}

Expand Down Expand Up @@ -421,7 +425,7 @@ data class Mat4(
[${x.y}|${y.y}|${z.y}|${w.y}]
[${x.z}|${y.z}|${z.z}|${w.z}]
[${x.w}|${y.w}|${z.w}|${w.w}]
""".trimIndent()
""".trimIndent()
}
}

Expand Down
36 changes: 24 additions & 12 deletions src/commonMain/kotlin/com/curiouscreature/kotlin/math/Vector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -636,25 +636,29 @@ fun refract(i: Float2, n: Float2, eta: Float): Float2 {
inline fun clamp(v: Float2, min: Float, max: Float): Float2 {
return Float2(
clamp(v.x, min, max),
clamp(v.y, min, max))
clamp(v.y, min, max)
)
}

inline fun clamp(v: Float2, min: Float2, max: Float2): Float2 {
return Float2(
clamp(v.x, min.x, max.x),
clamp(v.y, min.y, max.y))
clamp(v.y, min.y, max.y)
)
}

inline fun mix(a: Float2, b: Float2, x: Float): Float2 {
return Float2(
mix(a.x, b.x, x),
mix(a.y, b.y, x))
mix(a.y, b.y, x)
)
}

inline fun mix(a: Float2, b: Float2, x: Float2): Float2 {
return Float2(
mix(a.x, b.x, x.x),
mix(a.y, b.y, x.y))
mix(a.y, b.y, x.y)
)
}

inline fun min(v: Float2) = min(v.x, v.y)
Expand Down Expand Up @@ -727,28 +731,32 @@ inline fun clamp(v: Float3, min: Float, max: Float): Float3 {
return Float3(
clamp(v.x, min, max),
clamp(v.y, min, max),
clamp(v.z, min, max))
clamp(v.z, min, max)
)
}

inline fun clamp(v: Float3, min: Float3, max: Float3): Float3 {
return Float3(
clamp(v.x, min.x, max.x),
clamp(v.y, min.y, max.y),
clamp(v.z, min.z, max.z))
clamp(v.z, min.z, max.z)
)
}

inline fun mix(a: Float3, b: Float3, x: Float): Float3 {
return Float3(
mix(a.x, b.x, x),
mix(a.y, b.y, x),
mix(a.z, b.z, x))
mix(a.z, b.z, x)
)
}

inline fun mix(a: Float3, b: Float3, x: Float3): Float3 {
return Float3(
mix(a.x, b.x, x.x),
mix(a.y, b.y, x.y),
mix(a.z, b.z, x.z))
mix(a.z, b.z, x.z)
)
}

inline fun min(v: Float3) = min(v.x, min(v.y, v.z))
Expand Down Expand Up @@ -807,31 +815,35 @@ inline fun clamp(v: Float4, min: Float, max: Float): Float4 {
clamp(v.x, min, max),
clamp(v.y, min, max),
clamp(v.z, min, max),
clamp(v.w, min, max))
clamp(v.w, min, max)
)
}

inline fun clamp(v: Float4, min: Float4, max: Float4): Float4 {
return Float4(
clamp(v.x, min.x, max.x),
clamp(v.y, min.y, max.y),
clamp(v.z, min.z, max.z),
clamp(v.w, min.z, max.w))
clamp(v.w, min.z, max.w)
)
}

inline fun mix(a: Float4, b: Float4, x: Float): Float4 {
return Float4(
mix(a.x, b.x, x),
mix(a.y, b.y, x),
mix(a.z, b.z, x),
mix(a.w, b.w, x))
mix(a.w, b.w, x)
)
}

inline fun mix(a: Float4, b: Float4, x: Float4): Float4 {
return Float4(
mix(a.x, b.x, x.x),
mix(a.y, b.y, x.y),
mix(a.z, b.z, x.z),
mix(a.w, b.w, x.w))
mix(a.w, b.w, x.w)
)
}

inline fun min(v: Float4) = min(v.x, min(v.y, min(v.z, v.w)))
Expand Down
32 changes: 19 additions & 13 deletions src/commonTest/kotlin/com/curiouscreature/kotlin/math/MatrixTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ class MatrixTest {
Float3(-2f, 1f, 1f),
Float3(2f, -2f, 0f)
),
inverse(Mat3(
Float3(1f, 0f, 0.5f),
Float3(1f, 0f, 0f),
Float3(1f, 1f, 1f)
))
inverse(
Mat3(
Float3(1f, 0f, 0.5f),
Float3(1f, 0f, 0f),
Float3(1f, 1f, 1f)
)
)
)
}

Expand All @@ -123,12 +125,14 @@ class MatrixTest {
Float4(0f, 0f, 6f, 0f),
Float4(0f, 0f, 0f, 1f)
),
scale(Mat4(
Float4(2f, 0f, 0f, 0f),
Float4(4f, 0f, 0f, 0f),
Float4(6f, 0f, 0f, 0f),
Float4(0f, 0f, 0f, 0f)
))
scale(
Mat4(
Float4(2f, 0f, 0f, 0f),
Float4(4f, 0f, 0f, 0f),
Float4(6f, 0f, 0f, 0f),
Float4(0f, 0f, 0f, 0f)
)
)
)
}

Expand Down Expand Up @@ -179,7 +183,8 @@ class MatrixTest {
Float4(1f, 1f, 0f, 0f),
Float4(0f, 0f, 1f, 2f),
Float4(0f, -2f, 0f, 1f)
))
)
)
)
}

Expand All @@ -200,7 +205,8 @@ class MatrixTest {
Float4(1f, 1f, 0f, 0f),
Float4(0f, 0f, 1f, 2f),
Float4(0f, 0f, 0f, 1f)
)).toString()
)
).toString()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ class LibGDXMatrixTest {

@Test
fun transpose() {
assertEquals(Matrix4(
floatArrayOf(
1f, 2f, 3f, 4f,
5f, 6f, 7f, 8f,
9f, 10f, 11f, 12f,
13f, 14f, 15f, 16f
)
).tra(), transpose(Mat4.fromColumnMajor(1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f, 11f, 12f, 13f, 14f, 15f, 16f)))
assertEquals(
Matrix4(
floatArrayOf(
1f, 2f, 3f, 4f,
5f, 6f, 7f, 8f,
9f, 10f, 11f, 12f,
13f, 14f, 15f, 16f
)
).tra(),
transpose(Mat4.fromColumnMajor(1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f, 11f, 12f, 13f, 14f, 15f, 16f))
)
}

@Test
Expand Down Expand Up @@ -81,25 +84,34 @@ class LibGDXMatrixTest {

@Test
fun multiplication() {
val expected = Matrix4(floatArrayOf(
1f, 2f, 3f, 4f,
5f, 6f, 7f, 8f,
9f, 10f, 11f, 12f,
13f, 14f, 15f, 16f)).mul(Matrix4(floatArrayOf(
1f, 2f, 3f, 4f,
5f, 6f, 7f, 8f,
9f, 10f, 11f, 12f,
13f, 14f, 15f, 16f
)))
val expected = Matrix4(
floatArrayOf(
1f, 2f, 3f, 4f,
5f, 6f, 7f, 8f,
9f, 10f, 11f, 12f,
13f, 14f, 15f, 16f
)
).mul(
Matrix4(
floatArrayOf(
1f, 2f, 3f, 4f,
5f, 6f, 7f, 8f,
9f, 10f, 11f, 12f,
13f, 14f, 15f, 16f
)
)
)
val result = Mat4.fromColumnMajor(
1f, 2f, 3f, 4f,
5f, 6f, 7f, 8f,
9f, 10f, 11f, 12f,
13f, 14f, 15f, 16f) * Mat4.fromColumnMajor(
13f, 14f, 15f, 16f
) * Mat4.fromColumnMajor(
1f, 2f, 3f, 4f,
5f, 6f, 7f, 8f,
9f, 10f, 11f, 12f,
13f, 14f, 15f, 16f)
13f, 14f, 15f, 16f
)
assertEquals(expected, result)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ class LibGDXProjectionsTest {
@Test
fun orhotgraphic() {
val libgdx = Matrix4().setToOrtho(
10f, 20f,
30f, 40f,
0f, 10f
10f,
20f,
30f,
40f,
0f,
10f
)

val mat = ortho(10f, 20f, 30f, 40f, 0f, 10f)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.curiouscreature.kotlin.math

import com.badlogic.gdx.math.Matrix4
import com.badlogic.gdx.math.Quaternion as Quat
import com.badlogic.gdx.math.Vector3
import com.badlogic.gdx.utils.GdxNativesLoader
import kotlin.test.Test
import com.badlogic.gdx.math.Quaternion as Quat

class LibGDXQuaternionTest {
init {
Expand Down

0 comments on commit 5f41d52

Please sign in to comment.