Package snap.geom

Class Polygon

All Implemented Interfaces:
Cloneable

public class Polygon extends Shape implements Cloneable
A Shape subclass to represent a simple geometric polygon.
  • Constructor Details

    • Polygon

      public Polygon()
      Constructor.
    • Polygon

      public Polygon(double... theCoords)
      Creates a new Polygon from given x y coords.
    • Polygon

      public Polygon(Point... thePoints)
      Creates a new Polygon from given x y coords.
  • Method Details

    • getPointArray

      public double[] getPointArray()
      Returns the raw points array.
    • setPointArray

      public void setPointArray(double[] thePoints)
      Sets the points.
    • getPointCount

      public int getPointCount()
      Returns the point count.
    • getPointX

      public double getPointX(int anIndex)
      Returns the x at given point index.
    • getPointY

      public double getPointY(int anIndex)
      Returns the y at given point index.
    • getPoint

      public Point getPoint(int anIndex)
      Returns the point at given index.
    • addPoint

      public void addPoint(double aX, double aY)
      Adds a point at given x/y.
    • setPoint

      public void setPoint(int anIndex, double aX, double aY)
      Sets a point at given point index to given x/y.
    • isClosed

      public boolean isClosed()
      Returns whether the polygon is closed.
      Overrides:
      isClosed in class Shape
    • setClosed

      public void setClosed(boolean aValue)
      Sets whether the polygon is closed.
    • getLastPoint

      public Point getLastPoint()
      Returns the last point.
    • getLastPointX

      public double getLastPointX()
      Returns the last x point.
    • getLastPointY

      public double getLastPointY()
      Returns the last y point.
    • clear

      public void clear()
      Clears the polygon.
    • getPointIndexForXY

      public int getPointIndexForXY(double aX, double aY, double aRad)
      Returns index of point at given x/y within given radius.
    • isSelfIntersecting

      public boolean isSelfIntersecting()
      Returns whether polygon has no intersecting lines.
      Overrides:
      isSelfIntersecting in class Shape
    • isConvex

      public boolean isConvex()
      Returns whether polygon is convex.
    • getAngle

      public double getAngle(int anIndex)
      Returns the interior angle at given point index.
    • getExtAngle

      public double getExtAngle(int anIndex)
      Returns the exterior angle at given point index.
    • getExtAngleSum

      public double getExtAngleSum()
      Returns the sum of exterior angles.
    • getConvexPolygonsWithMaxSideCount

      public Polygon[] getConvexPolygonsWithMaxSideCount(int aMax)
      Returns an array of polygons that are convex with max number of vertices.
    • splitConvex

      public Polygon splitConvex(int aMax)
      Splits this polygon into the first convex polygon and the remainder polygon and returns the remainder.
    • getBoundsImpl

      protected Rect getBoundsImpl()
      Returns the shape bounds.
      Overrides:
      getBoundsImpl in class Shape
    • getPathIter

      public PathIter getPathIter(Transform aTrans)
      Returns the path iterator.
      Specified by:
      getPathIter in class Shape
    • clone

      public Polygon clone()
      Standard clone implementation.
      Overrides:
      clone in class Object
    • getConvexPolygonsWithMaxSideCount

      public static Polygon[] getConvexPolygonsWithMaxSideCount(Shape aShape, int aMax)
      Returns an array of convex polygons for given max side count.