Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit 9cd4b5a

Browse files
committed
Fix CycleEditor
CycleEditor would return the wrong (last) value at the given keyframes.
1 parent 285431d commit 9cd4b5a

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

desktop/CycleEditor/src/main/java/androidx/motionlayout/cycleEditor/CycleView.java

+13-11
Original file line numberDiff line numberDiff line change
@@ -696,20 +696,22 @@ public void normalize() {
696696
}
697697

698698
double getP(double time) {
699+
if (time <= 0.0) {
700+
return 0.0;
701+
} else if (time >= 1) {
702+
return 1.0;
703+
}
699704
int index = Arrays.binarySearch(mPosition, time);
700-
double p = 0;
701-
if (index > 0) {
702-
p = 1;
703-
} else if (index != 0) {
705+
if (index < 0) {
704706
index = -index - 1;
705-
double t = time;
706-
double m =
707-
(mPeriod[index] - mPeriod[index - 1]) / (mPosition[index] - mPosition[index - 1]);
708-
p = mArea[index - 1]
709-
+ (mPeriod[index - 1] - m * mPosition[index - 1]) * (t - mPosition[index - 1])
710-
+ m * (t * t - mPosition[index - 1] * mPosition[index - 1]) / 2;
711707
}
712-
return p;
708+
709+
double t = time;
710+
double m =
711+
(mPeriod[index] - mPeriod[index - 1]) / (mPosition[index] - mPosition[index - 1]);
712+
return mArea[index - 1]
713+
+ (mPeriod[index - 1] - m * mPosition[index - 1]) * (t - mPosition[index - 1])
714+
+ m * (t * t - mPosition[index - 1] * mPosition[index - 1]) / 2;
713715
}
714716

715717
public double getValue(double time) {

desktop/CycleEditor/src/main/java/androidx/motionlayout/cycleEditor/Oscillator.java

+13-10
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,22 @@ public Oscillator() {
5858
}
5959

6060
double getP(double time) {
61+
if (time <= 0.0) {
62+
return 0.0;
63+
} else if (time >= 1) {
64+
return 1.0;
65+
}
6166
int index = Arrays.binarySearch(mPosition, time);
62-
double p = 0;
63-
if (index > 0) {
64-
p = 1;
65-
} else if (index != 0) {
67+
if (index < 0) {
6668
index = -index - 1;
67-
double t = time;
68-
double m = (mPeriod[index] - mPeriod[index - 1]) / (mPosition[index] - mPosition[index - 1]);
69-
p = mArea[index - 1]
70-
+ (mPeriod[index - 1] - m * mPosition[index - 1]) * (t - mPosition[index - 1])
71-
+ m * (t * t - mPosition[index - 1] * mPosition[index - 1]) / 2;
7269
}
73-
return p;
70+
71+
double t = time;
72+
double m =
73+
(mPeriod[index] - mPeriod[index - 1]) / (mPosition[index] - mPosition[index - 1]);
74+
return mArea[index - 1]
75+
+ (mPeriod[index - 1] - m * mPosition[index - 1]) * (t - mPosition[index - 1])
76+
+ m * (t * t - mPosition[index - 1] * mPosition[index - 1]) / 2;
7477
}
7578

7679
public double getValue(double time) {

0 commit comments

Comments
 (0)