Class PolygonUtils


  • public class PolygonUtils
    extends Object
    Helper class for polygons.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    • Constructor Detail

      • PolygonUtils

        public PolygonUtils()
    • Method Detail

      • toPolygon

        public static Polygon toPolygon​(List<Point> points)
        Returns the bounding box for the polygon.
        Parameters:
        points - the polygon points to calculate the bounding box for
        Returns:
        the polygon
      • toPolygon

        public static Polygon toPolygon​(Rectangle rect)
        Turns the rectangle into a polygon.
        Parameters:
        rect - the polygon to convert
        Returns:
        the polygon
      • toPoints

        public static List<Point> toPoints​(Polygon poly)
        Turns the polygon into a list of points.
        Parameters:
        poly - the polygon
        Returns:
        the list of points
      • boundingBox

        public static Rectangle boundingBox​(List<Point> points)
        Returns the bounding box for the polygon.
        Parameters:
        points - the polygon points to calculate the bounding box for
        Returns:
        the bbox
      • minDistance

        public static double minDistance​(Point A,
                                         Point B,
                                         Point E)
        Returns the minimum distance between a line segment AB and a point E.
        Parameters:
        A - the start of the line segment
        B - the end of the line segment
        E - the point to calculate the min distance to
        Returns:
        the minimum distance
      • addVertext

        public static Polygon addVertext​(Polygon poly,
                                         Point vertex)
        Adds the vertex to the polygon at the appropriate position.
        Parameters:
        poly - the polygon to add to
        vertex - the vertex to insert
        Returns:
        the new polygon
      • inside

        public static int inside​(Polygon outer,
                                 Polygon inner)
        Determines the number of x/y pairs of the inner polygon that fall inside the outer polygon.
        Parameters:
        outer - the outer polygon
        inner - the inner polygon
        Returns:
        the number of pairs that fall inside
      • overlap

        public static boolean overlap​(Polygon p1,
                                      Polygon p2,
                                      boolean fully)
        Checks whether the polygons overlap.
        Parameters:
        p1 - the first polygon
        p2 - the second polygon
        fully - whether one polygon must be fully contained by the other
        Returns:
        true if they overlap
      • inc

        public static Polygon inc​(Polygon p,
                                  int incX,
                                  int incY)
        Increments/decrements the x/y coordinates of the polygon.
        Parameters:
        p - the polygon to update
        incX - the X increment/decrement
        incY - the Y increment/decrement
        Returns:
        the new polygon