Package arc.math.geom
Class Polygon
java.lang.Object
arc.math.geom.Polygon
- All Implemented Interfaces:
Shape2D
Encapsulates a 2D polygon defined by it's vertices relative to an origin point (default of 0, 0).
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfloat
area()
Returns the area contained within the polygon.boolean
contains
(float x, float y) Returns whether an x, y pair is contained within the polygon.boolean
Returns whether the given point is contained within the shape.void
dirty()
Sets the polygon's world vertices to be recalculated when callinggetTransformedVertices
.Returns an axis-aligned bounding box of this polygon.float
Returns the x-coordinate of the polygon's origin point.float
Returns the y-coordinate of the polygon's origin point.float
Returns the total rotation applied to the polygon.float
Returns the total horizontal scaling applied to the polygon.float
Returns the total vertical scaling applied to the polygon.float[]
Calculates and returns the vertices of the polygon after scaling, rotation, and positional translations have been applied, as they are position within the world.float[]
Returns the polygon's local vertices without scaling or rotation and without being offset by the polygon position.float
getX()
Returns the x-coordinate of the polygon's position within the world.float
getY()
Returns the y-coordinate of the polygon's position within the world.void
rotate
(float degrees) Applies additional rotation to the polygon by the supplied degrees.void
scale
(float amount) Applies additional scaling to the polygon by the supplied amount.void
setOrigin
(float originX, float originY) Sets the origin point to which all of the polygon's local vertices are relative to.void
setPosition
(float x, float y) Sets the polygon's position within the world.void
setRotation
(float degrees) Sets the polygon to be rotated by the supplied degrees.void
setScale
(float scaleX, float scaleY) Sets the amount of scaling to be applied to the polygon.void
setVertices
(float[] vertices) Sets the polygon's local vertices relative to the origin point, without any scaling, rotating or translations being applied.void
translate
(float x, float y) Translates the polygon's position by the specified horizontal and vertical amounts.
-
Constructor Details
-
Polygon
public Polygon()Constructs a new polygon with no vertices. -
Polygon
public Polygon(float[] vertices) Constructs a new polygon from a float array of parts of vertex points.- Parameters:
vertices
- an array where every even element represents the horizontal part of a point, and the following element representing the vertical part- Throws:
IllegalArgumentException
- if less than 6 elements, representing 3 points, are provided
-
-
Method Details
-
getVertices
public float[] getVertices()Returns the polygon's local vertices without scaling or rotation and without being offset by the polygon position. -
setVertices
public void setVertices(float[] vertices) Sets the polygon's local vertices relative to the origin point, without any scaling, rotating or translations being applied.- Parameters:
vertices
- float array where every even element represents the x-coordinate of a vertex, and the proceeding element representing the y-coordinate.- Throws:
IllegalArgumentException
- if less than 6 elements, representing 3 points, are provided
-
getTransformedVertices
public float[] getTransformedVertices()Calculates and returns the vertices of the polygon after scaling, rotation, and positional translations have been applied, as they are position within the world.- Returns:
- vertices scaled, rotated, and offset by the polygon position.
-
setOrigin
public void setOrigin(float originX, float originY) Sets the origin point to which all of the polygon's local vertices are relative to. -
setPosition
public void setPosition(float x, float y) Sets the polygon's position within the world. -
translate
public void translate(float x, float y) Translates the polygon's position by the specified horizontal and vertical amounts. -
rotate
public void rotate(float degrees) Applies additional rotation to the polygon by the supplied degrees. -
setScale
public void setScale(float scaleX, float scaleY) Sets the amount of scaling to be applied to the polygon. -
scale
public void scale(float amount) Applies additional scaling to the polygon by the supplied amount. -
dirty
public void dirty()Sets the polygon's world vertices to be recalculated when callinggetTransformedVertices
. -
area
public float area()Returns the area contained within the polygon. -
getBoundingRectangle
Returns an axis-aligned bounding box of this polygon.Note the returned Rectangle is cached in this polygon, and will be reused if this Polygon is changed.
- Returns:
- this polygon's bounding box
Rect
-
contains
public boolean contains(float x, float y) Returns whether an x, y pair is contained within the polygon. -
contains
Description copied from interface:Shape2D
Returns whether the given point is contained within the shape. -
getX
public float getX()Returns the x-coordinate of the polygon's position within the world. -
getY
public float getY()Returns the y-coordinate of the polygon's position within the world. -
getOriginX
public float getOriginX()Returns the x-coordinate of the polygon's origin point. -
getOriginY
public float getOriginY()Returns the y-coordinate of the polygon's origin point. -
getRotation
public float getRotation()Returns the total rotation applied to the polygon. -
setRotation
public void setRotation(float degrees) Sets the polygon to be rotated by the supplied degrees. -
getScaleX
public float getScaleX()Returns the total horizontal scaling applied to the polygon. -
getScaleY
public float getScaleY()Returns the total vertical scaling applied to the polygon.
-