[orx-fcurve] Clean-up FCurve.kt
This commit is contained in:
@@ -48,7 +48,6 @@ fun Segment2D.scaleTangents(axis: Vector2 = Vector2.UNIT_X): Segment2D {
|
|||||||
val c = this.cubic
|
val c = this.cubic
|
||||||
val width = end.distanceTo(start)
|
val width = end.distanceTo(start)
|
||||||
|
|
||||||
val d = c.end - c.start
|
|
||||||
val cd0 = (c.control[0] - c.start).projectedOn(axis)
|
val cd0 = (c.control[0] - c.start).projectedOn(axis)
|
||||||
val cd0a = cd0.dot(axis)
|
val cd0a = cd0.dot(axis)
|
||||||
val cd1 = (c.control[1] - c.end).projectedOn(-axis)
|
val cd1 = (c.control[1] - c.end).projectedOn(-axis)
|
||||||
@@ -220,7 +219,7 @@ data class FCurve(val segments: List<Segment2D>) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Evaluate the Fcurve at [t]
|
* Evaluate the Fcurve at [t]
|
||||||
* @param segment an optional segment that can be used to speed up scanning for the relevant segment
|
* @param cachedSegment an optional segment that can be used to speed up scanning for the relevant segment
|
||||||
*/
|
*/
|
||||||
fun valueWithSegment(t: Double, cachedSegment: Segment2D? = null): Pair<Double, Segment2D?> {
|
fun valueWithSegment(t: Double, cachedSegment: Segment2D? = null): Pair<Double, Segment2D?> {
|
||||||
if (cachedSegment != null) {
|
if (cachedSegment != null) {
|
||||||
@@ -348,11 +347,9 @@ class FCurveBuilder {
|
|||||||
|
|
||||||
if (segments.isNotEmpty()) {
|
if (segments.isNotEmpty()) {
|
||||||
val lastSegment = segments.last()
|
val lastSegment = segments.last()
|
||||||
val lastDuration = lastSegment.end.x - lastSegment.start.x
|
|
||||||
val outTangent = if (segments.last().linear) lastSegment.end else segments.last().control.last()
|
val outTangent = if (segments.last().linear) lastSegment.end else segments.last().control.last()
|
||||||
val outPos = lastSegment.end
|
val outPos = lastSegment.end
|
||||||
val d = outPos - outTangent
|
val d = outPos - outTangent
|
||||||
//val dn = d.normalized
|
|
||||||
val ts = 1.0// x / lastDuration
|
val ts = 1.0// x / lastDuration
|
||||||
segments.add(
|
segments.add(
|
||||||
Segment2D(
|
Segment2D(
|
||||||
@@ -417,14 +414,20 @@ fun fcurve(builder: FCurveBuilder.() -> Unit): FCurve {
|
|||||||
return fb.build()
|
return fb.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Split an Fcurve string in to command parts
|
* Splits an input string containing fcurve path commands and numbers into individual components,
|
||||||
|
* preserving the order of commands and associated numbers.
|
||||||
|
* The splitting considers the relations between commands and numbers, ensuring proper separation.
|
||||||
|
*
|
||||||
|
* @param d The input string representing fcurve path commands and numbers.
|
||||||
|
* @return A list of strings where each element is either an fcurve path command or a related numerical value.
|
||||||
*/
|
*/
|
||||||
fun fCurveCommands(d: String): List<String> {
|
fun fCurveCommands(d: String): List<String> {
|
||||||
val svgCommands = "mMlLqQsStTcChH"
|
val fcurveCommands = "mMlLqQsStTcChH"
|
||||||
val number = "0-9.\\-E%"
|
val number = "0-9.\\-E%"
|
||||||
|
|
||||||
return d.split(Regex("(?:[\t ,]|\r?\n)+|(?<=[$svgCommands])(?=[$number])|(?<=[$number])(?=[$svgCommands])"))
|
return d.split(Regex("(?:[\t ,]|\r?\n)+|(?<=[$fcurveCommands])(?=[$number])|(?<=[$number])(?=[$fcurveCommands])"))
|
||||||
.filter { it.isNotBlank() }
|
.filter { it.isNotBlank() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user