Class GPointArray

All Implemented Interfaces:
Cloneable, Iterable<GPoint>

public class GPointArray extends GMultiPoint
Author:
Federico Vera <[email protected]>
  • Constructor Details

    • GPointArray

      public GPointArray(GPointArray e)
      Copy constructor
      Parameters:
      e - GPointArray to copy
      Throws:
      IllegalArgumentException - if e is null
    • GPointArray

      public GPointArray(GPoint[] points)
      Parameters:
      points - GPoint array containing all the points
      Throws:
      IllegalArgumentException - if the array is null
    • GPointArray

      public GPointArray(GPoint[] points, int cs)
      Parameters:
      points - GPoint array containing all the points
      cs - cross size
      Throws:
      IllegalArgumentException - if the array is null
    • GPointArray

      public GPointArray()
      Generates a new empty GPointArray
    • 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 coordinates
      ys - array containing all the y coordinates
      Throws:
      IllegalArgumentException - if either array is null
      InvalidArgumentException - if the array size doesn't match
    • GPointArray

      public GPointArray(int[] xs, int[] ys, int cs)
      Parameters:
      xs - array containing all the x coordinates
      ys - array containing all the y coordinates
      cs - the cross size of the point
      Throws:
      IllegalArgumentException - if either array is null
      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

      public GPointArray pointsInRadius(GPoint p, double r)
      Retrieves a new GPointArray with all the points that are contained in the circle with center p and radius r.
      Parameters:
      p - GPoint of the center
      r - radius
      Returns:
      a new GPointArray with the points of the intersection
      Throws:
      IllegalArgumentException - if p is null
    • pointsInRadius

      public GPointArray pointsInRadius(int x, int y, double r)
      Retrieves a new GPointArray with all the points that are contained in the circle with center in (x, y) and radius r.
      Parameters:
      x - X coordinate of the center
      y - Y coordinate of the center
      r - radius
      Returns:
      a new GPointArray with the points of the intersection
    • closestPoint

      public GPoint closestPoint(GPoint p)
      Retrieves a new GPoint 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 to p
      Throws:
      IllegalArgumentException - if p is null
    • closestPoint

      public GPoint closestPoint(int x, int y)
      Retrieves a new GPoint representing the coordinates of the closest point in this array
      Parameters:
      x - X coordinate of the point
      y - Y coordinate of the point
      Returns:
      a new GPoint representing the closest to (x, y) or null 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()
      Retrieves GRectangle that contains all the points in this array
      Returns:
      rectangle containing all the points
    • higherThan

      public GPointArray higherThan(GPoint p)
      Retrieves a new GPointArray representing all the points that are above p.
      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 - if p is null
    • lowerThan

      public GPointArray lowerThan(GPoint p)
      Retrieves a new GPointArray representing all the points that are below p.
      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 - if p is null
    • leftThan

      public GPointArray leftThan(GPoint p)
      Retrieves a new GPointArray representing all the points that are located to the left of p.
      Parameters:
      p - GPoint that will be used to compare
      Returns:
      GPointArray with all the left points
      Throws:
      IllegalArgumentException - if p is null
    • rightThan

      public GPointArray rightThan(GPoint p)
      Retrieves a new GPointArray representing all the points that are located to the right of p.
      Parameters:
      p - GPoint that will be used to compare
      Returns:
      GPointArray with all the right points
      Throws:
      IllegalArgumentException - if p is null
    • 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:
      IllegalArgumentException - if array is null
    • 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:
      IllegalArgumentException - if array is null
    • intersection

      public GPointArray intersection(GPointArray array)
      Retrieves a new GPointArray 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 - if array is null
    • intersection

      public GPointArray intersection(GRectangle r)
      Retrieves a new GPointArray containing all the points that are contained both in this array and in the GRectangle passed as an argument
      Parameters:
      r - rectangle to intersect
      Returns:
      a new GPointArray with all the points of the intersection
      Throws:
      IllegalArgumentException - if r is null
    • intersection

      public GPointArray intersection(GLine l)
      Retrieves a new GPointArray containing all the points that are contained both in this array and in the GLine passed as an argument
      Parameters:
      l - the line to intersect
      Returns:
      a new GPointArray with all the points of the intersection
      Throws:
      IllegalArgumentException - if l is null
    • intersection

      public GPointArray intersection(GCircle c)
      Retrieves a new GPointArray containing all the points that are contained both in this array and in the GCircle passed as an argument
      Parameters:
      c - the circle to intersect
      Returns:
      a new GPointArray with all the points of the intersection
      Throws:
      IllegalArgumentException - if c is null
    • sortByX

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

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

      public void removeDuplicates()
      Removes ALL duplicate entries in the array.
    • draw

      public void draw(Graphics2D g)
      Description copied from class: GraphicE
      Draws the component on the given graphics
      Specified by:
      draw in class GraphicE
      Parameters:
      g - where to draw
    • clone

      public GPointArray clone()
      Specified by:
      clone in class GFillableE
    • hashCode

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

      public boolean equals(Object obj)
      Overrides:
      equals in class GMultiPoint