Class 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 npoints
      The total number of points.
      int[] xpoints
      The array of x coordinates.
      int[] ypoints
      The array of y coordinates.
    • Constructor Summary

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

      All Methods Instance Methods Concrete Methods 
      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.
      Rectangle getBounds()  
      Shape translate​(int tx, int ty)
      Translate the shape into another one.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • 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:
        addPoint(int, int)
      • 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:
        addPoint(int, int)
      • 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:
        addPoint(int, int)
    • Constructor Detail

      • 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:
        java.lang.NegativeArraySizeException - if the value of npoints is negative.
        java.lang.IndexOutOfBoundsException - if npoints is greater than the length of xpoints or the length of ypoints.
        java.lang.NullPointerException - if xpoints or ypoints is null.
    • Method Detail

      • 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:
        Polygon.getBounds()
      • 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:
        Shape.translate(int, int)
      • 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.