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
FieldsModifier and TypeFieldDescriptionprotected final AtomicIntegerprotected final Lockprotected intprotected int[]protected int[] -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedGMultiPoint(int initial) protectedGMultiPoint(int[] xs, int[] ys) protectedCopy constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidappend(int x, int y) Appends a new point to the path.voidAppends a new point to the pathvoidappendNR(int x, int y) Appends a new point to the path if and only if this point doesn't exist within the array.voidclear()Clears the objectvoidensureCapacity(int nElements) Allocates enough space for the specified number of elementsbooleangetPointAt(int idx) Retrieves a givenGPointfrom the pathGPoint[]Retrieves a COPY of theGPoint's in the pathgetShape()This method should return aAreathat represents theGFillableE.inthashCode()intindexOf(int x, int y) Retrieves the index of the first occurrence of this pointintindexOf(int x, int y, int start) Retrieves the index of the first occurrence of this point after the starting pointintRetrieves the index of the first occurrence of this pointintRetrieves the index of the first occurrence of this point after the starting pointbooleanisEmpty()Tells if the object doesn't contain any pointsiterator()booleanremove(int idx) Removes the element at the specified indexbooleanremove(int x, int y) Removes the first occurrence of this point in the arraybooleanRemoves the first occurrence of this point in the arrayintsize()Retrieves the number of verticesvoidsortByX()Sorts all the points in this array by it'sXvalue, and breaks ties with theYvaluevoidtraslate(int x, int y) Traslates this element on X and YvoidRemoves all the extra space used by the objectMethods inherited from class com.dkt.graphics.elements.GFillableE
clone, fill, getFillPaint, setFill, setFillPaintMethods inherited from class com.dkt.graphics.elements.GraphicE
draw, 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
-
Field Details
-
modCount
-
mutex
-
size
protected int size -
xs
protected int[] xs -
ys
protected int[] ys
-
-
Constructor Details
-
GMultiPoint
Copy constructor- Parameters:
e-GMultiPointto copy- Throws:
IllegalArgumentException- ifeisnull
-
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 isnullor 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- ifpointisnull
-
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- ifpointisnull
-
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:
trueif the point was contained andfalseotherwise- Throws:
IllegalArgumentException- ifpointisnull
-
remove
public boolean remove(int idx) Removes the element at the specified index- Parameters:
idx- Index of the element- Returns:
trueif the point was contained andfalseotherwise- 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:
trueif the point was contained andfalseotherwise
-
getPointAt
Retrieves a givenGPointfrom the path- Parameters:
idx- the index of the point to retrieve- Returns:
GPointat 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- theGPointto append- Throws:
IllegalArgumentException- ifpisnull- 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- ifnElementsis less than 0
-
isEmpty
public boolean isEmpty()Tells if the object doesn't contain any points- Returns:
trueif the object is empty andfalseotherwise
-
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:GraphicETraslates this element on X and Y -
sortByX
public void sortByX()Sorts all the points in this array by it'sXvalue, and breaks ties with theYvalue -
iterator
-
hashCode
public int hashCode()- Overrides:
hashCodein classGFillableE
-
equals
- Overrides:
equalsin classGFillableE
-
getShape
Description copied from class:GFillableEThis method should return aAreathat represents theGFillableE. Since this is not always possible, and the implementation ofAreaisn't always easy, it should returnnullotherwise.
InjDrawingLibs implementation we use the default shapes for this. Note that this method is only called to create clips forGraphicobjects- Specified by:
getShapein classGFillableE- Returns:
- Shape
-