~ubuntu-branches/debian/stretch/insubstantial/stretch

« back to all changes in this revision

Viewing changes to trident/src/main/java/org/pushingpixels/trident/interpolator/KeyTimes.java

  • Committer: Package Import Robot
  • Author(s): Felix Natter
  • Date: 2016-01-18 20:58:45 UTC
  • Revision ID: package-import@ubuntu.com-20160118205845-crbmrkda61qsi5qa
Tags: upstream-7.3+dfsg2
ImportĀ upstreamĀ versionĀ 7.3+dfsg2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright (c) 2005-2006, Sun Microsystems, Inc
 
3
 * All rights reserved.
 
4
 * 
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions
 
7
 * are met:
 
8
 * 
 
9
 *   * Redistributions of source code must retain the above copyright
 
10
 *     notice, this list of conditions and the following disclaimer.
 
11
 *   * Redistributions in binary form must reproduce the above
 
12
 *     copyright notice, this list of conditions and the following 
 
13
 *     disclaimer in the documentation and/or other materials provided 
 
14
 *     with the distribution.
 
15
 *   * Neither the name of the TimingFramework project nor the names of its
 
16
 *     contributors may be used to endorse or promote products derived 
 
17
 *     from this software without specific prior written permission.
 
18
 * 
 
19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
20
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
21
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
22
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
23
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
24
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
25
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
26
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
27
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
28
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
29
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
30
 */
 
31
 
 
32
package org.pushingpixels.trident.interpolator;
 
33
 
 
34
import java.util.ArrayList;
 
35
 
 
36
/**
 
37
 * Stores a list of times from 0 to 1 (the elapsed fraction of an animation
 
38
 * cycle) that are used in calculating interpolated
 
39
 * values for PropertySetter given a matching set of KeyValues and
 
40
 * Interpolators for those time intervals.  In the simplest case, a
 
41
 * KeyFrame will consist of just two times in KeyTimes: 0 and 1.
 
42
 *
 
43
 * @author Chet
 
44
 */
 
45
public class KeyTimes {
 
46
    
 
47
    private ArrayList<Float> times = new ArrayList<Float>();
 
48
    
 
49
    /** 
 
50
     * Creates a new instance of KeyTimes.  Times should be in increasing
 
51
     * order and should all be in the range [0,1], with the first value
 
52
     * being zero and the last being 1
 
53
     * @throws IllegalArgumentException Time values must be ordered in
 
54
     * increasing value, the first value must be 0 and the last value
 
55
     * must be 1
 
56
     */
 
57
    public KeyTimes(float... times) {
 
58
        if (times[0] != 0) {
 
59
            throw new IllegalArgumentException("First time value must" +
 
60
                    " be zero");
 
61
        }
 
62
        if (times[times.length - 1] != 1.0f) {
 
63
            throw new IllegalArgumentException("Last time value must" +
 
64
                    " be one");
 
65
        }
 
66
        float prevTime = 0;
 
67
        for (float time : times) {
 
68
            if (time < prevTime) {
 
69
                throw new IllegalArgumentException("Time values must be" +
 
70
                        " in increasing order");
 
71
            }
 
72
            this.times.add(time);
 
73
            prevTime = time;
 
74
        }
 
75
    }
 
76
    
 
77
    ArrayList getTimes() {
 
78
        return times;
 
79
    }
 
80
    
 
81
    int getSize() {
 
82
        return times.size();
 
83
    }
 
84
 
 
85
    /**
 
86
     * Returns time interval that contains this time fraction
 
87
     */
 
88
    int getInterval(float fraction) {
 
89
        int prevIndex = 0;
 
90
        for (int i = 1; i < times.size(); ++i) {
 
91
            float time = times.get(i);
 
92
            if (time >= fraction) { 
 
93
                // inclusive of start time at next interval.  So fraction==1
 
94
                // will return the final interval (times.size() - 1)
 
95
                return prevIndex;
 
96
            }
 
97
            prevIndex = i;
 
98
        }
 
99
        return prevIndex;
 
100
    }
 
101
 
 
102
    float getTime(int index) {
 
103
        return times.get(index);
 
104
    }
 
105
}
 
 
b'\\ No newline at end of file'