Package org.eclipse.draw2d.geometry
Class PointList
java.lang.Object
org.eclipse.draw2d.geometry.PointList
- All Implemented Interfaces:
- Serializable,- Translatable
Represents a List of Points. This class is used for building an
 
int[]. The array is internal, and is constructed and queried by
 the client using Points. SWT uses integer arrays when painting
 polylines and polygons.- See Also:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidAppends all of the given points to this PointList.voidaddPoint(int x, int y) Adds the input point values to this PointList.voidAdds Point p to this PointList.Returns the smallest Rectangle which contains all Points.getCopy()Creates a copyReturns the first Point in the list.Returns the last point in the list.Returns the midpoint of the list of Points.getPoint(int index) Returns the Point in the list at the specified index.Copies the x and y values at given index into a specified Point.voidinsertPoint(Point p, int index) Inserts a given point at a specified index.booleanDetermines whether any of the line segments represented by this PointList intersect the given Rectangle.voidperformScale(double factor) Scales this object by the scale factor.voidperformTranslate(int dx, int dy) Translates this object horizontally bydxand vertically bydy.booleanpolygonContainsPoint(int x, int y) booleanpolylineContainsPoint(int x, int y, int tolerance) voidRemoves all the points stored by this list.removePoint(int index) Removes the point at the specified index from the PointList, and returns it.voidreverse()Reverses the order of the points in the list.voidOverwrites a point at a given index in the list with the specified Point.voidsetSize(int newSize) Sets the size of this PointList.intsize()Returns the number of points in this PointList.int[]Returns the contents of this PointList as an integer array.voidtranslate(int x, int y) Moves the origin (0,0) of the coordinate system of all the points to the Point (x,y).final voidMoves the origin (0,0) of the coordinate system of all the points to the Point pt.voidTransposes all x and y values.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.eclipse.draw2d.geometry.TranslatableperformTranslate, performTranslate, performTranslate
- 
Constructor Details- 
PointListpublic PointList()Constructs an empty PointList.- Since:
- 2.0
 
- 
PointListpublic PointList(int[] points) Constructs a PointList with the given points.- Parameters:
- points- int array where two consecutive ints form the coordinates of a point
- Since:
- 3.1
 
- 
PointListpublic PointList(int size) Constructs a PointList with initial capacity size, but no points.- Parameters:
- size- Number of points to hold.
- Since:
- 2.0
 
 
- 
- 
Method Details- 
addAllAppends all of the given points to this PointList.- Parameters:
- source- the source pointlist
 
- 
addPointAdds Point p to this PointList.- Parameters:
- p- the point to be added
- Since:
- 2.0
- See Also:
 
- 
addPointpublic void addPoint(int x, int y) Adds the input point values to this PointList.- Parameters:
- x- X value of a point to add
- y- Y value of a point to add
- Since:
- 2.0
 
- 
getBoundsReturns the smallest Rectangle which contains all Points.- Returns:
- The smallest Rectangle which contains all Points.
- Since:
- 2.0
 
- 
getCopyCreates a copy- Returns:
- PointList A copy of this PointList
 
- 
getFirstPointReturns the first Point in the list.- Returns:
- The first point in the list.
- Throws:
- IndexOutOfBoundsException- if the list is empty
- Since:
- 2.0
 
- 
getLastPointReturns the last point in the list.- Returns:
- The last Point in the list
- Throws:
- IndexOutOfBoundsException- if the list is empty
- Since:
- 2.0
 
- 
getMidpointReturns the midpoint of the list of Points. The midpoint is the median of the List, unless there are 2 medians (size is even), then the middle of the medians is returned.- Returns:
- The midpoint
- Throws:
- IndexOutOfBoundsException- if the list is empty
 
- 
getPointReturns the Point in the list at the specified index.- Parameters:
- index- Index of the desired Point
- Returns:
- The requested Point
- Throws:
- IndexOutOfBoundsException- If the specified index is out of range
- Since:
- 2.0
 
