Record Class Polygon

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

public record Polygon(float[] points) extends Record implements Shape
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)
    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 polygon in the shape of a circle with the specified properties.
    final boolean
    Indicates whether some other object is "equal to" this one.
    Returns the smallest possible axis-aligned rectangle that contains this polygon.
     
    int
     
    float
    getPointX(int n)
     
    float
    getPointY(int n)
     
    final int
    Returns a hash code value for this object.
    boolean
    Returns true if this polygon intersects with the specified other polygon.
    float[]
    Returns the value of the points record component.
    Returns a new Shape instance that is repositioned by the specified X and Y offset.
    Subdivides this polygon into a number of triangles.
    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(float... points)
      Creates an instance of a Polygon record class.
      Parameters:
      points - the value for the points record component
  • Method Details

    • getNumPoints

      public int getNumPoints()
    • getPointX

      public float getPointX(int n)
    • getPointY

      public float getPointY(int n)
    • 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()
    • 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 X and Y 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
    • 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, float angle, 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.
    • 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 float[] points()
      Returns the value of the points record component.
      Returns:
      the value of the points record component