edu.umd.cs.piccolox.util
Class XYArray

java.lang.Object
  extended by edu.umd.cs.piccolox.util.XYArray
All Implemented Interfaces:
MutablePoints, Points, Cloneable

public class XYArray
extends Object
implements MutablePoints, Cloneable

Represents a sequence as points that's internally stored as a single array of point components.


Constructor Summary
XYArray()
          Constructs an empty XYArray.
XYArray(double[] points)
          Constructs an XYArray wrapping the given points.
XYArray(int n)
          Constructs an XYArray of the given size.
 
Method Summary
 void addPoint(int pos, double x, double y)
          Adds a point to the index provided.
 void addPoint(int pos, Point2D pt)
          Inserts the given point at the given index.
 void addPoints(int pos, Points pts)
          Inserts all the provided points at the given position.
 void addPoints(int index, Points newPoints, int start, int end)
          Adds a subsequence of the points provided at the given position.
 void appendPoints(Points pts)
          Adds the provided points to the end of the points.
 Object clone()
          Returns a clone of this XYArray ensuring a deep copy of coordinates is made.
static XYArray copyPoints(Points pts)
          Creates an XYArray representing the given points.
 Rectangle2D getBounds(Rectangle2D dst)
          Modifies dst to be the bounding box of the points represented by this XYArray.
 Point2D getPoint(int i, Point2D dst)
          Returns modified point representing the wrapped point at the given index.
 int getPointCount()
          Returns the number of points this XYArray represents.
 double getX(int i)
          Returns the x component of the point at the given index.
 double getY(int i)
          Returns the y component of the point at the given index.
static double[] initPoints(double[] points, int n, double[] old)
          Constructs an array of point coordinates for n points and copies the old values if provided.
 void removeAllPoints()
          Remove all points from this XYArray.
 void removePoints(int pos, int num)
          Remove a subsequence of points from this XYArray starting as pos.
 void setPoint(int i, double x, double y)
          Sets the coordinates of the point at the given index.
 void setPoint(int i, Point2D pt)
          Sets the coordinates of the point at the given index.
 void setX(int i, double x)
          Sets the x component of the point at the given index.
 void setY(int i, double y)
          Sets the y component of the point at the given index.
 void transformPoints(AffineTransform t)
          Applies the given transform to all points represented by this XYArray.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XYArray

public XYArray(double[] points)
Constructs an XYArray wrapping the given points.

Parameters:
points - array of coordinates defining the points

XYArray

public XYArray(int n)
Constructs an XYArray of the given size.

Parameters:
n - number of points XYArray should contain

XYArray

public XYArray()
Constructs an empty XYArray.

Method Detail

getPointCount

public int getPointCount()
Returns the number of points this XYArray represents.

Specified by:
getPointCount in interface Points
Returns:
number of points

getX

public double getX(int i)
Returns the x component of the point at the given index.

Specified by:
getX in interface Points
Parameters:
i - index of point
Returns:
x component of point at given index

getY

public double getY(int i)
Returns the y component of the point at the given index.

Specified by:
getY in interface Points
Parameters:
i - index of point
Returns:
y component of point at given index

getPoint

public Point2D getPoint(int i,
                        Point2D dst)
Returns modified point representing the wrapped point at the given index.

Specified by:
getPoint in interface Points
Parameters:
i - index of desired point
dst - point to be modified
Returns:
dst

setX

public void setX(int i,
                 double x)
Sets the x component of the point at the given index.

Parameters:
i - index of point to modify
x - new x component

setY

public void setY(int i,
                 double y)
Sets the y component of the point at the given index.

Parameters:
i - index of point to modify
y - new y component

setPoint

public void setPoint(int i,
                     double x,
                     double y)
Sets the coordinates of the point at the given index.

Specified by:
setPoint in interface MutablePoints
Parameters:
i - index of point to modify
x - new x component
y - new y component

setPoint

public void setPoint(int i,
                     Point2D pt)
Sets the coordinates of the point at the given index.

Parameters:
i - index of point to modify
pt - point from which coordinate is to be extracted

transformPoints

public void transformPoints(AffineTransform t)
Applies the given transform to all points represented by this XYArray.

Specified by:
transformPoints in interface MutablePoints
Parameters:
t - transform to apply

getBounds

public Rectangle2D getBounds(Rectangle2D dst)
Modifies dst to be the bounding box of the points represented by this XYArray.

Specified by:
getBounds in interface Points
Parameters:
dst - rectangle to be modified
Returns:
the bounding rectangle

initPoints

public static double[] initPoints(double[] points,
                                  int n,
                                  double[] old)
Constructs an array of point coordinates for n points and copies the old values if provided.

Parameters:
points - array to populate with point values, or null to generate a new array
n - number of points
old - old values to repopulate the array with, or null if not desired
Returns:
initialized points

addPoints

public void addPoints(int index,
                      Points newPoints,
                      int start,
                      int end)
Adds a subsequence of the points provided at the given position.

Parameters:
index - position at which the points should be inserted
newPoints - points from which to extract the subsequence of points
start - the start index within newPoints to start extracting points
end - the end index within newPoints to finish extracting points

addPoints

public void addPoints(int pos,
                      Points pts)
Inserts all the provided points at the given position.

Parameters:
pos - index at which to insert the points
pts - points to be inserted

appendPoints

public void appendPoints(Points pts)
Adds the provided points to the end of the points.

Parameters:
pts - points to be added

copyPoints

public static XYArray copyPoints(Points pts)
Creates an XYArray representing the given points.

Parameters:
pts - points to copy
Returns:
XYArray representing the points provided

addPoint

public void addPoint(int pos,
                     double x,
                     double y)
Adds a point to the index provided.

Specified by:
addPoint in interface MutablePoints
Parameters:
pos - index at which to add the point
x - x coordinate of new point
y - y coordinate of new point

addPoint

public void addPoint(int pos,
                     Point2D pt)
Inserts the given point at the given index.

Parameters:
pos - index at which to add the point
pt - point to be inserted *

removePoints

public void removePoints(int pos,
                         int num)
Remove a subsequence of points from this XYArray starting as pos.

Specified by:
removePoints in interface MutablePoints
Parameters:
pos - the position to start removing points
num - the number of points to remove

removeAllPoints

public void removeAllPoints()
Remove all points from this XYArray.


clone

public Object clone()
Returns a clone of this XYArray ensuring a deep copy of coordinates is made.

Overrides:
clone in class Object
Returns:
cloned XYArray


Copyright © 1995-2010 Piccolo2D. All Rights Reserved.