Record Class Polygon

java.lang.Object
java.lang.Record
nl.colorize.multimedialib.math.Polygon
All Implemented Interfaces:
Shape

public record Polygon(List<Point2D> points) extends Record implements Shape
A two-dimensional convex polygon with float precision coordinates.
  • Field Summary

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

    EPSILON
  • Constructor Summary

    Constructors
    Constructor
    Description
    Polygon(List<Point2D> points)
    Creates an instance of a Polygon record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns whether this shape contains the specified point.
    static Polygon
    createCircle(Point2D origin, float radius, int numPoints)
    Convenience method to create a polygon in the shape of a circle with the specified properties.
    static Polygon
    createCone(Point2D origin, float angle, float arc, float length)
    Convenience method to create a cone-shaped polygon.
    static Polygon
    createCone(Point2D origin, Angle angle, float arc, float length)
    Convenience method to create a cone-shaped polygon.
    final boolean
    Indicates whether some other object is "equal to" this one.
    static Polygon
    fromPoints(float... points)
    Factory method that creates a polygon from an array of points, in the format [x0, y0, x1, y1, ...].
    Returns the smallest possible axis-aligned rectangle that contains this polygon.
     
    int
    Deprecated.
    getPoint(int n)
    Deprecated.
    float
    getPointX(int n)
    Deprecated.
    float
    getPointY(int n)
    Deprecated.
    final int
    Returns a hash code value for this object.
    boolean
    Returns true if this polygon intersects with the specified other polygon.
    Returns the value of the points record component.
    Returns a new Shape instance that is repositioned by the specified offset.
    Subdivides this polygon into a number of triangles.
    float[]
    Returns an array that contains the X and Y coordinates for all points within this polygon, in the format [x0, y0, x1, y1, ...].
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface nl.colorize.multimedialib.math.Shape

    reposition
  • Constructor Details

    • Polygon

      public Polygon(List<Point2D> points)
      Creates an instance of a Polygon record class.
      Parameters:
      points - the value for the points record component
  • Method Details

    • toPoints

      public float[] toPoints()
      Returns an array that contains the X and Y coordinates for all points within this polygon, in the format [x0, y0, x1, y1, ...].
    • getNumPoints

      @Deprecated public int getNumPoints()
      Deprecated.
    • getPointX

      @Deprecated public float getPointX(int n)
      Deprecated.
    • getPointY

      @Deprecated public float getPointY(int n)
      Deprecated.
    • getPoint

      @Deprecated public Point2D getPoint(int n)
      Deprecated.
    • contains

      public boolean contains(Point2D p)
      Description copied from interface: Shape
      Returns whether this shape contains the specified point.
      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 Slick.
    • getBoundingBox

      public Rect getBoundingBox()
      Returns the smallest possible axis-aligned rectangle that contains this polygon.
      Specified by:
      getBoundingBox in interface Shape
    • getCenter

      public Point2D getCenter()
      Specified by:
      getCenter in interface Shape
    • subdivide

      public List<Polygon> subdivide()
      Subdivides this polygon into a number of triangles. This requires this polygon to be convex.
    • reposition

      public Polygon reposition(Point2D offset)
      Description copied from interface: Shape
      Returns a new Shape instance that is repositioned by the specified offset.
      Specified by:
      reposition in interface Shape
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • fromPoints

      public static Polygon fromPoints(float... points)
      Factory method that creates a polygon from an array of points, in the format [x0, y0, x1, y1, ...].
    • createCircle

      public static Polygon createCircle(Point2D 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(Point2D origin, Angle angle, float arc, float length)
      Convenience method to create a cone-shaped polygon. The cone's angle indicates in which direction the cone is pointed, its arc indicates its size (in degrees).
    • createCone

      public static Polygon createCone(Point2D origin, float angle, float arc, float length)
      Convenience method to create a cone-shaped polygon. The cone's angle indicates in which direction the cone is pointed, its arc indicates its size (in degrees).
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • points

      public List<Point2D> points()
      Returns the value of the points record component.
      Returns:
      the value of the points record component