Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SimpleInterpolator |
|
| 0.0;0 | ||||
SimpleInterpolator$Intf |
|
| 0.0;0 |
1 | /* | |
2 | * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. | |
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 | * | |
5 | * This code is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU General Public License version 2 only, as | |
7 | * published by the Free Software Foundation. Sun designates this | |
8 | * particular file as subject to the "Classpath" exception as provided | |
9 | * by Sun in the LICENSE file that accompanied this code. | |
10 | * | |
11 | * This code is distributed in the hope that it will be useful, but WITHOUT | |
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 | * version 2 for more details (a copy is included in the LICENSE file that | |
15 | * accompanied this code). | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License version | |
18 | * 2 along with this work; if not, write to the Free Software Foundation, | |
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
20 | * | |
21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
22 | * CA 95054 USA or visit www.sun.com if you need additional information or | |
23 | * have any questions. | |
24 | */ | |
25 | ||
26 | package javafx.animation; | |
27 | import java.lang.Object; | |
28 | ||
29 | /** A SimpleIterator is defined in terms of a "curve". | |
30 | * It can be used for any value type that either implements Interpolatable | |
31 | * or that extends java.lang.Number. | |
32 | */ | |
33 | ||
34 | 60 | public abstract class SimpleInterpolator extends Interpolator { |
35 | ||
36 | /** Mapping from [0.0..1.0] to itself. | |
37 | * @param t time, but normalized to the range [0.0..1.0], | |
38 | 4 | * where 0.0 is the start of the current interval (KeyFrame), |
39 | * while 1.0 is the end of the current interval (KeyFrame). | |
40 | * Usually a function that increases monotonically. | |
41 | */ | |
42 | public abstract function curve(t: Number) : Number; | |
43 | ||
44 | public function interpolate(startValue:Object, endValue:Object, fraction:Number):Object { | |
45 | if (startValue instanceof java.lang.Number and | |
46 | endValue instanceof java.lang.Number) { | |
47 | 26 | var start : Number = (startValue as java.lang.Number).doubleValue(); |
48 | 26 | var end : Number = (endValue as java.lang.Number).doubleValue(); |
49 | 26 | var val = start + (end-start)*curve(fraction); |
50 | if (startValue instanceof java.lang.Integer and | |
51 | endValue instanceof java.lang.Integer) | |
52 | 0 | java.lang.Integer.valueOf((val+0.5).intValue()) |
53 | else | |
54 | 26 | java.lang.Double.valueOf(val) |
55 | } | |
56 | else if (startValue instanceof Interpolatable) { | |
57 | 0 | (startValue as Interpolatable).ofTheWay((endValue as Interpolatable), curve(fraction)); |
58 | } else { | |
59 | // discrete | |
60 | 13 | if (fraction == 1.0) endValue else startValue; |
61 | } | |
62 | } | |
63 | ||
64 | public function interpolate(startValue:Number, endValue:Number, fraction:Number):Number { | |
65 | 0 | return startValue + (endValue-startValue)*curve(fraction); |
66 | } | |
67 | ||
68 | 0 | public function interpolate(startValue:Integer, endValue:Integer, fraction:Number):Integer { |
69 | 0 | return (startValue + (endValue-startValue)*curve(fraction) + 0.5).intValue(); |
70 | } | |
71 | } |