diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2016-12-01 20:21:09 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-12-01 20:21:13 +0000 |
commit | e9bf7c843664c16aaeac4cd79550a7461ae00b5d (patch) | |
tree | e6040f06dab501e70dbac0888123b2f85b627c80 /libs/hwui/Interpolator.cpp | |
parent | f7c77a3caea19bc0f9677e295428e9abb769ad5c (diff) | |
parent | 9e9eeeeb78d94804cda00c2b36e56fdaca5552d6 (diff) |
Merge "Introduce PathInterpolator to native animators"
Diffstat (limited to 'libs/hwui/Interpolator.cpp')
-rw-r--r-- | libs/hwui/Interpolator.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/libs/hwui/Interpolator.cpp b/libs/hwui/Interpolator.cpp index bddb01b97865..f94a22d51d9f 100644 --- a/libs/hwui/Interpolator.cpp +++ b/libs/hwui/Interpolator.cpp @@ -88,6 +88,39 @@ float OvershootInterpolator::interpolate(float t) { return t * t * ((mTension + 1) * t + mTension) + 1.0f; } +float PathInterpolator::interpolate(float t) { + if (t <= 0) { + return 0; + } else if (t >= 1) { + return 1; + } + // Do a binary search for the correct x to interpolate between. + size_t startIndex = 0; + size_t endIndex = mX.size() - 1; + + while (endIndex > startIndex + 1) { + int midIndex = (startIndex + endIndex) / 2; + if (t < mX[midIndex]) { + endIndex = midIndex; + } else { + startIndex = midIndex; + } + } + + float xRange = mX[endIndex] - mX[startIndex]; + if (xRange == 0) { + return mY[startIndex]; + } + + float tInRange = t - mX[startIndex]; + float fraction = tInRange / xRange; + + float startY = mY[startIndex]; + float endY = mY[endIndex]; + return startY + (fraction * (endY - startY)); + +} + LUTInterpolator::LUTInterpolator(float* values, size_t size) : mValues(values) , mSize(size) { |