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
-
- All Implemented Interfaces:
java.lang.Cloneable
,java.lang.Iterable<GPoint>
public class GPointArray extends GMultiPoint
-
-
Constructor Summary
Constructors Constructor Description GPointArray()
Generates 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)
GPointArray(GPointArray e)
Copy constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
append(GPointArray arr)
Appends all the point to this array, regardless if they are already containedGPointArray
clone()
GPoint
closestPoint(int x, int y)
Retrieves a newGPoint
representing the coordinates of the closest point in this arrayGPoint
closestPoint(GPoint p)
Retrieves a newGPoint
representing the coordinates of the closest point in this arrayvoid
draw(java.awt.Graphics2D g)
Draws the component on the given graphicsboolean
equals(java.lang.Object obj)
GRectangle
getBounds()
RetrievesGRectangle
that contains all of the points in this arrayint
hashCode()
GPointArray
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 axisGPoint
highestPoint()
Retrieves a copy of the highest point in this array at the momentGPointArray
intersection(GCircle c)
Retrieves a newGPointArray
containing all the points that are contained both in this array and in theGCircle
passed as an argumentGPointArray
intersection(GLine l)
Retrieves a newGPointArray
containing all the points that are contained both in this array and in theGLine
passed as an argumentGPointArray
intersection(GPointArray array)
Retrieves a newGPointArray
containing all the points that are both in this array and in the one passed as an argumentGPointArray
intersection(GRectangle r)
Retrieves a newGPointArray
containing all the points that are contained both in this array and in theGRectangle
passed as an argumentGPoint
leftmostPoint()
Retrieves a copy of the leftmost point in this array at the momentGPointArray
leftThan(GPoint p)
Retrieves a newGPointArray
representing all the points that are located to the left ofp
.GPointArray
lowerThan(GPoint p)
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 axisGPoint
lowestPoint()
Retrieves a copy of the lowest point in this array at the momentGPointArray
pointsInRadius(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 and radiusr
.GPointArray
pointsInRadius(GPoint p, double r)
Retrieves a newGPointArray
with all the points that are contained in the circle with centerp
and 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
removeDuplicates()
Removes ALL duplicate entries in the array.GPoint
rightmostPoint()
Retrieves a copy of the rightmost point in this array at the momentGPointArray
rightThan(GPoint p)
Retrieves 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
value-
Methods inherited from class com.dkt.graphics.elements.GFillableE
fill, getFillPaint, setFill, setFillPaint
-
Methods 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
-
-
-
-
Constructor Detail
-
GPointArray
public GPointArray(GPointArray e)
Copy constructor- Parameters:
e
-GPointArray
to copy- Throws:
java.lang.IllegalArgumentException
- ife
isnull
-
GPointArray
public GPointArray(GPoint[] points)
- Parameters:
points
-GPoint
array containing all the points- Throws:
java.lang.IllegalArgumentException
- if the array isnull
-
GPointArray
public GPointArray(GPoint[] points, int cs)
- Parameters:
points
-GPoint
array containing all the pointscs
- cross size- Throws:
java.lang.IllegalArgumentException
- if the array isnull
-
GPointArray
public GPointArray()
Generates a new emptyGPointArray
-
GPointArray
public GPointArray(int initial)
- Parameters:
initial
- initial reserved size- Throws:
java.lang.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:
java.lang.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:
java.lang.IllegalArgumentException
- if either array isnull
InvalidArgumentException
- if the array size doesn't match
-
-
Method Detail
-
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
public GPointArray pointsInRadius(GPoint p, double r)
Retrieves a newGPointArray
with all the points that are contained in the circle with centerp
and and radiusr
.- Parameters:
p
-GPoint
of the centerr
- radius- Returns:
- a new
GPointArray
with the points of the intersection - Throws:
java.lang.IllegalArgumentException
- ifp
isnull
-
pointsInRadius
public GPointArray pointsInRadius(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 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
public GPoint closestPoint(GPoint p)
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:
java.lang.IllegalArgumentException
- ifp
isnull
-
closestPoint
public GPoint closestPoint(int x, int y)
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
public GPoint highestPoint()
Retrieves a copy of the highest point in this array at the moment- Returns:
- highest point
-
lowestPoint
public GPoint lowestPoint()
Retrieves a copy of the lowest point in this array at the moment- Returns:
- lowest point
-
leftmostPoint
public GPoint leftmostPoint()
Retrieves a copy of the leftmost point in this array at the moment- Returns:
- leftmost point or
null
if none is found.
-
rightmostPoint
public GPoint rightmostPoint()
Retrieves a copy of the rightmost point in this array at the moment- Returns:
- rightmost point or
null
if none is found.
-
getBounds
public GRectangle getBounds()
RetrievesGRectangle
that contains all of the points in this array- Returns:
- rectangle containing all the points
-
higherThan
public GPointArray 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 axis- Parameters:
p
-GPoint
that will be used to compare- Returns:
GPointArray
with all the higher points- Throws:
java.lang.IllegalArgumentException
- ifp
isnull
-
lowerThan
public GPointArray lowerThan(GPoint p)
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:
java.lang.IllegalArgumentException
- ifp
isnull
-
leftThan
public GPointArray leftThan(GPoint p)
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:
java.lang.IllegalArgumentException
- ifp
isnull
-
rightThan
public GPointArray rightThan(GPoint p)
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:
java.lang.IllegalArgumentException
- ifp
isnull
-
removeAll
public void removeAll(GPointArray arr)
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:
java.lang.IllegalArgumentException
- ifarray
isnull
-
append
public void append(GPointArray arr)
Appends all the point to this array, regardless if they are already contained- Parameters:
arr
- points to add- Throws:
java.lang.IllegalArgumentException
- ifarray
isnull
-
intersection
public GPointArray intersection(GPointArray array)
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:
java.lang.IllegalArgumentException
- ifarray
isnull
-
intersection
public GPointArray intersection(GRectangle r)
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:
java.lang.IllegalArgumentException
- ifr
isnull
-
intersection
public GPointArray intersection(GLine l)
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:
java.lang.IllegalArgumentException
- ifl
isnull
-
intersection
public GPointArray intersection(GCircle c)
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:
java.lang.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
public void draw(java.awt.Graphics2D g)
Description copied from class:GraphicE
Draws the component on the given graphics
-
clone
public GPointArray clone()
- Specified by:
clone
in classGFillableE
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classGMultiPoint
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classGMultiPoint
-
-