Class Looper

java.lang.Object
org.vanted.animation.loopers.Looper
Direct Known Subclasses:
ForwardLooper, StandardLooper, SwingLooper

public abstract class Looper
extends Object
Author:
- Patrick Shaw The looper class which points the Interpolator classes need to perform an interpolation. It also works out what the previousIndex is for Animation classes.
  • Constructor Summary

    Constructors
    Constructor Description
    Looper()  
  • Method Summary

    Modifier and Type Method Description
    <V,​ T extends TimePoint<V>>
    int
    findPreviousIndex​(List<T> dataPoints, int oldPreviousIndex, int currentLoopNumber, double time)
    (Provided this method is not overridden) Finds the largest index, from a set of data points, who's getTime() method is <= time.
    <V,​ T extends TimePoint<V>>
    int
    getNextLoopPreviousIndex​(List<T> dataPoints, int newLoopNumber)
    Specifies what the previousIndex animation should be set to when it starts a new loop.
    <V,​ T extends InterpolatableTimePoint<V>>
    double
    getNormalizedTime​(double time, double loopDuration, List<T> dataPoints, List<T> pointsUsed, T previousPoint, T nextPoint)
    Calculates how far the time is from the next data point as a percentage.
    <V,​ T extends TimePoint<V>>
    int[]
    getPointIndexes​(List<T> dataPoints, int previousIndex, int pointsBefore, int pointsAfter)  
    <V,​ T extends TimePoint<V>>
    List<T>
    getPointsUsed​(List<T> dataPoints, int previousIndex, int pointsBefore, int pointsAfter)  
    double getTimeSinceStartOfLoop​(int currentLoopNumber, double startTime, double loopDuration, double time)
    Calculates the time since the start of the loop

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Looper

      public Looper()
  • Method Details

    • getPointIndexes

      public <V,​ T extends TimePoint<V>> int[] getPointIndexes​(List<T> dataPoints, int previousIndex, int pointsBefore, int pointsAfter)
      Parameters:
      time -
      dataPoints -
      previousIndex - The last data point that time has past with respect to time.
      pointsBefore - The number of points to return that are before dataPoints[previousIndex].
      pointsAfter - The number of points to return that are after dataPoints[previousIndex].
      Returns:
      Returns a set of indexes relative to the previousIndex.
    • getPointsUsed

      public <V,​ T extends TimePoint<V>> List<T> getPointsUsed​(List<T> dataPoints, int previousIndex, int pointsBefore, int pointsAfter)
      Parameters:
      x - A value between 0 and 1 that represents where a particular values is relative to the two data points it is between. Eg. If you have two points, (1,5) and (4,5) and you want to interpolate (2,?) then x=0.25
      y - The y values used for the particular interpolation.
    • findPreviousIndex

      public <V,​ T extends TimePoint<V>> int findPreviousIndex​(List<T> dataPoints, int oldPreviousIndex, int currentLoopNumber, double time)
      (Provided this method is not overridden) Finds the largest index, from a set of data points, who's getTime() method is <= time.
      Type Parameters:
      V - The type of data value that the data point holds.
      T - The type of data point that the interpolator is interpolating for.
      Parameters:
      dataPoints - The set of data points that the interpolator is interpolating on
      oldPreviousIndex - The old index that was being used before this method was called
      currentLoopNumber - The current loop number of the animation
      time - The time that has elapsed since the start of the animation loop.
      Returns:
      The largest index from a set of data points, who's getTime() return value is <= time.
      See Also:
      TimePoint.getTime()
    • getNextLoopPreviousIndex

      public <V,​ T extends TimePoint<V>> int getNextLoopPreviousIndex​(List<T> dataPoints, int newLoopNumber)
      Specifies what the previousIndex animation should be set to when it starts a new loop.
      Parameters:
      dataPoints - The set of data points that the interpolator is interpolating on.
      newLoopNumber - The animation's new loop number.
      Returns:
      The new previousIndex value of the Animation.
    • getTimeSinceStartOfLoop

      public double getTimeSinceStartOfLoop​(int currentLoopNumber, double startTime, double loopDuration, double time)
      Calculates the time since the start of the loop
      Parameters:
      currentLoopNumber - The animation's loop number.
      Returns:
      The time since the start of the animation's current loop.
    • getNormalizedTime

      public <V,​ T extends InterpolatableTimePoint<V>> double getNormalizedTime​(double time, double loopDuration, List<T> dataPoints, List<T> pointsUsed, T previousPoint, T nextPoint)
      Calculates how far the time is from the next data point as a percentage.
      Eg. If there are 4 points with times: 3,6,7,9 and time = 6.5 then this method will return 0.5 because 6.5-6/7-6 = 0.5
      Type Parameters:
      V - The type of data value that the data point holds.
      T - The type of data point that the interpolator is interpolating for.
      Parameters:
      time - The time has elapsed since the start of the animation.
      loopDuration - How long each loop takes in milliseconds
      dataPoints - All the dataPoints that the interpolator needs to interpolate between
      pointsUsed - The points being used for the interpolation.
      Returns:
      A value between 0 and 1.