From feb8d8641e85efb9ddf4f27eeabdd806c4ea0728 Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Sat, 30 Mar 2024 16:26:23 +0100 Subject: [PATCH] [orx-fcurve] Replace _expr_ with {expr} --- orx-fcurve/README.md | 10 +++++----- orx-fcurve/src/commonMain/kotlin/EFCurve.kt | 2 +- orx-fcurve/src/commonTest/kotlin/TestEFCurve.kt | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/orx-fcurve/README.md b/orx-fcurve/README.md index d3b1e103..35e695be 100644 --- a/orx-fcurve/README.md +++ b/orx-fcurve/README.md @@ -152,7 +152,7 @@ In this example we used `% 9.0` to loop the time between 0.0 and 9.0, repeating # EFCurves -Extended Fcurves have a additional preprocessing step in which scalar expressions are evaluated. +Extended Fcurves have an additional preprocessing step in which scalar expressions are evaluated. ## Comments @@ -170,10 +170,10 @@ L5,5 ## Expressions -Expressions wrapped in underscore characters (`_`) are evaluated using `orx-expression-evaluator`. +Expressions within curly brackets are evaluated using `orx-expression-evaluator`. Please refer to its [documentation](https://github.com/openrndr/orx/tree/master/orx-expression-evaluator) for details on the expression language used. -For example: `M0 L_3 * 4_,4` evaluates to `M0 L12,4`. +For example: `M0 L{3 * 4},4` evaluates to `M0 L12,4`. ## Repetitions @@ -193,9 +193,9 @@ For example `|M0 |h1 m1|[3]|[2]` expands to `M0 h1 m1 h1 m1 h1 m1 M0 h1 m1 h1 m1 ### Interaction between repetitions and expressions -`M0 |H_it + 1_ m1][3]` expands to `M0 H1 m1 H2 m1 H3 m1` +`M0 |H{it + 1} m1][3]` expands to `M0 H1 m1 H2 m1 H3 m1` -`M0 |H_index + 1_ m_it_]{1.2, 1.3, 1.4}` expands to `M0 H1 m1.2 H2 m1.3 H3 m1.4` +`M0 |H{index + 1} m{it}]{1.2, 1.3, 1.4}` expands to `M0 H1 m1.2 H2 m1.3 H3 m1.4` # References diff --git a/orx-fcurve/src/commonMain/kotlin/EFCurve.kt b/orx-fcurve/src/commonMain/kotlin/EFCurve.kt index 5a4f25b6..20fed533 100644 --- a/orx-fcurve/src/commonMain/kotlin/EFCurve.kt +++ b/orx-fcurve/src/commonMain/kotlin/EFCurve.kt @@ -8,7 +8,7 @@ import org.openrndr.extra.expressions.evaluateExpression * @param constants a map of constants that is passed to [evaluateExpression] */ fun efcurve(ef: String, constants: Map = emptyMap()): String { - val expression = Regex("_([^_]+)_") + val expression = Regex("\\{([^_]+)\\}") // IntelliJ falsely reports a redundant escape character. the escape character is required when running the regular // expression on a javascript target. Removing the escape character will result in a `Lone quantifier brackets` diff --git a/orx-fcurve/src/commonTest/kotlin/TestEFCurve.kt b/orx-fcurve/src/commonTest/kotlin/TestEFCurve.kt index 89da902c..8c245c73 100644 --- a/orx-fcurve/src/commonTest/kotlin/TestEFCurve.kt +++ b/orx-fcurve/src/commonTest/kotlin/TestEFCurve.kt @@ -16,18 +16,18 @@ class TestEFCurve { @Test fun expressions() { - assertEquals("M${9.0}", efcurve("M_4 + 5_")) + assertEquals("M${9.0}", efcurve("M{4 + 5}")) } @Test fun listExpansion() { - assertEquals("M0 L1.0, ${3.0} L1.0, ${6.0}", efcurve("M0 |L1.0, _it_|{3, 6}")) + assertEquals("M0 L1.0, ${3.0} L1.0, ${6.0}", efcurve("M0 |L1.0, {it}|{3, 6}")) } @Test fun repetition() { assertEquals("M0 L1.0, 3.0 L1.0, 3.0", efcurve("M0 |L1.0, 3.0|[2]")) - assertEquals("M0 L1.0, ${0.0} L1.0, ${1.0}", efcurve("M0 |L1.0, _it_|[2]")) - assertEquals("M0 L1.0, ${0.0} L1.0, ${1.0} L1.0, ${0.0} L1.0, ${1.0} L1.0, ${0.0} L1.0, ${1.0}", efcurve("M0 ||L1.0, _it_|[2]|[3]")) + assertEquals("M0 L1.0, ${0.0} L1.0, ${1.0}", efcurve("M0 |L1.0, {it}|[2]")) + assertEquals("M0 L1.0, ${0.0} L1.0, ${1.0} L1.0, ${0.0} L1.0, ${1.0} L1.0, ${0.0} L1.0, ${1.0}", efcurve("M0 ||L1.0, {it}|[2]|[3]")) } } \ No newline at end of file