[orx-fcurve] Add support for single constant values
This commit is contained in:
@@ -477,6 +477,9 @@ private fun evaluateFCurveCommands(parts: List<String>): FCurve {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun fcurve(d: String): FCurve {
|
fun fcurve(d: String): FCurve {
|
||||||
|
val constantExpression = d.toDoubleOrNull()
|
||||||
|
if (constantExpression != null) {
|
||||||
|
return FCurve(listOf(Segment2D(Vector2(0.0, constantExpression), Vector2(0.0, constantExpression))))
|
||||||
|
}
|
||||||
return evaluateFCurveCommands(fCurveCommands(d))
|
return evaluateFCurveCommands(fCurveCommands(d))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,4 +38,31 @@ class TestEFCurve {
|
|||||||
val s = fc.sampler()
|
val s = fc.sampler()
|
||||||
assertEquals(0.0, s(6.0))
|
assertEquals(0.0, s(6.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testConstantValue() {
|
||||||
|
val text = "10.5"
|
||||||
|
val fc = fcurve(efcurve(text))
|
||||||
|
assertEquals(10.5, fc.value(0.0))
|
||||||
|
assertEquals(10.5, fc.value(1.0))
|
||||||
|
assertEquals(10.5, fc.value(-1.0))
|
||||||
|
|
||||||
|
val normalizedSampler = fc.sampler(true)
|
||||||
|
assertEquals(10.5, normalizedSampler(0.0))
|
||||||
|
assertEquals(10.5, normalizedSampler(1.0))
|
||||||
|
assertEquals(10.5, normalizedSampler(-1.0))
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
fun testConstantExpression() {
|
||||||
|
val text = "${21.0 / 2.0}"
|
||||||
|
val fc = fcurve(efcurve(text))
|
||||||
|
assertEquals(10.5, fc.value(0.0))
|
||||||
|
assertEquals(10.5, fc.value(1.0))
|
||||||
|
assertEquals(10.5, fc.value(-1.0))
|
||||||
|
|
||||||
|
val normalizedSampler = fc.sampler(true)
|
||||||
|
assertEquals(10.5, normalizedSampler(0.0))
|
||||||
|
assertEquals(10.5, normalizedSampler(1.0))
|
||||||
|
assertEquals(10.5, normalizedSampler(-1.0))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
19
orx-fcurve/src/commonTest/kotlin/TestFCurve.kt
Normal file
19
orx-fcurve/src/commonTest/kotlin/TestFCurve.kt
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import org.openrndr.extra.fcurve.fcurve
|
||||||
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
class TestFCurve {
|
||||||
|
@Test
|
||||||
|
fun testConstantExpression() {
|
||||||
|
val text = "10.5"
|
||||||
|
val fc = fcurve(text)
|
||||||
|
assertEquals(10.5, fc.value(0.0))
|
||||||
|
assertEquals(10.5, fc.value(1.0))
|
||||||
|
assertEquals(10.5, fc.value(-1.0))
|
||||||
|
|
||||||
|
val normalizedSampler = fc.sampler(true)
|
||||||
|
assertEquals(10.5, normalizedSampler(0.0))
|
||||||
|
assertEquals(10.5, normalizedSampler(1.0))
|
||||||
|
assertEquals(10.5, normalizedSampler(-1.0))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user