Class XYCurve

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  XYCurve.Itr
      Iterator for the curve. 2D, does not follow Java collections style.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected DoubleArray data
      X and Y positions
      protected java.lang.String labelx
      Label of X axis
      protected java.lang.String labely
      Label of Y axis
      protected double maxdx
      Drawing bounds for x
      protected double maxdy
      Drawing bounds for y
      protected double maxx
      Minimum and maximum for X axis
      protected double maxy
      Minimum and maximum for Y axis
      protected double mindx
      Drawing bounds for x
      protected double mindy
      Drawing bounds for y
      protected double minx
      Minimum and maximum for X axis
      protected double miny
      Minimum and maximum for Y axis
      protected static double THRESHOLD
      Simplification threshold
    • Constructor Summary

      Constructors 
      Constructor Description
      XYCurve()
      Constructor.
      XYCurve​(int size)
      Constructor with size estimate
      XYCurve​(XYCurve curve)
      Constructor, cloning an existing curve.
      XYCurve​(java.lang.String labelx, java.lang.String labely)
      Constructor with labels
      XYCurve​(java.lang.String labelx, java.lang.String labely, int size)
      Constructor with size estimate and labels.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(double x, double y)
      Add a coordinate pair, but don't simplify
      void addAndSimplify​(double x, double y)
      Add a coordinate pair, performing curve simplification if possible.
      static double areaUnderCurve​(XYCurve curve)
      Compute the area under curve for a curve monotonously increasing in X.
      java.lang.String getLabelx()
      Get label of x axis
      java.lang.String getLabely()
      Get label of y axis
      double getMaxdx()
      upper drawing bound on x axis.
      double getMaxdy()
      Upper drawing bound on y axis.
      double getMaxx()
      Maximum on x axis.
      double getMaxy()
      Maximum on y axis.
      double getMindx()
      Lower drawing bound on x axis.
      double getMindy()
      Lower drawing bound on y axis.
      double getMinx()
      Minimum on x axis.
      double getMiny()
      Minimum on y axis.
      double getX​(int off)
      Curve X value at given position
      double getY​(int off)
      Curve Y value at given position
      boolean isInDrawingBounds​(double x, double y)
      Checks if a point is inside the drawing bounds of this curve
      XYCurve.Itr iterator()
      Get an iterator for the curve.
      void rescale​(double sx, double sy)
      Rescale the graph.
      void setAxes​(double minx, double miny, double maxx, double maxy)
      Set the range of the plot.
      void setDrawingBounds​(double mindx, double mindy, double maxdx, double maxdy)
      Set the drawing bounds of the plot.
      int size()
      Size of curve.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • THRESHOLD

        protected static final double THRESHOLD
        Simplification threshold
        See Also:
        Constant Field Values
      • labelx

        protected java.lang.String labelx
        Label of X axis
      • labely

        protected java.lang.String labely
        Label of Y axis
      • minx

        protected double minx
        Minimum and maximum for X axis
      • maxx

        protected double maxx
        Minimum and maximum for X axis
      • miny

        protected double miny
        Minimum and maximum for Y axis
      • maxy

        protected double maxy
        Minimum and maximum for Y axis
      • mindx

        protected double mindx
        Drawing bounds for x
      • maxdx

        protected double maxdx
        Drawing bounds for x
      • mindy

        protected double mindy
        Drawing bounds for y
      • maxdy

        protected double maxdy
        Drawing bounds for y
    • Constructor Detail

      • XYCurve

        public XYCurve​(java.lang.String labelx,
                       java.lang.String labely)
        Constructor with labels
        Parameters:
        labelx - Label for X axis
        labely - Label for Y axis
      • XYCurve

        public XYCurve​(java.lang.String labelx,
                       java.lang.String labely,
                       int size)
        Constructor with size estimate and labels.
        Parameters:
        labelx - Label for X axis
        labely - Label for Y axis
        size - Estimated size (initial allocation size)
      • XYCurve

        public XYCurve()
        Constructor.
      • XYCurve

        public XYCurve​(int size)
        Constructor with size estimate
        Parameters:
        size - Estimated size (initial allocation size)
      • XYCurve

        public XYCurve​(XYCurve curve)
        Constructor, cloning an existing curve.
        Parameters:
        curve - Curve to clone.
    • Method Detail

      • add

        public void add​(double x,
                        double y)
        Add a coordinate pair, but don't simplify
        Parameters:
        x - X coordinate
        y - Y coordinate
      • addAndSimplify

        public void addAndSimplify​(double x,
                                   double y)
        Add a coordinate pair, performing curve simplification if possible.
        Parameters:
        x - X coordinate
        y - Y coordinate
      • getLabelx

        public java.lang.String getLabelx()
        Get label of x axis
        Returns:
        label of x axis
      • getLabely

        public java.lang.String getLabely()
        Get label of y axis
        Returns:
        label of y axis
      • getMinx

        public double getMinx()
        Minimum on x axis.
        Returns:
        Minimum on X
      • getMaxx

        public double getMaxx()
        Maximum on x axis.
        Returns:
        Maximum on X
      • getMiny

        public double getMiny()
        Minimum on y axis.
        Returns:
        Minimum on Y
      • getMaxy

        public double getMaxy()
        Maximum on y axis.
        Returns:
        Maximum on Y
      • getMindx

        public double getMindx()
        Lower drawing bound on x axis.
        Returns:
        lower drawing bound on X
      • getMaxdx

        public double getMaxdx()
        upper drawing bound on x axis.
        Returns:
        upper drawing bound on X
      • getMindy

        public double getMindy()
        Lower drawing bound on y axis.
        Returns:
        lower drawing bound on Y
      • getMaxdy

        public double getMaxdy()
        Upper drawing bound on y axis.
        Returns:
        upper drawing bound on Y
      • getX

        public double getX​(int off)
        Curve X value at given position
        Parameters:
        off - Offset
        Returns:
        X value
      • getY

        public double getY​(int off)
        Curve Y value at given position
        Parameters:
        off - Offset
        Returns:
        Y value
      • rescale

        public void rescale​(double sx,
                            double sy)
        Rescale the graph.
        Parameters:
        sx - Scaling factor for X axis
        sy - Scaling factor for Y axis
      • setAxes

        public void setAxes​(double minx,
                            double miny,
                            double maxx,
                            double maxy)
        Set the range of the plot.
        Parameters:
        minx - Minimum x
        miny - Minimum y
        maxx - Maximum x
        maxy - Maximum y
      • setDrawingBounds

        public void setDrawingBounds​(double mindx,
                                     double mindy,
                                     double maxdx,
                                     double maxdy)
        Set the drawing bounds of the plot.
        Parameters:
        mindx - lower drawing x
        mindy - lower drawing y
        maxdx - upper drawing x
        maxdy - upper drawing y
      • isInDrawingBounds

        public boolean isInDrawingBounds​(double x,
                                         double y)
        Checks if a point is inside the drawing bounds of this curve
        Parameters:
        x - X value
        y - Y value
        Returns:
        whether the point is in the drawing bounds
      • size

        public int size()
        Size of curve.
        Returns:
        curve length
      • iterator

        public XYCurve.Itr iterator()
        Get an iterator for the curve.

        Note: this is not a Java style iterator, since the only way to get positions is using "next" in Java style. Here, we can have two getters for current values!

        Instead, use this style of iteration:

         for(XYCurve.Itr it = curve.iterator(); it.valid(); it.advance()) {
           doSomethingWith(it.getX(), it.getY());
         }
         
        Returns:
        Iterator
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • areaUnderCurve

        public static double areaUnderCurve​(XYCurve curve)
        Compute the area under curve for a curve monotonously increasing in X. You might need to relate this to the total area of the chart.
        Parameters:
        curve - Curve
        Returns:
        Area under curve.