Class Polygon

  • All Implemented Interfaces:
    Shape

    public class Polygon
    extends java.lang.Object
    implements Shape
    Describes a two-dimensional convex polygon with float precision coordinates. The polygon is described by an array of points, e.g. [x0, y0, x1, y1, ...].
    • Field Summary

      • Fields inherited from interface nl.colorize.multimedialib.math.Shape

        EPSILON
    • Constructor Summary

      Constructors 
      Constructor Description
      Polygon​(float... points)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean contains​(Point p)  
      static Polygon createCircle​(Point origin, float radius, int numPoints)
      Convenience method to create a polygon in the shape of a circle with the specified properties.
      static Polygon createCone​(Point origin, float startAngle, float arc, float length)
      Convenience method to create a polygon in the shape of a circle with the specified properties.
      boolean equals​(java.lang.Object o)  
      int getNumPoints()  
      float[] getPoints()  
      float getPointX​(int n)  
      float getPointY​(int n)  
      int hashCode()  
      boolean intersects​(Polygon p)
      Returns true if this polygon intersects with the specified other polygon.
      void move​(float dx, float dy)  
      void setPoints​(float... points)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • Polygon

        public Polygon​(float... points)
    • Method Detail

      • setPoints

        public void setPoints​(float... points)
      • getPoints

        public float[] getPoints()
      • getNumPoints

        public int getNumPoints()
      • getPointX

        public float getPointX​(int n)
      • getPointY

        public float getPointY​(int n)
      • move

        public void move​(float dx,
                         float dy)
      • contains

        public boolean contains​(Point p)
        Specified by:
        contains in interface Shape
      • intersects

        public boolean intersects​(Polygon p)
        Returns true if this polygon intersects with the specified other polygon. Implementation based on http://slick.cokeandcode.com.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • createCircle

        public static Polygon createCircle​(Point origin,
                                           float radius,
                                           int numPoints)
        Convenience method to create a polygon in the shape of a circle with the specified properties.
      • createCone

        public static Polygon createCone​(Point origin,
                                         float startAngle,
                                         float arc,
                                         float length)
        Convenience method to create a polygon in the shape of a circle with the specified properties. The cone's start angle and arc are specified in degrees.