[orx-fcurve] Add FCurve.start, Fcurve.end, MultiFCurve.start, MultiFCurve.end
This commit is contained in:
@@ -129,6 +129,31 @@ data class FCurve(val segments: List<Segment2D>) {
|
||||
* The unitless duration of the Fcurve
|
||||
*/
|
||||
val duration: Double
|
||||
get() {
|
||||
return if (segments.isEmpty()) {
|
||||
0.0
|
||||
} else {
|
||||
end - start
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The unitless start position of the Fcurve
|
||||
*/
|
||||
val start: Double
|
||||
get() {
|
||||
return if (segments.isEmpty()) {
|
||||
0.0
|
||||
} else {
|
||||
segments.first().start.x
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The unitless end position of the Fcurve
|
||||
*/
|
||||
val end: Double
|
||||
get() {
|
||||
return if (segments.isEmpty()) {
|
||||
0.0
|
||||
@@ -137,6 +162,7 @@ data class FCurve(val segments: List<Segment2D>) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Evaluate the Fcurve at [t]
|
||||
* @param segment an optional segment that can be used to speed up scanning for the relevant segment
|
||||
|
||||
@@ -13,6 +13,18 @@ open class MultiFCurve(val compounds: Map<String, FCurve?>) {
|
||||
* Duration of the [MultiFCurve]
|
||||
*/
|
||||
val duration by lazy { compounds.values.maxOfOrNull { it?.duration ?: 0.0 } ?: 0.0 }
|
||||
|
||||
|
||||
/**
|
||||
* Start position of the [MultiFCurve]
|
||||
*/
|
||||
val start by lazy { compounds.values.minOfOrNull { it?.start ?: 0.0 } ?: 0.0 }
|
||||
|
||||
/**
|
||||
* End position of the [MultiFCurve]
|
||||
*/
|
||||
val end by lazy { compounds.values.maxOfOrNull { it?.end ?: 0.0 } ?: 0.0 }
|
||||
|
||||
operator fun get(name: String): FCurve? {
|
||||
return compounds[name]
|
||||
}
|
||||
|
||||
@@ -24,12 +24,18 @@ class TestFCurve {
|
||||
val fc = fcurve(text)
|
||||
assertEquals(0.0, fc.value(-1.0))
|
||||
assertEquals(5.0, fc.value(4.0))
|
||||
assertEquals(-1.0, fc.start)
|
||||
assertEquals(4.0, fc.end)
|
||||
assertEquals(5.0, fc.duration)
|
||||
}
|
||||
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))
|
||||
assertEquals(1.0, fc.start)
|
||||
assertEquals(6.0, fc.end)
|
||||
assertEquals(5.0, fc.duration)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user