Class Spline

  • All Implemented Interfaces:
    TimelineEase

    public class Spline
    extends java.lang.Object
    implements TimelineEase
    Spline easer. Is based on the code from TimingFramework by Chet Haase and Romain Guy.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  Spline.FloatPoint  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.ArrayList<LengthItem> lengths  
      private float x1  
      private float x2  
      private float y1  
      private float y2  
    • Constructor Summary

      Constructors 
      Constructor Description
      Spline​(float easeAmount)  
      Spline​(float x1, float y1, float x2, float y2)
      Creates a new instance of SplineInterpolator with the control points defined by (x1, y1) and (x2, y2).
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private Spline.FloatPoint getXY​(float t)
      Calculates the XY point for a given t value.
      private float getY​(float t)
      Utility function: When we are evaluating the spline, we only care about the Y values.
      float map​(float lengthFraction)
      Given a fraction of time along the spline (which we can interpret as the length along a spline), return the interpolated value of the spline.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • x1

        private float x1
      • y1

        private float y1
      • x2

        private float x2
      • y2

        private float y2
      • lengths

        private java.util.ArrayList<LengthItem> lengths
    • Constructor Detail

      • Spline

        public Spline​(float easeAmount)
      • Spline

        public Spline​(float x1,
                      float y1,
                      float x2,
                      float y2)
        Creates a new instance of SplineInterpolator with the control points defined by (x1, y1) and (x2, y2). The anchor points are implicitly defined as (0, 0) and (1, 1).
        Parameters:
        x1 - X coordinate of the first control point
        y1 - Y coordinate of the first control point
        x2 - X coordinate of the second control point
        y2 - Y coordinate of the second control point
        Throws:
        java.lang.IllegalArgumentException - This exception is thrown when values beyond the allowed [0,1] range are passed in
    • Method Detail

      • getXY

        private Spline.FloatPoint getXY​(float t)
        Calculates the XY point for a given t value.

        The general spline equation is: x = b0*x0 + b1*x1 + b2*x2 + b3*x3 y = b0*y0 + b1*y1 + b2*y2 + b3*y3 where: b0 = (1-t)^3 b1 = 3 * t * (1-t)^2 b2 = 3 * t^2 * (1-t) b3 = t^3 We know that (x0,y0) == (0,0) and (x1,y1) == (1,1) for our splines, so this simplifies to: x = b1*x1 + b2*x2 + b3 y = b1*x1 + b2*x2 + b3

        Parameters:
        t - parametric value for spline calculation
      • getY

        private float getY​(float t)
        Utility function: When we are evaluating the spline, we only care about the Y values. See getXY(float) for the details.
      • map

        public float map​(float lengthFraction)
        Given a fraction of time along the spline (which we can interpret as the length along a spline), return the interpolated value of the spline. We first calculate the t value for the length (by doing a lookup in our array of previousloy calculated values and then linearly interpolating between the nearest values) and then calculate the Y value for this t.
        Specified by:
        map in interface TimelineEase
        Parameters:
        lengthFraction - Fraction of time in a given time interval.
        Returns:
        interpolated fraction between 0 and 1