Class Polygon

java.lang.Object
ro.sync.exml.view.graphics.BaseShape
ro.sync.exml.view.graphics.Polygon
All Implemented Interfaces:
Shape, ro.sync.exml.view.graphics.ShapePointContributor

@API(type=EXTENDABLE, src=PRIVATE) public class Polygon extends BaseShape implements ro.sync.exml.view.graphics.ShapePointContributor
The Polygon class encapsulates a description of a closed, two-dimensional region within a coordinate space.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
    The total number of points.
    int[]
    The array of x coordinates.
    int[]
    The array of y coordinates.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty polygon.
    Polygon(int[] xpoints, int[] ypoints, int npoints)
    Constructs and initializes a Polygon from the specified parameters.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addPoint(int x, int y)
    Appends the specified coordinates to this Polygon.
    boolean
    contains(int x, int y)
    Check if this complicated shape contains the requested point.
     
    translate(int tx, int ty)
    Translate the shape into another one.

    Methods inherited from class ro.sync.exml.view.graphics.BaseShape

    contains

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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. This value can be NULL.
      See Also:
    • xpoints

      public int[] 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.
      See Also:
    • ypoints

      public int[] 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.
      See Also:
  • Constructor Details

    • Polygon

      public Polygon()
      Creates an empty polygon.
    • Polygon

      public Polygon(int[] xpoints, int[] 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.
  • Method Details

    • addPoint

      public void addPoint(int x, int 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.

      Specified by:
      addPoint in interface ro.sync.exml.view.graphics.ShapePointContributor
      Parameters:
      x - the specified x coordinate
      y - the specified y coordinate
      See Also:
    • getBounds

      public Rectangle getBounds()
      Specified by:
      getBounds in interface Shape
      Returns:
      The bounds of this shape.
      See Also:
    • translate

      public Shape translate(int tx, int ty)
      Description copied from interface: Shape
      Translate the shape into another one.
      Specified by:
      translate in interface Shape
      Parameters:
      tx - the distance by which coordinates are translated in the X axis direction
      ty - the distance by which coordinates are translated in the Y axis direction
      Returns:
      The newly translated shape
      See Also:
    • contains

      public boolean contains(int x, int y)
      Check if this complicated shape contains the requested point.
      Specified by:
      contains in interface Shape
      Parameters:
      x - The X of the point.
      y - The Y of the point.
      Returns:
      true if the point is inside of the shape. false otherwise.