Package com.dkt.graphics.elements
Class GMultiPoint
java.lang.Object
com.dkt.graphics.elements.GraphicE
com.dkt.graphics.elements.GFillableE
com.dkt.graphics.elements.GMultiPoint
- Direct Known Subclasses:
GPath
,GPointArray
,GPoly
Represents an abstract array of (x, y) coordinates.
Note: even though this class extends from
Note: even though this class extends from
GFillableE
it's the
subclass option to enforce the fill methods- Author:
- Federico Vera <[email protected]>
-
Field Summary
Modifier and TypeFieldDescriptionprotected final AtomicInteger
protected final Lock
protected int
protected int[]
protected int[]
-
Constructor Summary
ModifierConstructorDescriptionprotected
GMultiPoint
(int initial) protected
GMultiPoint
(int[] xs, int[] ys) protected
Copy constructor -
Method Summary
Modifier and TypeMethodDescriptionvoid
append
(int x, int y) Appends a new point to the path.void
Appends a new point to the pathvoid
appendNR
(int x, int y) Appends a new point to the path if and only if this point doesn't exist within the array.void
clear()
Clears the objectvoid
ensureCapacity
(int nElements) Allocates enough space for the specified number of elementsboolean
getPointAt
(int idx) Retrieves a givenGPoint
from the pathGPoint[]
Retrieves a COPY of theGPoint
's in the pathgetShape()
This method should return aArea
that represents theGFillableE
.int
hashCode()
int
indexOf
(int x, int y) Retrieves the index of the first occurrence of this pointint
indexOf
(int x, int y, int start) Retrieves the index of the first occurrence of this point after the starting pointint
Retrieves the index of the first occurrence of this pointint
Retrieves the index of the first occurrence of this point after the starting pointboolean
isEmpty()
Tells if the object doesn't contain any pointsiterator()
boolean
remove
(int idx) Removes the element at the specified indexboolean
remove
(int x, int y) Removes the first occurrence of this point in the arrayboolean
Removes the first occurrence of this point in the arrayint
size()
Retrieves the number of verticesvoid
sortByX()
Sorts all the points in this array by it'sX
value, and breaks ties with theY
valuevoid
traslate
(int x, int y) Traslates this element on X and Yvoid
Removes all the extra space used by the objectMethods inherited from class com.dkt.graphics.elements.GFillableE
clone, fill, getFillPaint, setFill, setFillPaint
Methods inherited from class com.dkt.graphics.elements.GraphicE
draw, 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
-
Field Details
-
modCount
-
mutex
-
size
protected int size -
xs
protected int[] xs -
ys
protected int[] ys
-
-
Constructor Details
-
GMultiPoint
Copy constructor- Parameters:
e
-GMultiPoint
to copy- Throws:
IllegalArgumentException
- ife
isnull
-
GMultiPoint
protected GMultiPoint(int initial) - Parameters:
initial
- initial reserved size- Throws:
NegativeArraySizeException
- if the size is less than zero
-
GMultiPoint
protected GMultiPoint(int[] xs, int[] ys) - Parameters:
xs
- list of X coordinatesys
- list of Y coordinates- Throws:
IllegalArgumentException
- if either array isnull
or if the array size doesn't match
-
-
Method Details
-
size
public int size()Retrieves the number of vertices- Returns:
- number of vertices
-
indexOf
Retrieves the index of the first occurrence of this point- Parameters:
point
- point to check- Returns:
- first index of the point or -1 if the point is not one of the path's vertices
- Throws:
IllegalArgumentException
- ifpoint
isnull
-
indexOf
Retrieves the index of the first occurrence of this point after the starting point- Parameters:
point
- point to checkstart
- starting point of the search- Returns:
- first index of the point or -1 if the point is not one of the path's vertices
- Throws:
IllegalArgumentException
- ifpoint
isnull
-
indexOf
public int indexOf(int x, int y) Retrieves the index of the first occurrence of this point- Parameters:
x
- y coordinate of the pointy
- y coordinate of the point- Returns:
- first index of the point or -1 if the point is not one of the path's vertices
-
indexOf
public int indexOf(int x, int y, int start) Retrieves the index of the first occurrence of this point after the starting point- Parameters:
x
- y coordinate of the pointy
- y coordinate of the pointstart
- starting point of the search- Returns:
- first index of the point or -1 if the point is not one of the path's vertices
-
clear
public void clear()Clears the object -
remove
Removes the first occurrence of this point in the array- Parameters:
point
- the point to check- Returns:
true
if the point was contained andfalse
otherwise- Throws:
IllegalArgumentException
- ifpoint
isnull
-
remove
public boolean remove(int idx) Removes the element at the specified index- Parameters:
idx
- Index of the element- Returns:
true
if the point was contained andfalse
otherwise- Throws:
IndexOutOfBoundsException
- ifidx < 0 | idx >= size
-
remove
public boolean remove(int x, int y) Removes the first occurrence of this point in the array- Parameters:
x
- x coordinate of the pointy
- y coordinate of the point- Returns:
true
if the point was contained andfalse
otherwise
-
getPointAt
Retrieves a givenGPoint
from the path- Parameters:
idx
- the index of the point to retrieve- Returns:
GPoint
at the specified position- Throws:
ArrayIndexOutOfBoundsException
- if(idx < 0 | idx > numberOfVertices)
-
getPoints
Retrieves a COPY of theGPoint
's in the path- Returns:
- array of points
-
append
public void append(int x, int y) Appends a new point to the path. If the path has run out of space then it will callensureCapacity(size + 5)
- Parameters:
x
- X coordinate of the pointy
- Y coordinate of the point- See Also:
-
appendNR
public void appendNR(int x, int y) Appends a new point to the path if and only if this point doesn't exist within the array. If the path has run out of space then it will callensureCapacity(size + 5)
- Parameters:
x
- X coordinate of the pointy
- Y coordinate of the point- See Also:
-
append
Appends a new point to the path- Parameters:
p
- theGPoint
to append- Throws:
IllegalArgumentException
- ifp
isnull
- See Also:
-
ensureCapacity
public void ensureCapacity(int nElements) Allocates enough space for the specified number of elements- Parameters:
nElements
- the capacity the array must be able to hold- Throws:
InvalidArgumentException
- ifnElements
is less than 0
-
isEmpty
public boolean isEmpty()Tells if the object doesn't contain any points- Returns:
true
if the object is empty andfalse
otherwise
-
trimToSize
public void trimToSize()Removes all the extra space used by the object -
traslate
public void traslate(int x, int y) Description copied from class:GraphicE
Traslates this element on X and Y -
sortByX
public void sortByX()Sorts all the points in this array by it'sX
value, and breaks ties with theY
value -
iterator
-
hashCode
public int hashCode()- Overrides:
hashCode
in classGFillableE
-
equals
- Overrides:
equals
in classGFillableE
-
getShape
Description copied from class:GFillableE
This method should return aArea
that represents theGFillableE
. Since this is not always possible, and the implementation ofArea
isn't always easy, it should returnnull
otherwise.
InjDrawingLib
s implementation we use the default shapes for this. Note that this method is only called to create clips forGraphic
objects- Specified by:
getShape
in classGFillableE
- Returns:
- Shape
-