public class Point2DFloatList
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
class |
Point2DFloatList.CentroidAndArea
This is a helper class that stores centroid and area (which share
calculations and will be calculated together.
|
Modifier and Type | Field and Description |
---|---|
private BoundingBox2DFloat |
boundingBox
Bounding box of the shape.
|
private boolean |
boundingBoxNeedsRecalculation
A flag indicating if the BoundingBox needs recalculation.
|
private Point2DFloatList.CentroidAndArea |
centroidAndArea
The centroid and area, if we've calculated it.
|
private boolean |
centroidNeedsRecalculation
Flag indicating if the centroidAndArea needs recalculating.
|
java.util.Vector<Point2DFloat> |
points
The vector of points
|
private int |
recalculateFrom
The index to start recalculating the bounding box from.
|
Constructor and Description |
---|
Point2DFloatList()
Construct a point list with no initial points.
|
Modifier and Type | Method and Description |
---|---|
void |
addPoint(float x,
float y)
Adds a point to this shape.
|
void |
addPoint(Point2DFloat point)
Adds a point to this shape.
|
private Point2DFloatList.CentroidAndArea |
calculateCentroidAndArea()
Calculate the centroid of the point list and the area, and caches it.
|
float |
getArea()
Calculates the area (if necessary) and returns it.
|
BoundingBox2DFloat |
getBoundingBox()
Returns the Bounding box of the object.
|
Point2DFloat |
getCentroid()
Calculates the centroid (if necessary) and returns it.
|
Point2DFloatList.CentroidAndArea |
getCentroidAndArea()
Calculates the centroid and area (if necessary) and returns it.
|
Point2DFloat |
getPoint(int index)
Gets the specified point.
|
int |
getPointCount()
Returns the number of points contained here.
|
boolean |
isInside(float x,
float y)
Returns true if the specified point is inside the polygon using the
even-odd rule.
|
static Point2DFloatList |
makeRegularPolygon(int sides,
float outerRadius,
double startAngle)
Constructs a regular polygon with the specified number of sides,
outer radius, and starting angle specified in radians (0 radians
points along the x-axis.)
TODO: Make the angle as a Unit?
|
private void |
recalculateBoundingBox()
Recalculates the BoundingBox for this shape.
|
Point2DFloatList |
rotateAround(float cx,
float cy,
double theta)
Creates a version of this polygon rotated around (cx, cy, by the
specified angle).
|
Point2DFloatList |
scaleAround(float cx,
float cy,
float scale)
Creates a version of this polygon scaled around (cx, cy).
|
public java.util.Vector<Point2DFloat> points
private boolean boundingBoxNeedsRecalculation
private int recalculateFrom
private Point2DFloatList.CentroidAndArea centroidAndArea
private boolean centroidNeedsRecalculation
private BoundingBox2DFloat boundingBox
public Point2DFloatList()
public void addPoint(float x, float y)
public void addPoint(Point2DFloat point)
public int getPointCount()
public Point2DFloat getPoint(int index)
public BoundingBox2DFloat getBoundingBox()
private void recalculateBoundingBox()
public Point2DFloat getCentroid()
public float getArea()
public Point2DFloatList.CentroidAndArea getCentroidAndArea()
private Point2DFloatList.CentroidAndArea calculateCentroidAndArea()
public boolean isInside(float x, float y)
public Point2DFloatList scaleAround(float cx, float cy, float scale)
public Point2DFloatList rotateAround(float cx, float cy, double theta)
public static Point2DFloatList makeRegularPolygon(int sides, float outerRadius, double startAngle)