From 426e35ebd0daaeee7221c61c783ef3d0b5f2e471 Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Sat, 1 Feb 2025 13:53:29 +0100 Subject: [PATCH] Replace the custom `mod` function with Kotlin's built-in `mod` extension. --- .../src/commonMain/kotlin/Expressions.kt | 2 +- orx-mesh-generators/src/commonMain/kotlin/MeshGenerators.kt | 4 ++-- orx-shapes/src/commonMain/kotlin/splines/CatmullRom.kt | 6 +++--- orx-time-operators/src/main/kotlin/LFO.kt | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/orx-expression-evaluator/src/commonMain/kotlin/Expressions.kt b/orx-expression-evaluator/src/commonMain/kotlin/Expressions.kt index e5229009..6a3f6b61 100644 --- a/orx-expression-evaluator/src/commonMain/kotlin/Expressions.kt +++ b/orx-expression-evaluator/src/commonMain/kotlin/Expressions.kt @@ -91,7 +91,7 @@ internal class ExpressionListener( KeyLangParser.Tokens.MINUS -> left - right KeyLangParser.Tokens.ASTERISK -> left * right KeyLangParser.Tokens.DIVISION -> left / right - KeyLangParser.Tokens.PERCENTAGE -> mod(left, right) + KeyLangParser.Tokens.PERCENTAGE -> left.mod(right) else -> error("operator '$operator' not implemented") } doubleStack.push(result) diff --git a/orx-mesh-generators/src/commonMain/kotlin/MeshGenerators.kt b/orx-mesh-generators/src/commonMain/kotlin/MeshGenerators.kt index b01adf5a..c6c7c715 100644 --- a/orx-mesh-generators/src/commonMain/kotlin/MeshGenerators.kt +++ b/orx-mesh-generators/src/commonMain/kotlin/MeshGenerators.kt @@ -137,8 +137,8 @@ fun extrudeShape( val points = it val normals = (points.indices).map { index -> - val a = mod(index + 1, points.size) - val b = mod(index - 1, points.size) + val a = (index + 1).mod(points.size) + val b = (index - 1).mod(points.size) (points[a] - points[b]).safeNormalized * -flip } val forward = Vector3(0.0, 0.0, depth) diff --git a/orx-shapes/src/commonMain/kotlin/splines/CatmullRom.kt b/orx-shapes/src/commonMain/kotlin/splines/CatmullRom.kt index 82923bc7..dc73177e 100644 --- a/orx-shapes/src/commonMain/kotlin/splines/CatmullRom.kt +++ b/orx-shapes/src/commonMain/kotlin/splines/CatmullRom.kt @@ -83,7 +83,7 @@ class CatmullRomChain1(points: List, alpha: Double = 0.5, val loop: Bool } fun position(rt: Double): Double { - val st = if (loop) mod(rt, 1.0) else rt.coerceIn(0.0, 1.0) + val st = if (loop) rt.mod(1.0) else rt.coerceIn(0.0, 1.0) val segmentIndex = (kotlin.math.min(almostOne, st) * segments.size).toInt() val t = (kotlin.math.min(almostOne, st) * segments.size) - segmentIndex return segments[segmentIndex].position(t) @@ -178,7 +178,7 @@ class CatmullRomChain2(points: List, alpha: Double = 0.5, val loop: Boo } fun position(rt: Double): Vector2 { - val st = if (loop) mod(rt, 1.0) else rt.coerceIn(0.0, 1.0) + val st = if (loop) rt.mod(1.0) else rt.coerceIn(0.0, 1.0) val segmentIndex = (kotlin.math.min(almostOne, st) * segments.size).toInt() val t = (kotlin.math.min(almostOne, st) * segments.size) - segmentIndex return segments[segmentIndex].position(t) @@ -273,7 +273,7 @@ class CatmullRomChain3(points: List, alpha: Double = 0.5, val loop: Boo } fun position(rt: Double): Vector3 { - val st = if (loop) mod(rt, 1.0) else rt.coerceIn(0.0, 1.0) + val st = if (loop) rt.mod(1.0) else rt.coerceIn(0.0, 1.0) val segmentIndex = (kotlin.math.min(almostOne, st) * segments.size).toInt() val t = (kotlin.math.min(almostOne, st) * segments.size) - segmentIndex return segments[segmentIndex].position(t) diff --git a/orx-time-operators/src/main/kotlin/LFO.kt b/orx-time-operators/src/main/kotlin/LFO.kt index edbbf559..126e3201 100644 --- a/orx-time-operators/src/main/kotlin/LFO.kt +++ b/orx-time-operators/src/main/kotlin/LFO.kt @@ -33,7 +33,7 @@ class LFO(wave: LFOWave = LFOWave.Saw) : TimeTools { } fun sample(frequency: Double = 1.0, phase: Double = 0.0): Double { - return when(wave) { + return when (wave) { LFOWave.Saw -> saw(frequency, phase) LFOWave.Sine -> sine(frequency, phase) LFOWave.Square -> square(frequency, phase) @@ -43,7 +43,7 @@ class LFO(wave: LFOWave = LFOWave.Saw) : TimeTools { fun saw(frequency: Double = 1.0, phase: Double = 0.0): Double { val cycleFreq = 1.0 / frequency - val cycleTime = mod(time + (phase * frequency), cycleFreq) + val cycleTime = (time + (phase * frequency)).mod(cycleFreq) current = (cycleTime) / cycleFreq return current } @@ -60,7 +60,7 @@ class LFO(wave: LFOWave = LFOWave.Saw) : TimeTools { fun triangle(frequency: Double = 1.0, phase: Double = 0.0): Double { val t = (time * frequency) + (phase * frequency) - current = 1.0 - 2.0 * abs(mod(t, 1.0) - 0.5) + current = 1.0 - 2.0 * abs(t.mod(1.0) - 0.5) return current } } \ No newline at end of file