Skip to content

Commit b631e44

Browse files
committed
[orx-fcurve] Clean-up FCurve.kt
1 parent ff2918f commit b631e44

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

orx-fcurve/src/commonMain/kotlin/FCurve.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ fun Segment2D.scaleTangents(axis: Vector2 = Vector2.UNIT_X): Segment2D {
4848
val c = this.cubic
4949
val width = end.distanceTo(start)
5050

51-
val d = c.end - c.start
5251
val cd0 = (c.control[0] - c.start).projectedOn(axis)
5352
val cd0a = cd0.dot(axis)
5453
val cd1 = (c.control[1] - c.end).projectedOn(-axis)
@@ -220,7 +219,7 @@ data class FCurve(val segments: List<Segment2D>) {
220219

221220
/**
222221
* Evaluate the Fcurve at [t]
223-
* @param segment an optional segment that can be used to speed up scanning for the relevant segment
222+
* @param cachedSegment an optional segment that can be used to speed up scanning for the relevant segment
224223
*/
225224
fun valueWithSegment(t: Double, cachedSegment: Segment2D? = null): Pair<Double, Segment2D?> {
226225
if (cachedSegment != null) {
@@ -348,11 +347,9 @@ class FCurveBuilder {
348347

349348
if (segments.isNotEmpty()) {
350349
val lastSegment = segments.last()
351-
val lastDuration = lastSegment.end.x - lastSegment.start.x
352350
val outTangent = if (segments.last().linear) lastSegment.end else segments.last().control.last()
353351
val outPos = lastSegment.end
354352
val d = outPos - outTangent
355-
//val dn = d.normalized
356353
val ts = 1.0// x / lastDuration
357354
segments.add(
358355
Segment2D(
@@ -417,14 +414,20 @@ fun fcurve(builder: FCurveBuilder.() -> Unit): FCurve {
417414
return fb.build()
418415
}
419416

417+
420418
/**
421-
* Split an Fcurve string in to command parts
419+
* Splits an input string containing fcurve path commands and numbers into individual components,
420+
* preserving the order of commands and associated numbers.
421+
* The splitting considers the relations between commands and numbers, ensuring proper separation.
422+
*
423+
* @param d The input string representing fcurve path commands and numbers.
424+
* @return A list of strings where each element is either an fcurve path command or a related numerical value.
422425
*/
423426
fun fCurveCommands(d: String): List<String> {
424-
val svgCommands = "mMlLqQsStTcChH"
427+
val fcurveCommands = "mMlLqQsStTcChH"
425428
val number = "0-9.\\-E%"
426429

427-
return d.split(Regex("(?:[\t ,]|\r?\n)+|(?<=[$svgCommands])(?=[$number])|(?<=[$number])(?=[$svgCommands])"))
430+
return d.split(Regex("(?:[\t ,]|\r?\n)+|(?<=[$fcurveCommands])(?=[$number])|(?<=[$number])(?=[$fcurveCommands])"))
428431
.filter { it.isNotBlank() }
429432
}
430433

0 commit comments

Comments
 (0)