We might have delta zero when we change segment
This should not produce a WTF log (or a crash in eng-build).
Test: atest MotionValueTest
Bug: 420622452
Flag: com.android.systemui.scene_container
Change-Id: I93748b0d02fb7215874b650bf9bce9212ce4a6ab
diff --git a/mechanics/src/com/android/mechanics/impl/Computations.kt b/mechanics/src/com/android/mechanics/impl/Computations.kt
index 9e80b9a..2ac9574 100644
--- a/mechanics/src/com/android/mechanics/impl/Computations.kt
+++ b/mechanics/src/com/android/mechanics/impl/Computations.kt
@@ -495,21 +495,23 @@
val delta = afterBreakpoint - beforeBreakpoint
val deltaIsFinite = delta.fastIsFinite()
- if (deltaIsFinite && delta != 0f) {
- // There is a discontinuity on this breakpoint, that needs to be
- // animated. The delta is pushed to the spring, to consume the
- // discontinuity over time.
- springState =
- springState.nudge(
- displacementDelta = -delta,
- velocityDelta = initialSpringVelocity,
- )
+ if (deltaIsFinite) {
+ if (delta != 0f) {
+ // There is a discontinuity on this breakpoint, that needs to be
+ // animated. The delta is pushed to the spring, to consume the
+ // discontinuity over time.
+ springState =
+ springState.nudge(
+ displacementDelta = -delta,
+ velocityDelta = initialSpringVelocity,
+ )
- // When *first* crossing a discontinuity in a given frame, the static
- // mapped velocity observed during previous frame is added as initial
- // velocity to the spring. This is done ot most once per frame, and only
- // if there is an actual discontinuity.
- initialSpringVelocity = 0f
+ // When *first* crossing a discontinuity in a given frame, the
+ // static mapped velocity observed during previous frame is added as
+ // initial velocity to the spring. This is done ot most once per
+ // frame, and only if there is an actual discontinuity.
+ initialSpringVelocity = 0f
+ }
} else {
// The before and / or after mapping produced an non-finite number,
// which is not allowed. This intentionally crashes eng-builds, since
diff --git a/mechanics/tests/goldens/segmentChange_inMaxDirection_zeroDelta.json b/mechanics/tests/goldens/segmentChange_inMaxDirection_zeroDelta.json
new file mode 100644
index 0000000..f68e961
--- /dev/null
+++ b/mechanics/tests/goldens/segmentChange_inMaxDirection_zeroDelta.json
@@ -0,0 +1,82 @@
+{
+ "frame_ids": [
+ 0,
+ 16,
+ 32,
+ 48
+ ],
+ "features": [
+ {
+ "name": "input",
+ "type": "float",
+ "data_points": [
+ 0,
+ 0.5,
+ 1,
+ 1
+ ]
+ },
+ {
+ "name": "gestureDirection",
+ "type": "string",
+ "data_points": [
+ "Max",
+ "Max",
+ "Max",
+ "Max"
+ ]
+ },
+ {
+ "name": "output",
+ "type": "float",
+ "data_points": [
+ 0,
+ 0,
+ 0,
+ 0
+ ]
+ },
+ {
+ "name": "outputTarget",
+ "type": "float",
+ "data_points": [
+ 0,
+ 0,
+ 0,
+ 0
+ ]
+ },
+ {
+ "name": "outputSpring",
+ "type": "springParameters",
+ "data_points": [
+ {
+ "stiffness": 100000,
+ "dampingRatio": 1
+ },
+ {
+ "stiffness": 700,
+ "dampingRatio": 0.9
+ },
+ {
+ "stiffness": 700,
+ "dampingRatio": 0.9
+ },
+ {
+ "stiffness": 700,
+ "dampingRatio": 0.9
+ }
+ ]
+ },
+ {
+ "name": "isStable",
+ "type": "boolean",
+ "data_points": [
+ true,
+ true,
+ true,
+ true
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/mechanics/tests/src/com/android/mechanics/MotionValueTest.kt b/mechanics/tests/src/com/android/mechanics/MotionValueTest.kt
index 9341710..ffb8e87 100644
--- a/mechanics/tests/src/com/android/mechanics/MotionValueTest.kt
+++ b/mechanics/tests/src/com/android/mechanics/MotionValueTest.kt
@@ -112,6 +112,13 @@
}
@Test
+ fun segmentChange_inMaxDirection_zeroDelta() =
+ motion.goldenTest(spec = specBuilder(Mapping.Zero) { fixedValueFromCurrent(0.5f) }) {
+ animateValueTo(1f, changePerFrame = 0.5f)
+ awaitStable()
+ }
+
+ @Test
fun segmentChange_inMinDirection_animatedWhenReachingBreakpoint() =
motion.goldenTest(
initialValue = 2f,
@@ -198,9 +205,6 @@
) {
animateValueTo(21f, changePerFrame = 3f)
awaitStable()
-
- // TODO(b/420622452) This test should not produce a WTF log.
- wtfLog.removeLoggedFailures()
}
@Test
@@ -214,9 +218,6 @@
) {
animateValueTo(30f, changePerFrame = 3f)
awaitStable()
-
- // TODO(b/420622452) This test should not produce a WTF log.
- wtfLog.removeLoggedFailures()
}
@Test
@@ -248,9 +249,6 @@
awaitStable()
animateValueTo(3f)
awaitStable()
-
- // TODO(b/420622452) This test should not produce a WTF log.
- wtfLog.removeLoggedFailures()
}
@Test