Package nl.colorize.multimedialib.math
Record Class Polygon
java.lang.Object
java.lang.Record
nl.colorize.multimedialib.math.Polygon
- All Implemented Interfaces:
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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
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
hashCode()
Returns a hash code value for this object.boolean
Returns true if this polygon intersects with the specified other polygon.float[]
points()
Returns the value of thepoints
record component.reposition
(Point2D offset) Returns a newShape
instance that is repositioned by the specified X and Y offset.Subdivides this polygon into a number of triangles.toString()
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 aPolygon
record class.- Parameters:
points
- the value for thepoints
record component
-
-
Method Details
-
getNumPoints
public int getNumPoints() -
getPointX
public float getPointX(int n) -
getPointY
public float getPointY(int n) -
contains
Description copied from interface:Shape
Returns whether this shape contains the specified point. -
intersects
Returns true if this polygon intersects with the specified other polygon. Implementation based on Slick. -
getBoundingBox
Returns the smallest possible axis-aligned rectangle that contains this polygon.- Specified by:
getBoundingBox
in interfaceShape
-
getCenter
-
subdivide
Subdivides this polygon into a number of triangles. This requires this polygon to be convex. -
reposition
Description copied from interface:Shape
Returns a newShape
instance that is repositioned by the specified X and Y offset.- Specified by:
reposition
in interfaceShape
-
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. -
createCircle
Convenience method to create a polygon in the shape of a circle with the specified properties. -
createCone
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. -
equals
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 withObjects::equals(Object,Object)
. -
points
public float[] points()Returns the value of thepoints
record component.- Returns:
- the value of the
points
record component
-