Class GMultiPoint

All Implemented Interfaces:
Cloneable, Iterable<GPoint>
Direct Known Subclasses:
GPath, GPointArray, GPoly

public abstract class GMultiPoint extends GFillableE implements Iterable<GPoint>
Represents an abstract array of (x, y) coordinates.
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

    Fields
    Modifier and Type
    Field
    Description
    protected final AtomicInteger
     
    protected final Lock
     
    protected int
     
    protected int[]
     
    protected int[]
     

    Fields inherited from class com.dkt.graphics.elements.GraphicE

    STROKE
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    GMultiPoint(int initial)
     
    protected
    GMultiPoint(int[] xs, int[] ys)
     
    protected
    Copy constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    append(int x, int y)
    Appends a new point to the path.
    void
    Appends a new point to the path
    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.
    void
    Clears the object
    void
    ensureCapacity(int nElements)
    Allocates enough space for the specified number of elements
    boolean
     
    getPointAt(int idx)
    Retrieves a given GPoint from the path
    Retrieves a COPY of the GPoint's in the path
    This method should return a Area that represents the GFillableE.
    int
     
    int
    indexOf(int x, int y)
    Retrieves the index of the first occurrence of this point
    int
    indexOf(int x, int y, int start)
    Retrieves the index of the first occurrence of this point after the starting point
    int
    indexOf(GPoint point)
    Retrieves the index of the first occurrence of this point
    int
    indexOf(GPoint point, int start)
    Retrieves the index of the first occurrence of this point after the starting point
    boolean
    Tells if the object doesn't contain any points
     
    boolean
    remove(int idx)
    Removes the element at the specified index
    boolean
    remove(int x, int y)
    Removes the first occurrence of this point in the array
    boolean
    remove(GPoint point)
    Removes the first occurrence of this point in the array
    int
    Retrieves the number of vertices
    void
    Sorts all the points in this array by it's X value, and breaks ties with the Y value
    void
    traslate(int x, int y)
    Traslates this element on X and Y
    void
    Removes all the extra space used by the object

    Methods 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

      protected final AtomicInteger modCount
    • mutex

      protected final Lock mutex
    • size

      protected int size
    • xs

      protected int[] xs
    • ys

      protected int[] ys
  • Constructor Details

    • GMultiPoint

      protected GMultiPoint(GMultiPoint e)
      Copy constructor
      Parameters:
      e - GMultiPoint to copy
      Throws:
      IllegalArgumentException - if e is null
    • 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 coordinates
      ys - list of Y coordinates
      Throws:
      IllegalArgumentException - if either array is null or if the array size doesn't match
  • Method Details

    • size

      public int size()
      Retrieves the number of vertices
      Returns:
      number of vertices
    • indexOf

      public int indexOf(GPoint point)
      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 - if point is null
    • indexOf

      public int indexOf(GPoint point, int start)
      Retrieves the index of the first occurrence of this point after the starting point
      Parameters:
      point - point to check
      start - 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 - if point is null
    • indexOf

      public int indexOf(int x, int y)
      Retrieves the index of the first occurrence of this point
      Parameters:
      x - y coordinate of the point
      y - 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 point
      y - y coordinate of the point
      start - 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

      public boolean remove(GPoint point)
      Removes the first occurrence of this point in the array
      Parameters:
      point - the point to check
      Returns:
      true if the point was contained and false otherwise
      Throws:
      IllegalArgumentException - if point is null
    • 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 and false otherwise
      Throws:
      IndexOutOfBoundsException - if idx < 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 point
      y - y coordinate of the point
      Returns:
      true if the point was contained and false otherwise
    • getPointAt

      public GPoint getPointAt(int idx)
      Retrieves a given GPoint 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

      public GPoint[] getPoints()
      Retrieves a COPY of the GPoint'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 call ensureCapacity(size + 5)
      Parameters:
      x - X coordinate of the point
      y - 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 call ensureCapacity(size + 5)
      Parameters:
      x - X coordinate of the point
      y - Y coordinate of the point
      See Also:
    • append

      public void append(GPoint p)
      Appends a new point to the path
      Parameters:
      p - the GPoint to append
      Throws:
      IllegalArgumentException - if p is null
      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 - if nElements is less than 0
    • isEmpty

      public boolean isEmpty()
      Tells if the object doesn't contain any points
      Returns:
      true if the object is empty and false 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
      Specified by:
      traslate in class GraphicE
      Parameters:
      x - size in px of the horizontal translation
      y - size in px of the vertical translation
    • sortByX

      public void sortByX()
      Sorts all the points in this array by it's X value, and breaks ties with the Y value
    • iterator

      public Iterator<GPoint> iterator()
      Specified by:
      iterator in interface Iterable<GPoint>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class GFillableE
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class GFillableE
    • getShape

      public Area getShape()
      Description copied from class: GFillableE
      This method should return a Area that represents the GFillableE. Since this is not always possible, and the implementation of Area isn't always easy, it should return null otherwise.
      In jDrawingLibs implementation we use the default shapes for this. Note that this method is only called to create clips for Graphic objects
      Specified by:
      getShape in class GFillableE
      Returns:
      Shape