@@ -26,32 +26,32 @@ Item {
26 signal velocityThresholdTriggered
26 signal velocityThresholdTriggered
28 function reset() {
28 function reset() {
29+ velocityTimer.stop();
29 stopLateralChanges = false;
30 stopLateralChanges = false;
30 calc.reset();
31 calc.reset();
33− function calculate() {
34+ function update() {
35+ calc.trackedPosition = trackedValue;
34 stopLateralChanges = Math.abs(calc.calculate()) > velocityThreshold;
36 stopLateralChanges = Math.abs(calc.calculate()) > velocityThreshold;
37 onTrackedValueChanged: {
39 onTrackedValueChanged: {
38− calc.trackedPosition = trackedValue;
40+ update(); // initial calculation
41+ if (root.stopLateralChanges) { // only start timer if we're above the threshold.
39− velocityTimer.start();
42+ velocityTimer.start();
42 AxisVelocityCalculator {
46 AxisVelocityCalculator {
44− onTrackedPositionChanged: calculate();
48 id: velocityTimer
51 id: velocityTimer
49 interval: 50
52 interval: 50
50 onTriggered: {
53 onTriggered: {
51− var recalculate = calc.trackedPosition == trackedValue;
54+ update();
52− calc.trackedPosition = trackedValue;
53− if (recalculate) calculate();
55 if (root.stopLateralChanges) {
55 if (root.stopLateralChanges) {
56 velocityTimer.start();
56 velocityTimer.start();