[orx-fcurve] improve handling of absolute hold command

This commit is contained in:
Edwin Jakobs
2024-05-09 10:41:27 +02:00
parent 4c086d9ff9
commit 15e1b4b04a
3 changed files with 28 additions and 14 deletions

View File

@@ -308,11 +308,8 @@ class FCurveBuilder {
if (relative) {
lineTo(x, cursor.y)
} else {
val d = x - cursor.x
require(d >= 0.0) {
"requested to hold until $x, but cursor is already at ${cursor.x}"
}
lineTo(d, cursor.y)
require(segments.isEmpty()) { "absolute hold (H $x) is only allowed when used as first command"}
cursor = cursor.copy(x = x)
}
path += "h$x"
}

View File

@@ -16,4 +16,20 @@ class TestFCurve {
assertEquals(10.5, normalizedSampler(1.0))
assertEquals(10.5, normalizedSampler(-1.0))
}
@Test
fun testAbsoluteHold() {
run {
val text = "H-1 L 5 5"
val fc = fcurve(text)
assertEquals(0.0, fc.value(-1.0))
assertEquals(5.0, fc.value(4.0))
}
run {
val text = "H1 L 5 5"
val fc = fcurve(text)
assertEquals(0.0, fc.value(1.0))
assertEquals(5.0, fc.value(6.0))
}
}
}