public class ConvexObject extends RenderableObject implements Identity, java.io.Serializable
Modifier and Type | Field and Description |
---|---|
private int |
id
The ID for this object.
|
private Player |
owner
The player that owns this object.
|
private java.util.List<java.awt.geom.Point2D> |
points
The points that make up this convex object, starting
with the left most point in counter clockwise order.
|
private static long |
serialVersionUID
Serial ID.
|
private java.awt.geom.Path2D |
shape
The shape of this convex object.
|
Constructor and Description |
---|
ConvexObject(double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double x4,
double y4)
Constructs a new convex object defined by the given four points.
|
ConvexObject(int x1,
int y1,
int x2,
int y2,
int x3,
int y3)
Constructs a new convex object defined by the given three points.
|
ConvexObject(int x1,
int y1,
int x2,
int y2,
int x3,
int y3,
int x4,
int y4)
Constructs a new convex object defined by the given four points.
|
ConvexObject(java.util.List<java.awt.geom.Point2D> data)
Constructs a new convex object defined by the given list of points.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canClaim()
Checks if this objects is unowned and
thus claimable by any player.
|
private void |
constructShape()
Constructs the shape object for the bounds of this object.
|
boolean |
contains(ConvexObject other)
Checks if the given convex object is fully
contained within this convex object.
|
boolean |
contains(double x,
double y)
Checks if the given point is contained in this
convex object.
|
boolean |
equals(java.lang.Object other) |
double |
getArea()
Computes the area of this convex object.
|
java.awt.geom.Point2D |
getCentroid()
Computes the centroid of this convex object.
|
int |
getID()
Gets the ID of this entity.
|
Player |
getOwner()
Gets the player that owns this object.
|
java.util.List<java.awt.geom.Point2D> |
getPoints()
Gets the points that define this convex object.
|
java.awt.geom.Path2D |
getShape()
Gets a closed path representing the shape of
this convex object.
|
int |
hashCode() |
boolean |
intersects(ConvexObject other)
Checks if the given convex object intersects
this convex object.
|
boolean |
intersects(java.awt.geom.Point2D a,
java.awt.geom.Point2D b)
Checks if this convex object intersects the line segment
defined by the given end points.
|
boolean |
isOwned()
Checks if this object is owned by a player.
|
boolean |
isOwnedBy(Player player)
Tests if this convex object is owned by the given player.
|
ConvexObject |
merge(ConvexObject other)
Merges this object with the given object.
|
ConvexObject |
merge(GameState state,
ConvexObject other)
Attempts to merge this object with the given
object while checking that the boundary of the
resulting merged object does not intersect any
other objects in the given game state.
|
ConvexObject |
merge(GameState state,
ConvexObject other,
boolean saveSegments)
Attempts to merge this object with the given
object while checking that the boundary of the
resulting merged object does not intersect any
other objects in the given game state.
|
void |
render(java.awt.Graphics2D g)
Renders this object.
|
void |
scale(double factor)
Scales this object by the given scaling factor.
|
void |
setID(int id)
Sets the ID of this entity.
|
void |
setOwner(Player player)
Sets the player that owns this object.
|
java.lang.String |
toString() |
getAnimation, hasAnimation, renderOrAnimate, runAnimation, setAnimation
private static final long serialVersionUID
private int id
private java.util.List<java.awt.geom.Point2D> points
private java.awt.geom.Path2D shape
private transient Player owner
public ConvexObject(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
x1
- The x coordinate of the first point.y1
- The y coordinate of the first point.x2
- The x coordinate of the second point.y2
- The y coordinate of the second point.x3
- The x coordinate of the third point.y3
- The y coordinate of the third point.x4
- The x coordinate of the fourth point.y4
- The y coordinate of the fourth point.public ConvexObject(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
x1
- The x coordinate of the first point.y1
- The y coordinate of the first point.x2
- The x coordinate of the second point.y2
- The y coordinate of the second point.x3
- The x coordinate of the third point.y3
- The y coordinate of the third point.x4
- The x coordinate of the fourth point.y4
- The y coordinate of the fourth point.public ConvexObject(int x1, int y1, int x2, int y2, int x3, int y3)
x1
- The x coordinate of the first point.y1
- The y coordinate of the first point.x2
- The x coordinate of the second point.y2
- The y coordinate of the second point.x3
- The x coordinate of the third point.y3
- The y coordinate of the third point.public ConvexObject(java.util.List<java.awt.geom.Point2D> data)
data
- The point data.private void constructShape()
public java.awt.geom.Path2D getShape()
public java.util.List<java.awt.geom.Point2D> getPoints()
public Player getOwner()
null
if this object
is currently unowned.isOwned()
public boolean isOwned()
getOwner()
public void setOwner(Player player)
player
- The player to own this object.public boolean contains(double x, double y)
x
- The x coordinate of the point to test.y
- The y coordinate of the point to test.public ConvexObject merge(ConvexObject other)
other
- The object to merge with.merge(GameState, ConvexObject)
public ConvexObject merge(GameState state, ConvexObject other)
state
- The game state to check with if the
resulting object has any intersections. Can
be null
to skip this check.other
- The object to merge with.merge(ConvexObject)
public ConvexObject merge(GameState state, ConvexObject other, boolean saveSegments) throws java.lang.InterruptedException
state
- The game state to check with if the
resulting object has any intersections. Can
be null
to skip this check.other
- The object to merge with.saveSegments
- True if the merge lines for the
merge should be added to the game state.java.lang.InterruptedException
- When the player was
interrupted while making its move. Signalling
that the game was aborted.merge(ConvexObject)
public boolean intersects(java.awt.geom.Point2D a, java.awt.geom.Point2D b)
a
- The first endpoint of the line segment.b
- The second endpoint of the line segment.public boolean contains(ConvexObject other)
other
- The object to check.public boolean intersects(ConvexObject other)
other
- The object to check for
intersection with.public double getArea()
public boolean isOwnedBy(Player player)
player
- The player to check.public java.awt.geom.Point2D getCentroid()
public boolean canClaim()
public void scale(double factor)
factor
- The scaling factor.public void render(java.awt.Graphics2D g)
RenderableObject
render
in class RenderableObject
g
- The graphics context to use.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public int getID()
Identity