uk.ac.starlink.diva.geom
Class InterpolatedCurve2D

java.lang.Object
  extended by uk.ac.starlink.diva.geom.InterpolatedCurve2D
All Implemented Interfaces:
Shape

public class InterpolatedCurve2D
extends Object
implements Shape

A curve generated by an interpolator between a series of vertices.

Version:
$Id$
Author:
Peter W. Draper

Constructor Summary
InterpolatedCurve2D(InterpolatedCurve2D in)
          Copy constructor.
InterpolatedCurve2D(Interpolator interpolator)
          Create an empty instance.
 
Method Summary
static double[] applySortIndex(double[] a, int[] remap, boolean incr)
          Sort an array using the index produced by the insertionSort(double[]) method.
 void calculate()
          Evaluate the interpolation.
 boolean contains(double x, double y)
           
 boolean contains(double x, double y, double w, double h)
           
 boolean contains(Point2D p)
           
 boolean contains(Rectangle2D r)
           
protected  void extendXCoords(double newx)
          Create extra X coordinates for interpolation points.
 Rectangle getBounds()
           
 Rectangle2D getBounds2D()
          Get the floating-point bounds.
 int getCoordCount()
          Get the number of coordinates.
 Interpolator getInterpolator()
          Get the interpolator.
 PathIterator getPathIterator(AffineTransform at)
           
 PathIterator getPathIterator(AffineTransform at, double flatness)
           
 int getVertexCount()
          Get the number of vertices.
 double getXCoord(int index)
          Get an interpolated X-coordinate
 double[] getXCoords()
          Get all interpolated X-coordinates.
 double getXVertex(int index)
          Get the X-coordinate of a vertex.
 double[] getXVertices()
          Get all the X vertices.
 double getYCoord(int index)
          Get a interpolated Y-coordinate.
 double[] getYCoords()
          Get all interpolated Y-coordinates.
 double getYVertex(int index)
          Get the Y-coordinate of a vertex.
 double[] getYVertices()
          Get all the Y vertices.
static int[] insertionSort(double[] a)
          Creates an index that sorts a double precision array.
 boolean intersects(double x, double y, double w, double h)
           
 boolean intersects(Rectangle2D r)
           
 boolean isFull()
          Return if the Interpolator is full, i.e.
 boolean isIncreasing()
          Find out if X coordinates are increasing or decreasing.
 void lineTo(double x, double y)
          Add a new vertex at the end of the curve.
 void moveTo(double x, double y)
          Move the start point of the vertex to the given position.
 int[] orderVertices()
          Make sure the vertices are monotonic in some sense.
 void setInterpolator(Interpolator interpolator)
          Set the interpolator.
 void setVertex(int index, double xValue, double yValue)
          Set the coordinates of a vertex.
 void setXVertex(int index, double value)
          Set the X-coordinate of a vertex.
 void setYVertex(int index, double value)
          Set the Y-coordinate of a vertex.
 String toString()
           
 void transform(AffineTransform at)
          Transform the vertex positions.
 void translate(double dx, double dy)
          Translate the vertex positions.
 void translateVertex(int index, double dx, double dy, boolean recalc)
          Translate the coordinates of a vertex.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InterpolatedCurve2D

public InterpolatedCurve2D(Interpolator interpolator)
Create an empty instance.


InterpolatedCurve2D

public InterpolatedCurve2D(InterpolatedCurve2D in)
Copy constructor.

Method Detail

setInterpolator

public void setInterpolator(Interpolator interpolator)
Set the interpolator.


extendXCoords

protected void extendXCoords(double newx)
Create extra X coordinates for interpolation points.


getInterpolator

public Interpolator getInterpolator()
Get the interpolator.


contains

public boolean contains(double x,
                        double y)
Specified by:
contains in interface Shape

contains

public boolean contains(Point2D p)
Specified by:
contains in interface Shape

contains

public boolean contains(Rectangle2D r)
Specified by:
contains in interface Shape

