diff --git a/orx-fcurve/src/commonMain/kotlin/FCurve.kt b/orx-fcurve/src/commonMain/kotlin/FCurve.kt index 58cffaa6..c67d9801 100644 --- a/orx-fcurve/src/commonMain/kotlin/FCurve.kt +++ b/orx-fcurve/src/commonMain/kotlin/FCurve.kt @@ -477,6 +477,9 @@ private fun evaluateFCurveCommands(parts: List): 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)) } - diff --git a/orx-fcurve/src/commonTest/kotlin/TestEFCurve.kt b/orx-fcurve/src/commonTest/kotlin/TestEFCurve.kt index d318bee6..de5bfced 100644 --- a/orx-fcurve/src/commonTest/kotlin/TestEFCurve.kt +++ b/orx-fcurve/src/commonTest/kotlin/TestEFCurve.kt @@ -38,4 +38,31 @@ class TestEFCurve { val s = fc.sampler() 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)) + } } \ No newline at end of file diff --git a/orx-fcurve/src/commonTest/kotlin/TestFCurve.kt b/orx-fcurve/src/commonTest/kotlin/TestFCurve.kt new file mode 100644 index 00000000..291e24fe --- /dev/null +++ b/orx-fcurve/src/commonTest/kotlin/TestFCurve.kt @@ -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)) + } +} \ No newline at end of file