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
ConstructorDescriptionGenerates a new emptyGPointArray
GPointArray
(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 TypeMethodDescriptionvoid
append
(GPointArray arr) Appends all the point to this array, regardless if they are already containedclone()
closestPoint
(int x, int y) Retrieves a newGPoint
representing the coordinates of the closest point in this arrayRetrieves a newGPoint
representing the coordinates of the closest point in this arrayvoid
draw
(Graphics2D g) Draws the component on the given graphicsboolean
RetrievesGRectangle
that contains all the points in this arrayint
hashCode()
higherThan
(GPoint p) Retrieves a newGPointArray
representing 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 newGPointArray
containing all the points that are contained both in this array and in theGCircle
passed as an argumentRetrieves a newGPointArray
containing all the points that are contained both in this array and in theGLine
passed as an argumentintersection
(GPointArray array) Retrieves a newGPointArray
containing all the points that are both in this array and in the one passed as an argumentRetrieves a newGPointArray
containing all the points that are contained both in this array and in theGRectangle
passed as an argumentRetrieves a copy of the leftmost point in this array at the momentRetrieves a newGPointArray
representing all the points that are located to the left ofp
.Retrieves a newGPointArray
representing 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 newGPointArray
with all the points that are contained in the circle with center in(x, y)
and radiusr
.pointsInRadius
(GPoint p, double r) Retrieves a newGPointArray
with all the points that are contained in the circle with centerp
and radiusr
.void
removeAll
(GPointArray arr) Removes all the points that are contained both in this array and in the array passed as an argumentvoid
Removes ALL duplicate entries in the array.Retrieves a copy of the rightmost point in this array at the momentRetrieves a newGPointArray
representing all the points that are located to the right ofp
.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 0void
sortByX()
Sorts all the points in this array by it'sX
value, and breaks ties with theY
valuevoid
sortByY()
Sorts all the points in this array by it'sY
value, and breaks ties with theX
valueMethods 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, trimToSize
Methods inherited from class com.dkt.graphics.elements.GFillableE
fill, getFillPaint, setFill, setFillPaint
Methods inherited from class com.dkt.graphics.elements.GraphicE
getPaint, getStroke, setPaint, setStroke
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
GPointArray
Copy constructor- Parameters:
e
-GPointArray
to copy- Throws:
IllegalArgumentException
- ife
isnull
-
GPointArray
- Parameters:
points
-GPoint
array containing all the points- Throws:
IllegalArgumentException
- if the array isnull
-
GPointArray
- Parameters:
points
-GPoint
array 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 isnull
InvalidArgumentException
- 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 isnull
InvalidArgumentException
- 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 newGPointArray
with all the points that are contained in the circle with centerp
and radiusr
.- Parameters:
p
-GPoint
of the centerr
- radius- Returns:
- a new
GPointArray
with the points of the intersection - Throws:
IllegalArgumentException
- ifp
isnull
-
pointsInRadius
Retrieves a newGPointArray
with 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
GPointArray
with the points of the intersection
-
closestPoint
Retrieves a newGPoint
representing the coordinates of the closest point in this array- Parameters:
p
-GPoint
that will be used to compare- Returns:
- a new
GPoint
representing the closest top
- Throws:
IllegalArgumentException
- ifp
isnull
-
closestPoint
Retrieves a newGPoint
representing the coordinates of the closest point in this array- Parameters:
x
- X coordinate of the pointy
- Y coordinate of the point- Returns:
- a new
GPoint
representing the closest to(x, y)
ornull
if 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
null
if none is found.
-
rightmostPoint
Retrieves a copy of the rightmost point in this array at the moment- Returns:
- rightmost point or
null
if none is found.
-
getBounds
RetrievesGRectangle
that contains all the points in this array- Returns:
- rectangle containing all the points
-
higherThan
Retrieves a newGPointArray
representing 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
-GPoint
that will be used to compare- Returns:
GPointArray
with all the higher points- Throws:
IllegalArgumentException
- ifp
isnull
-
lowerThan
Retrieves a newGPointArray
representing 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
-GPoint
that will be used to compare- Returns:
GPointArray
with all the lower points- Throws:
IllegalArgumentException
- ifp
isnull
-
leftThan
Retrieves a newGPointArray
representing all the points that are located to the left ofp
.- Parameters:
p
-GPoint
that will be used to compare- Returns:
GPointArray
with all the left points- Throws:
IllegalArgumentException
- ifp
isnull
-
rightThan
Retrieves a newGPointArray
representing all the points that are located to the right ofp
.- Parameters:
p
-GPoint
that will be used to compare- Returns:
GPointArray
with all the right points- Throws:
IllegalArgumentException
- ifp
isnull
-
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
- ifarray
isnull
-
append
Appends all the point to this array, regardless if they are already contained- Parameters:
arr
- points to add- Throws:
IllegalArgumentException
- ifarray
isnull
-
intersection
Retrieves a newGPointArray
containing 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
GPointArray
with all the points of the intersection - Throws:
IllegalArgumentException
- ifarray
isnull
-
intersection
Retrieves a newGPointArray
containing all the points that are contained both in this array and in theGRectangle
passed as an argument- Parameters:
r
- rectangle to intersect- Returns:
- a new
GPointArray
with all the points of the intersection - Throws:
IllegalArgumentException
- ifr
isnull
-
intersection
Retrieves a newGPointArray
containing all the points that are contained both in this array and in theGLine
passed as an argument- Parameters:
l
- the line to intersect- Returns:
- a new
GPointArray
with all the points of the intersection - Throws:
IllegalArgumentException
- ifl
isnull
-
intersection
Retrieves a newGPointArray
containing all the points that are contained both in this array and in theGCircle
passed as an argument- Parameters:
c
- the circle to intersect- Returns:
- a new
GPointArray
with all the points of the intersection - Throws:
IllegalArgumentException
- ifc
isnull
-
sortByX
public void sortByX()Sorts all the points in this array by it'sX
value, and breaks ties with theY
value- Overrides:
sortByX
in classGMultiPoint
-
sortByY
public void sortByY()Sorts all the points in this array by it'sY
value, and breaks ties with theX
value -
removeDuplicates
public void removeDuplicates()Removes ALL duplicate entries in the array. -
draw
Description copied from class:GraphicE
Draws the component on the given graphics -
clone
- Specified by:
clone
in classGFillableE
-
hashCode
public int hashCode()- Overrides:
hashCode
in classGMultiPoint
-
equals
- Overrides:
equals
in classGMultiPoint
-