contains

public boolean contains(double x,
                        double y,
                        double w,
                        double h)
Specified by:
contains in interface Shape

getPathIterator

public PathIterator getPathIterator(AffineTransform at,
                                    double flatness)
Specified by:
getPathIterator in interface Shape

getPathIterator

public PathIterator getPathIterator(AffineTransform at)
Specified by:
getPathIterator in interface Shape

calculate

public void calculate()
Evaluate the interpolation.


orderVertices

public int[] orderVertices()
Make sure the vertices are monotonic in some sense. Also reinterpolates to refresh all positions. A mapping from old to new indices is returned.


isIncreasing

public boolean isIncreasing()
Find out if X coordinates are increasing or decreasing.


getVertexCount

public int getVertexCount()
Get the number of vertices.


getCoordCount

public int getCoordCount()
Get the number of coordinates.


intersects

public boolean intersects(Rectangle2D r)
Specified by:
intersects in interface Shape

intersects

public boolean intersects(double x,
                          double y,
                          double w,
                          double h)
Specified by:
intersects in interface Shape

lineTo

public void lineTo(double x,
                   double y)
Add a new vertex at the end of the curve. This should also generate the necessary interpolation coordinates.


moveTo

public void moveTo(double x,
                   double y)
Move the start point of the vertex to the given position. Can only be done when curve is first created, or has been reset.

Throws:
UnsupportedOperationException - If this isn't the first vertex.

toString

public String toString()
Overrides:
toString in class Object

getBounds2D

public Rectangle2D getBounds2D()
Get the floating-point bounds. As approximate as the drawn interpolated curve.

Specified by:
getBounds2D in interface Shape

getBounds

public Rectangle getBounds()
Specified by:
getBounds in interface Shape

getXCoords

public double[] getXCoords()
Get all interpolated X-coordinates.


getYCoords

public double[] getYCoords()
Get all interpolated Y-coordinates.


getXCoord

public double getXCoord(int index)
Get an interpolated X-coordinate


getYCoord

public double getYCoord(int index)
Get a interpolated Y-coordinate.


isFull

public boolean isFull()
Return if the Interpolator is full, i.e. will ignore or refuse any further vectices.


getXVertices

public double[] getXVertices()
Get all the X vertices.


getYVertices

public double[] getYVertices()
Get all the Y vertices.


getXVertex

public double getXVertex(int index)
Get the X-coordinate of a vertex.


getYVertex

public double getYVertex(int index)
Get the Y-coordinate of a vertex.


setXVertex

public void setXVertex(int index,
                       double value)
Set the X-coordinate of a vertex.


setYVertex

public void setYVertex(int index,
                       double value)
Set the Y-coordinate of a vertex.


setVertex

public void setVertex(int index,
                      double xValue,
                      double yValue)
Set the coordinates of a vertex.


translateVertex

public void translateVertex(int index,
                            double dx,
                            double dy,
                            boolean recalc)
Translate the coordinates of a vertex.

If recalc is false then a full re-calculation of the interpolation coordinates is not performed. This can be used to defer full re-calculations (if this or other vertices are to be modified almost immediately) but the user must call either orderVertices or setInterpolator (this can be with the same interpolator as is currently in use) to force an eventual re-calculation.

Translation of a vertex is contrained to not break the monotonic nature of X coordinates, so if an attempt to move past another vertex is made this will not be successful.


transform

public void transform(AffineTransform at)
Transform the vertex positions.


translate

public void translate(double dx,
                      double dy)
Translate the vertex positions.


insertionSort

public static int[] insertionSort(double[] a)
Creates an index that sorts a double precision array. On exit a is sorted. A reordering of associated arrays can be performed using the applySortIndex methods.


applySortIndex

public static double[] applySortIndex(double[] a,
                                      int[] remap,
                                      boolean incr)
Sort an array using the index produced by the insertionSort(double[]) method.



Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.