Class WorldPolygon

java.lang.Object
edu.cnu.mdi.graphics.world.WorldPolygon

public class WorldPolygon extends Object
  • Field Details

    • npoints

      public int npoints
      The total number of points. The value of npoints represents the number of valid points in this Polygon and might be less than the number of elements in xpoints or ypoints.
    • xpoints

      public double[] xpoints
      The array of X coordinates. The number of elements in this array might be more than the number of X coordinates in this Polygon. The extra elements allow new points to be added to this Polygon without re-creating this array. The value of npoints is equal to the number of valid points in this Polygon.
    • ypoints

      public double[] ypoints
      The array of Y coordinates. The number of elements in this array might be more than the number of Y coordinates in this Polygon. The extra elements allow new points to be added to this Polygon without re-creating this array. The value of npoints is equal to the number of valid points in this Polygon.
    • bounds

      protected Rectangle2D.Double bounds
      The bounds of this Polygon. This value can be null.
  • Constructor Details

    • WorldPolygon

      public WorldPolygon()
      Creates an empty polygon.
    • WorldPolygon

      public WorldPolygon(double[] xpoints, double[] ypoints, int npoints)
      Constructs and initializes a Polygon from the specified parameters.
      Parameters:
      xpoints - an array of X coordinates
      ypoints - an array of Y coordinates
      npoints - the total number of points in the Polygon
      Throws:
      NegativeArraySizeException - if the value of npoints is negative.
      IndexOutOfBoundsException - if npoints is greater than the length of xpoints or the length of ypoints .
      NullPointerException - if xpoints or ypoints is null.
    • WorldPolygon

      public WorldPolygon(Point2D.Double w1, Point2D.Double w2, Point2D.Double w3, Point2D.Double w4)
  • Method Details

    • reset

      public void reset()
      Resets this Polygon object to an empty polygon. The coordinate arrays and the data in them are left untouched but the number of points is reset to zero to mark the old vertex data as invalid and to start accumulating new vertex data at the beginning. All internally-cached data relating to the old vertices are discarded. Note that since the coordinate arrays from before the reset are reused, creating a new empty Polygon might be more memory efficient than resetting the current one if the number of vertices in the new polygon data is significantly smaller than the number of vertices in the data from before the reset.
      See Also:
    • invalidate

      public void invalidate()
      Invalidates or flushes any internally-cached data that depends on the vertex coordinates of this Polygon. This method should be called after any direct manipulation of the coordinates in the xpoints or ypoints arrays to avoid inconsistent results from methods such as getBounds or contains that might cache data from earlier computations relating to the vertex coordinates.
      See Also:
    • addPoint

      public void addPoint(double x, double y)
      Appends the specified coordinates to this Polygon.

      If an operation that calculates the bounding box of this Polygon has already been performed, such as getBounds or contains, then this method updates the bounding box.

      Parameters:
      x - the specified X coordinate
      y - the specified Y coordinate
      See Also:
    • getBounds

      public Rectangle getBounds()
      Gets the bounding box of this Polygon. The bounding box is the smallest Rectangle whose sides are parallel to the x and y axes of the coordinate space, and can completely contain the Polygon.
      Returns:
      a Rectangle that defines the bounds of this Polygon.
    • contains

      public boolean contains(int x, int y)
      Determines whether the specified coordinates are inside this Polygon.

      Parameters:
      x - the specified X coordinate to be tested
      y - the specified Y coordinate to be tested
      Returns:
      true if this Polygon contains the specified coordinates (x,y); false otherwise.
      See Also:
    • contains

      public boolean contains(double x, double y)
      Determines whether the specified coordinates are inside this Polygon.

      Parameters:
      x - the specified X coordinate to be tested
      y - the specified Y coordinate to be tested
      Returns:
      true if this Polygon contains the specified coordinates (x,y); false otherwise.
    • getBoundingBox

      public Rectangle getBoundingBox()
      Returns the bounds of this Polygon.
      Returns:
      the bounds of this Polygon.
    • contains

      public boolean contains(Point2D p)
      Determines whether the specified Point2D is inside this Polygon.
      Parameters:
      p - the specified Point2D to be tested
      Returns:
      true if this Polygon contains the specified Point2D; false otherwise.
      See Also: