Class Curve

java.lang.Object
ca.spatial.tracks.builder.Curve
All Implemented Interfaces:
Iterator<CurvePoint>

public class Curve extends Object implements Iterator<CurvePoint>
This class implements a linear curve. Linear curves have all points in ascending X order and have no duplicate X values. The curve is contained as a doubly-linked list.

A number of simple curve manipulations and calculation methods are provided.

The getY(double) method will return a Y-value for any given X-value. Value of X that are lower than the lowest defined point return the Y-value from the lowest X-value. Similaryly values of X greater than the higest defined point return the Y-value from the highest X-value. For X-values that match a point with the same X-value the corresponding Y-value is returned. Otherwise the method calculates a linear interpolation between the two surronding points.

Warning, the iterator methods in this class are not reentrant.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct a curve with no points
    Curve​(double y)
    Construct a curve with a single point at x=0
    Curve​(double x, double y)
    Construct a single point
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add​(Curve curve, double shift, double factor)
     
    cai​(int width, int horizon)
    Return a curve that having values that are the current annual increment of this curve.
    copy​(double factor)
     
    int
     
    delta​(double offset)
    Return a curve that shows the difference from an offset.
    void
    divide​(Curve curve, double shift, double factor)
     
    boolean
    equals​(Object o)
     
    double
    getXatY​(double y)
    Get the first X value for a specified value of Y
    double
    getY​(double x)
    Get the Y value at the specified value of X
    boolean
     
    insert​(double x, double y)
    Insert a point in to the curve in sorted order.
    boolean
    isZero​(double tolerance)
     
     
    mai​(int width, int horizon)
    Return a curve that having values that are the mean annual increment of this curve.
    double
    Get the maximum X value
    double
    Get the maximum Y value
    double
    Get the minimum X value
    double
    Get the minimum Y value
    void
    multiply​(Curve curve, double shift, double factor)
     
     
    operable​(BitSet bits)
     
    void
    remainder​(Curve curve, double shift, double factor)
     
    void
     
    void
    shiftX​(double value)
     
    static int
    thin​(double[] x, double[] y, int n, double tolerance)
    Douglas Peucker recursive in place line thinning
     
    trim​(double beginLimit, double endLimit)
    Return a curve that will trim this curve o exclude values before and after the specified limits.
    truncate​(double limit)
    Return a curve that will flat-line the this curve at a given value along the entire length of the curve.
    truncate​(double limit, boolean fromEnd)
    Return a curve that will flat-line the this curve at a given value, either at the start or end of the curve depending on the setting of the fromEnd parameter.
    void
    visit​(Curve curve, double shift, double factor, Curve.Visitor visitor)
    Visit this curve with a Curve.Visitor method.
    weedcopy​(double tolerance)
    Thin a copy of a line to a given tolerance, leaving the original untouched.
    double
    ytp()
    Return the age of the highest point on the curve
    static Curve
    Return a zero value curve

    Methods inherited from class java.lang.Object

    getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.util.Iterator

    forEachRemaining
  • Constructor Details

    • Curve

      public Curve()
      Construct a curve with no points
    • Curve

      public Curve(double y)
      Construct a curve with a single point at x=0
    • Curve

      public Curve(double x, double y)
      Construct a single point
  • Method Details

    • ytp

      public double ytp()
      Return the age of the highest point on the curve
    • mai

      public Curve mai(int width, int horizon)
      Return a curve that having values that are the mean annual increment of this curve.
    • cai

      public Curve cai(int width, int horizon)
      Return a curve that having values that are the current annual increment of this curve.
    • delta

      public Curve delta(double offset)
      Return a curve that shows the difference from an offset.
    • trim

      public Curve trim(double beginLimit, double endLimit)
      Return a curve that will trim this curve o exclude values before and after the specified limits.
      Parameters:
      beginLimit - the X-value before which the curve should be trimmed
      endLimit - the X-value after which the curve should be trimmed
    • truncate

      public Curve truncate(double limit, boolean fromEnd)
      Return a curve that will flat-line the this curve at a given value, either at the start or end of the curve depending on the setting of the fromEnd parameter.
      Parameters:
      limit - the Y-value where the curve flattening should begin
      fromEnd - if true then flatten the end of the curve after reaching the last value of limit. If false then flatten the beginning of the curve up to the point where the first limit value is encountered.
    • truncate

      public Curve truncate(double limit)
      Return a curve that will flat-line the this curve at a given value along the entire length of the curve.
      Parameters:
      limit - the Y-value where the curve flattening should begin
    • insert

      public Curve insert(double x, double y)
      Insert a point in to the curve in sorted order.
    • visit

      public void visit(Curve curve, double shift, double factor, Curve.Visitor visitor)
      Visit this curve with a Curve.Visitor method.
    • add

      public void add(Curve curve, double shift, double factor)
    • multiply

      public void multiply(Curve curve, double shift, double factor)
    • divide

      public void divide(Curve curve, double shift, double factor)
    • remainder

      public void remainder(Curve curve, double shift, double factor)
    • copy

      public final Curve copy(double factor)
    • minX

      public double minX()
      Get the minimum X value
    • maxX

      public double maxX()
      Get the maximum X value
    • minY

      public double minY()
      Get the minimum Y value
    • maxY

      public double maxY()
      Get the maximum Y value
    • getY

      public double getY(double x)
      Get the Y value at the specified value of X
    • getXatY

      public double getXatY(double y)
      Get the first X value for a specified value of Y
    • shiftX

      public final void shiftX(double value)
    • isZero

      public boolean isZero(double tolerance)
    • count

      public int count()
    • weedcopy

      public Curve weedcopy(double tolerance)
      Thin a copy of a line to a given tolerance, leaving the original untouched.
    • thin

      public static int thin(double[] x, double[] y, int n, double tolerance)
      Douglas Peucker recursive in place line thinning
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • iterator

      public final Iterator<CurvePoint> iterator()
    • hasNext

      public final boolean hasNext()
      Specified by:
      hasNext in interface Iterator<CurvePoint>
    • remove

      public void remove()
      Specified by:
      remove in interface Iterator<CurvePoint>
    • next

      public CurvePoint next()
      Specified by:
      next in interface Iterator<CurvePoint>
    • zero

      public static Curve zero()
      Return a zero value curve
    • operable

      public Curve operable(BitSet bits)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object