- 
getPointCopies the x and y values at given index into a specified Point. This method exists to avoid the creation of a newPoint.- Parameters:
- p- The Point which will be set with the <x, y> values
- index- The index being requested
- Returns:
- The parameter pis returned for convenience
- Since:
- 2.0
- See Also:
 
- 
insertPointInserts a given point at a specified index.- Parameters:
- p- Point to be inserted.
- index- Position where the point is to be inserted.
- Throws:
- IndexOutOfBoundsException- if the index is invalid
- Since:
- 2.0
- See Also:
 
- 
intersectsDetermines whether any of the line segments represented by this PointList intersect the given Rectangle. If a segment touches the given rectangle, that's considered intersection.- Parameters:
- r- the rectangle
- Returns:
- trueif the given rectangle intersects any of the line segments represented by this PointList
- Since:
- 3.1
 
- 
performScalepublic void performScale(double factor) Description copied from interface:TranslatableScales this object by the scale factor.- Specified by:
- performScalein interface- Translatable
- Parameters:
- factor- The scale factor
- See Also:
 
- 
performTranslatepublic void performTranslate(int dx, int dy) Description copied from interface:TranslatableTranslates this object horizontally bydxand vertically bydy.- Specified by:
- performTranslatein interface- Translatable
- Parameters:
- dx- The amount to translate horizontally
- dy- The amount to translate vertically
- See Also:
 
- 
removeAllPointspublic void removeAllPoints()Removes all the points stored by this list. Resets all the properties based on the point information.- Since:
- 2.0
 
- 
removePointRemoves the point at the specified index from the PointList, and returns it.- Parameters:
- index- Index of the point to be removed.
- Returns:
- The point which has been removed
- Throws:
- IndexOutOfBoundsException- if the removal index is beyond the list capacity
- Since:
- 2.0
- See Also:
 
- 
reversepublic void reverse()Reverses the order of the points in the list.- Since:
- 3.2
 
- 
setPointOverwrites a point at a given index in the list with the specified Point.- Parameters:
- pt- Point which is to be stored at the index.
- index- Index where the given point is to be stored.
- Since:
- 2.0
 
- 
setSizepublic void setSize(int newSize) Sets the size of this PointList.- Parameters:
- newSize- the new size
 
- 
sizepublic int size()Returns the number of points in this PointList.- Returns:
- The number of points
- Since:
- 2.0
 
- 
toIntArraypublic int[] toIntArray()Returns the contents of this PointList as an integer array. The returned array is by reference. Any changes made to the array will also be changing the original PointList.- Returns:
- the integer array of points by reference
- Since:
- 2.0
 
- 
translateMoves the origin (0,0) of the coordinate system of all the points to the Point pt. This updates the position of all the points in this PointList.- Parameters:
- pt- Position by which all the points will be shifted.
- Since:
- 2.0
- See Also:
 
- 
translatepublic void translate(int x, int y) Moves the origin (0,0) of the coordinate system of all the points to the Point (x,y). This updates the position of all the points in this PointList.- Parameters:
- x- Amount by which all the points will be shifted on the X axis.
- y- Amount by which all the points will be shifted on the Y axis.
- Since:
- 2.0
- See Also:
 
- 
transposepublic void transpose()Transposes all x and y values. Useful for orientation changes.- Since:
- 3.2
 
- 
polygonContainsPointpublic boolean polygonContainsPoint(int x, int y) - Parameters:
- x- - X coordinate of the point
- y- - Y coordinate of the point
- Returns:
- true if specified point belongs to the polygon drawn using this PointList
- Since:
- 3.5
- See Also:
 
- 
polylineContainsPointpublic boolean polylineContainsPoint(int x, int y, int tolerance) - Parameters:
- x- - X coordinate of the point
- y- - Y coordinate of the point
- tolerance- - allowed distance between point and polyline segment
- Returns:
- true if the least distance between specified point and polyline drawn using this PointList is less then specified tolerance
- Since:
- 3.5
- See Also:
 
 
-