Replace the custom mod function with Kotlin's built-in mod extension.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -83,7 +83,7 @@ class CatmullRomChain1(points: List<Double>, 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<Vector2>, 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<Vector3>, 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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user