• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.example.android.curvedmotion;
17 
18 import android.animation.TypeEvaluator;
19 
20 /**
21  * This evaluator interpolates between two PathPoint values given the value t, the
22  * proportion traveled between those points. The value of the interpolation depends
23  * on the operation specified by the endValue (the operation for the interval between
24  * PathPoints is always specified by the end point of that interval).
25  */
26 public class PathEvaluator implements TypeEvaluator<PathPoint> {
27     @Override
evaluate(float t, PathPoint startValue, PathPoint endValue)28     public PathPoint evaluate(float t, PathPoint startValue, PathPoint endValue) {
29         float x, y;
30         if (endValue.mOperation == PathPoint.CURVE) {
31             float oneMinusT = 1 - t;
32             x = oneMinusT * oneMinusT * oneMinusT * startValue.mX +
33                     3 * oneMinusT * oneMinusT * t * endValue.mControl0X +
34                     3 * oneMinusT * t * t * endValue.mControl1X +
35                     t * t * t * endValue.mX;
36             y = oneMinusT * oneMinusT * oneMinusT * startValue.mY +
37                     3 * oneMinusT * oneMinusT * t * endValue.mControl0Y +
38                     3 * oneMinusT * t * t * endValue.mControl1Y +
39                     t * t * t * endValue.mY;
40         } else if (endValue.mOperation == PathPoint.LINE) {
41             x = startValue.mX + t * (endValue.mX - startValue.mX);
42             y = startValue.mY + t * (endValue.mY - startValue.mY);
43         } else {
44             x = endValue.mX;
45             y = endValue.mY;
46         }
47         return PathPoint.moveTo(x, y);
48     }
49 }
50