Class Polygon2D.Double

  • All Implemented Interfaces:
    java.awt.Shape
    Enclosing class:
    Polygon2D

    public static class Polygon2D.Double
    extends Polygon2D
    The concrete Polygon class that stores coordinates internally as doubles.
    • Constructor Summary

      Constructors 
      Constructor Description
      Double()
      Create a new polygon with no coordinates
      Double​(double[] coords)
      Create a new polygon with the given vertices, in the format [x0, y0, x1, y1, ...
      Double​(double x, double y)
      Create a new polygon with a single start point
      Double​(int size)
      Create a new polygon with space for the given number of vertices.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.awt.geom.Rectangle2D getBounds2D()
      Get the floating-point bounds of the polygon.
      int getVertexCount()
      Get the number of vertices
      double getX​(int index)
      Get the given X-coordinate
      double getY​(int index)
      Get the given Y-coordinate
      void lineTo​(double x, double y)
      Add a new vertex to the end of the line.
      void moveTo​(double x, double y)
      Move the start point of the vertex to the given position.
      void setX​(int index, double x)
      Set the given X-coordinate.
      void setY​(int index, double y)
      Set the given Y-coordinate
      void transform​(java.awt.geom.AffineTransform at)
      Transform the polygon with the given transform.
      void translate​(double x, double y)
      Translate the polygon the given distance.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Double

        public Double​(int size)
        Create a new polygon with space for the given number of vertices.
      • Double

        public Double​(double[] coords)
        Create a new polygon with the given vertices, in the format [x0, y0, x1, y1, ... ].
      • Double

        public Double()
        Create a new polygon with no coordinates
      • Double

        public Double​(double x,
                      double y)
        Create a new polygon with a single start point
    • Method Detail

      • getBounds2D

        public java.awt.geom.Rectangle2D getBounds2D()
        Get the floating-point bounds of the polygon.
        Specified by:
        getBounds2D in interface java.awt.Shape
        Specified by:
        getBounds2D in class Polygon2D
      • getVertexCount

        public int getVertexCount()
        Get the number of vertices
        Overrides:
        getVertexCount in class Polygon2D
      • getX

        public double getX​(int index)
        Get the given X-coordinate
        Specified by:
        getX in class Polygon2D
        Throws:
        java.lang.IndexOutOfBoundsException - The index is out of bounds.
      • getY

        public double getY​(int index)
        Get the given Y-coordinate
        Specified by:
        getY in class Polygon2D
        Throws:
        java.lang.IndexOutOfBoundsException - The index is out of bounds.
      • lineTo

        public void lineTo​(double x,
                           double y)
        Add a new vertex to the end of the line.
        Specified by:
        lineTo in class Polygon2D
      • moveTo

        public void moveTo​(double x,
                           double y)
        Move the start point of the vertex to the given position.
        Specified by:
        moveTo in class Polygon2D
        Throws:
        java.lang.UnsupportedOperationException - The polygon already has vertices
      • setX

        public void setX​(int index,
                         double x)
        Set the given X-coordinate.
        Specified by:
        setX in class Polygon2D
        Throws:
        java.lang.IndexOutOfBoundsException - The index is out of bounds.
      • setY

        public void setY​(int index,
                         double y)
        Set the given Y-coordinate
        Specified by:
        setY in class Polygon2D
        Throws:
        java.lang.IndexOutOfBoundsException - The index is out of bounds.
      • transform

        public void transform​(java.awt.geom.AffineTransform at)
        Transform the polygon with the given transform.
        Specified by:
        transform in class Polygon2D
      • translate

        public void translate​(double x,
                              double y)
        Translate the polygon the given distance.
        Specified by:
        translate in class Polygon2D