Class Polygon2D.Double

    • Constructor Detail

      • Double

        public Double()
        Create a new polygon with no coordinates
      • 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​(Point2D p)
      • Double

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

        public Double​(double[] xlocs,
                      double[] ylocs)
        Create a new polygon with the provided x and y locations. If the two arrays are of unequal length, an empty polygon is created. NaN values are ignored
        Parameters:
        xlocs - the array of x locations.
        ylocs - the array of y locations.
    • Method Detail

      • copy

        public Polygon2D.Double copy()
        Creates a copy of this polygon with the same coordinates. The original polygon remains unchanged.
        Specified by:
        copy in class Polygon2D
        Returns:
        a copy of the this polygon
      • getCentroid

        public Point2D getCentroid()
        Description copied from class: Polygon2D
        Calculates the center point of this Polygon2D
        Specified by:
        getCentroid in class Polygon2D
        Returns:
        the center point of this Polygon2D
      • getVertices

        public List<Point2D> getVertices()
        Description copied from class: Polygon2D
        Gets a list of Point2D vertices of this polygon.
        Specified by:
        getVertices in class Polygon2D
        Returns:
        a List{Point2D} of vertices
      • getXCoords

        public double[] getXCoords()
        Description copied from class: Polygon2D
        Gets a double array containing the X coordinates of the polygon.
        Specified by:
        getXCoords in class Polygon2D
        Returns:
        the X coordinates
      • getYCoords

        public double[] getYCoords()
        Description copied from class: Polygon2D
        Gets a double array containing the Y coordinates of the polygon.
        Specified by:
        getYCoords in class Polygon2D
        Returns:
        the Y coordinates
      • 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:
        UnsupportedOperationException - The polygon already has vertices
      • translate

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