Package com.dkt.graphics.elements
Class GPointArray
java.lang.Object
com.dkt.graphics.elements.GraphicE
com.dkt.graphics.elements.GFillableE
com.dkt.graphics.elements.GMultiPoint
com.dkt.graphics.elements.GPointArray
- Author:
- Federico Vera <[email protected]>
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionGenerates a new emptyGPointArrayGPointArray(int initial) GPointArray(int[] xs, int[] ys) GPointArray(int[] xs, int[] ys, int cs) GPointArray(GPoint[] points) GPointArray(GPoint[] points, int cs) Copy constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidappend(GPointArray arr) Appends all the point to this array, regardless if they are already containedclone()closestPoint(int x, int y) Retrieves a newGPointrepresenting the coordinates of the closest point in this arrayRetrieves a newGPointrepresenting the coordinates of the closest point in this arrayvoiddraw(Graphics2D g) Draws the component on the given graphicsbooleanRetrievesGRectanglethat contains all the points in this arrayinthashCode()higherThan(GPoint p) Retrieves a newGPointArrayrepresenting all the points that are abovep.
Please note that this is done considering the Y axis, graphically it means the higher if and only if you are inverting the Y axisRetrieves a copy of the highest point in this array at the momentRetrieves a newGPointArraycontaining all the points that are contained both in this array and in theGCirclepassed as an argumentRetrieves a newGPointArraycontaining all the points that are contained both in this array and in theGLinepassed as an argumentintersection(GPointArray array) Retrieves a newGPointArraycontaining all the points that are both in this array and in the one passed as an argumentRetrieves a newGPointArraycontaining all the points that are contained both in this array and in theGRectanglepassed as an argumentRetrieves a copy of the leftmost point in this array at the momentRetrieves a newGPointArrayrepresenting all the points that are located to the left ofp.Retrieves a newGPointArrayrepresenting all the points that are belowp.
Please note that this is done considering the Y axis, graphically it means the lower if and only if you are inverting the Y axisRetrieves a copy of the lowest point in this array at the momentpointsInRadius(int x, int y, double r) Retrieves a newGPointArraywith all the points that are contained in the circle with center in(x, y)and radiusr.pointsInRadius(GPoint p, double r) Retrieves a newGPointArraywith all the points that are contained in the circle with centerpand radiusr.voidremoveAll(GPointArray arr) Removes all the points that are contained both in this array and in the array passed as an argumentvoidRemoves ALL duplicate entries in the array.Retrieves a copy of the rightmost point in this array at the momentRetrieves a newGPointArrayrepresenting all the points that are located to the right ofp.voidsetCrossSize(int cs) Changes the cross size.
We treat points as crosses on the canvas, this method changes the size of that cross.
Note: The default value is 0voidsortByX()Sorts all the points in this array by it'sXvalue, and breaks ties with theYvaluevoidsortByY()Sorts all the points in this array by it'sYvalue, and breaks ties with theXvalueMethods inherited from class com.dkt.graphics.elements.GMultiPoint
append, append, appendNR, clear, ensureCapacity, getPointAt, getPoints, getShape, indexOf, indexOf, indexOf, indexOf, isEmpty, iterator, remove, remove, remove, size, traslate, trimToSizeMethods inherited from class com.dkt.graphics.elements.GFillableE
fill, getFillPaint, setFill, setFillPaintMethods inherited from class com.dkt.graphics.elements.GraphicE
getPaint, getStroke, setPaint, setStrokeMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
GPointArray
Copy constructor- Parameters:
e-GPointArrayto copy- Throws:
IllegalArgumentException- ifeisnull
-
GPointArray
- Parameters:
points-GPointarray containing all the points- Throws:
IllegalArgumentException- if the array isnull
-
GPointArray
- Parameters:
points-GPointarray containing all the pointscs- cross size- Throws:
IllegalArgumentException- if the array isnull
-
GPointArray
public GPointArray()Generates a new emptyGPointArray -
GPointArray
public GPointArray(int initial) - Parameters:
initial- initial reserved size- Throws:
NegativeArraySizeException- if the size is less than zero
-
GPointArray
public GPointArray(int[] xs, int[] ys) - Parameters:
xs- array containing all the x coordinatesys- array containing all the y coordinates- Throws:
IllegalArgumentException- if either array isnullInvalidArgumentException- if the array size doesn't match
-
GPointArray
public GPointArray(int[] xs, int[] ys, int cs) - Parameters:
xs- array containing all the x coordinatesys- array containing all the y coordinatescs- the cross size of the point- Throws:
IllegalArgumentException- if either array isnullInvalidArgumentException- if the array size doesn't match
-
-
Method Details
-
setCrossSize
public void setCrossSize(int cs) Changes the cross size.
We treat points as crosses on the canvas, this method changes the size of that cross.
Note: The default value is 0- Parameters:
cs- new cross size
-
pointsInRadius
Retrieves a newGPointArraywith all the points that are contained in the circle with centerpand radiusr.- Parameters:
p-GPointof the centerr- radius- Returns:
- a new
GPointArraywith the points of the intersection - Throws:
IllegalArgumentException- ifpisnull
-
pointsInRadius
Retrieves a newGPointArraywith all the points that are contained in the circle with center in(x, y)and radiusr.- Parameters:
x- X coordinate of the centery- Y coordinate of the centerr- radius- Returns:
- a new
GPointArraywith the points of the intersection
-
closestPoint
Retrieves a newGPointrepresenting the coordinates of the closest point in this array- Parameters:
p-GPointthat will be used to compare- Returns:
- a new
GPointrepresenting the closest top - Throws:
IllegalArgumentException- ifpisnull
-
closestPoint
Retrieves a newGPointrepresenting the coordinates of the closest point in this array- Parameters:
x- X coordinate of the pointy- Y coordinate of the point- Returns:
- a new
GPointrepresenting the closest to(x, y)ornullif none is found.
-
highestPoint
Retrieves a copy of the highest point in this array at the moment- Returns:
- highest point
-
lowestPoint
Retrieves a copy of the lowest point in this array at the moment- Returns:
- lowest point
-
leftmostPoint
Retrieves a copy of the leftmost point in this array at the moment- Returns:
- leftmost point or
nullif none is found.
-
rightmostPoint
Retrieves a copy of the rightmost point in this array at the moment- Returns:
- rightmost point or
nullif none is found.
-
getBounds
RetrievesGRectanglethat contains all the points in this array- Returns:
- rectangle containing all the points
-
higherThan
Retrieves a newGPointArrayrepresenting all the points that are abovep.
Please note that this is done considering the Y axis, graphically it means the higher if and only if you are inverting the Y axis- Parameters:
p-GPointthat will be used to compare- Returns:
GPointArraywith all the higher points- Throws:
IllegalArgumentException- ifpisnull
-
lowerThan
Retrieves a newGPointArrayrepresenting all the points that are belowp.
Please note that this is done considering the Y axis, graphically it means the lower if and only if you are inverting the Y axis- Parameters:
p-GPointthat will be used to compare- Returns:
GPointArraywith all the lower points- Throws:
IllegalArgumentException- ifpisnull
-
leftThan
Retrieves a newGPointArrayrepresenting all the points that are located to the left ofp.- Parameters:
p-GPointthat will be used to compare- Returns:
GPointArraywith all the left points- Throws:
IllegalArgumentException- ifpisnull
-
rightThan
Retrieves a newGPointArrayrepresenting all the points that are located to the right ofp.- Parameters:
p-GPointthat will be used to compare- Returns:
GPointArraywith all the right points- Throws:
IllegalArgumentException- ifpisnull
-
removeAll
Removes all the points that are contained both in this array and in the array passed as an argument- Parameters:
arr- points to remove- Throws:
IllegalArgumentException- ifarrayisnull
-
append
Appends all the point to this array, regardless if they are already contained- Parameters:
arr- points to add- Throws:
IllegalArgumentException- ifarrayisnull
-
intersection
Retrieves a newGPointArraycontaining all the points that are both in this array and in the one passed as an argument- Parameters:
array- points to intersect- Returns:
- a new
GPointArraywith all the points of the intersection - Throws:
IllegalArgumentException- ifarrayisnull
-
intersection
Retrieves a newGPointArraycontaining all the points that are contained both in this array and in theGRectanglepassed as an argument- Parameters:
r- rectangle to intersect- Returns:
- a new
GPointArraywith all the points of the intersection - Throws:
IllegalArgumentException- ifrisnull
-
intersection
Retrieves a newGPointArraycontaining all the points that are contained both in this array and in theGLinepassed as an argument- Parameters:
l- the line to intersect- Returns:
- a new
GPointArraywith all the points of the intersection - Throws:
IllegalArgumentException- iflisnull
-
intersection
Retrieves a newGPointArraycontaining all the points that are contained both in this array and in theGCirclepassed as an argument- Parameters:
c- the circle to intersect- Returns:
- a new
GPointArraywith all the points of the intersection - Throws:
IllegalArgumentException- ifcisnull
-
sortByX
public void sortByX()Sorts all the points in this array by it'sXvalue, and breaks ties with theYvalue- Overrides:
sortByXin classGMultiPoint
-
sortByY
public void sortByY()Sorts all the points in this array by it'sYvalue, and breaks ties with theXvalue -
removeDuplicates
public void removeDuplicates()Removes ALL duplicate entries in the array. -
draw
Description copied from class:GraphicEDraws the component on the given graphics -
clone
- Specified by:
clonein classGFillableE
-
hashCode
public int hashCode()- Overrides:
hashCodein classGMultiPoint
-
equals
- Overrides:
equalsin classGMultiPoint
-