blob: 9463aa12d116b9d3669ec023d486cf69fdbbdd1c [file] [log] [blame]
Chet Haase17fb4b02010-06-28 17:55:07 -07001/*
2 * Copyright (C) 2010 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
17package android.animation;
18
19/**
20 * This evaluator can be used to perform type interpolation between <code>float</code> values.
21 */
Chet Haaseb39f0512011-05-24 14:36:40 -070022public class FloatEvaluator implements TypeEvaluator<Number> {
Chet Haase17fb4b02010-06-28 17:55:07 -070023
24 /**
25 * This function returns the result of linearly interpolating the start and end values, with
26 * <code>fraction</code> representing the proportion between the start and end values. The
27 * calculation is a simple parametric calculation: <code>result = x0 + t * (v1 - v0)</code>,
28 * where <code>x0</code> is <code>startValue</code>, <code>x1</code> is <code>endValue</code>,
29 * and <code>t</code> is <code>fraction</code>.
30 *
31 * @param fraction The fraction from the starting to the ending values
32 * @param startValue The start value; should be of type <code>float</code> or
33 * <code>Float</code>
34 * @param endValue The end value; should be of type <code>float</code> or <code>Float</code>
35 * @return A linear interpolation between the start and end values, given the
36 * <code>fraction</code> parameter.
37 */
Chet Haaseb39f0512011-05-24 14:36:40 -070038 public Float evaluate(float fraction, Number startValue, Number endValue) {
39 float startFloat = startValue.floatValue();
40 return startFloat + fraction * (endValue.floatValue() - startFloat);
Chet Haase17fb4b02010-06-28 17:55:07 -070041 }
42}