org.moyoman.util.closestpoint
Class ClosestPointGroup

java.lang.Object
  |
  +--org.moyoman.util.closestpoint.ClosestPointGroup
All Implemented Interfaces:
Cloneable, Serializable

public class ClosestPointGroup
extends Object
implements Serializable, Cloneable

This class represents a group of stones, and the points which are closer to one of those stones than to any other stones.

See Also:
Serialized Form

Field Summary
private  int maxx
          The maximum horizontal value of any point or stone.
private  int maxy
          The maximum vertical value of any point or stone.
private  int minx
          The minimum horizontal value of any point or stone.
private  int miny
          The minimum vertical value of any point or stone.
private  HashSet points
          The points which are as close to this group as any other.
private  ArrayList stones
          The stones which make up this group.
 
Constructor Summary
protected ClosestPointGroup(Stone st)
          Create a new ClosestPointGroup object.
 
Method Summary
protected  void addEmptyPoint(Point pt)
          Add an empty point to the list.
protected  void addStone(Stone st)
          Add a stone to the group.
 Object clone()
          Override the Object.clone() method.
protected  void combineGroups(ClosestPointGroup cpg)
          Add all of the stones and empty points from the specified group to this one.
 boolean containsPoint(Point pt)
          Determine whether the group contains the empty point.
 boolean containsStone(Stone st)
          Determine if the stone is in the group.
 Stone getAnyStone()
          Get any stone in the group.
 Color getColor()
           
protected  int getMaxX()
          Get the maximum horizontal value for an empty point or stone in this group.
protected  int getMaxY()
          Get the maximum vertical value for an empty point or stone in this group.
protected  int getMinX()
          Get the minimum horizontal value for an empty point or stone in this group.
protected  int getMinY()
          Get the minimum vertical value for an empty point or stone in this group.
 Point[] getPoints()
          Get all the points which are closest to one of the stones of this group.
 Point[] getPointsAndStones()
          Get all of the stones and empty points in this group.
 Stone[] getStones()
          Get all of the stones contained by this polygon.
protected  short getTotalPoints()
          Get the number of empty points in this group.
protected  short getTotalStones()
          Get the total number of stones in this group.
private  void initializeBoundsVariables()
          Set the variables which describe the bounding box for this group.
 boolean isInBoundingBox(Point pt)
          Determine if the point is inside of the bounding box for this group.
protected  void removeEmptyPoint(Point pt)
          Remove an empty point from this group.
protected  void removePoints(Point[] pts)
          Remove multiple empty points from this group.
protected  void removeStones(Stone[] st)
          Remove some stones from this group.
private  void setBoundsVariables(Point pt)
          Update the bounds variables for this group.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

points

private HashSet points
The points which are as close to this group as any other.


stones

private ArrayList stones
The stones which make up this group.


minx

private int minx
The minimum horizontal value of any point or stone.


maxx

private int maxx
The maximum horizontal value of any point or stone.


miny

private int miny
The minimum vertical value of any point or stone.


maxy

private int maxy
The maximum vertical value of any point or stone.

Constructor Detail

ClosestPointGroup

protected ClosestPointGroup(Stone st)
Create a new ClosestPointGroup object. Note that this object is not in a consistent state until the addEmptyPoint() method has been called. It is the responsiblility of the ClosestPoints class to do that.

Parameters:
st - The stone which this new group contains.
Method Detail

addStone

protected void addStone(Stone st)
Add a stone to the group. Note that this object is not in a consistent state until the addEmptyPoint() method has been called. It is the responsiblility of the ClosestPoints class to do that.

Parameters:
st - The stone to be added to this group.

combineGroups

protected void combineGroups(ClosestPointGroup cpg)
Add all of the stones and empty points from the specified group to this one.

Parameters:
cpg - The group which is to be combined with this one.

addEmptyPoint

protected void addEmptyPoint(Point pt)
Add an empty point to the list.

Parameters:
pt - The empty point to be added.

initializeBoundsVariables

private void initializeBoundsVariables()
Set the variables which describe the bounding box for this group. The bounding box is the smallest one which contains all the empty points and stones of this group.


setBoundsVariables

private void setBoundsVariables(Point pt)
Update the bounds variables for this group.

Parameters:
pt - The point which has been added to the group.

getMinX

protected int getMinX()
Get the minimum horizontal value for an empty point or stone in this group.

Returns:
The minimum horizontal value.

getMaxX

protected int getMaxX()
Get the maximum horizontal value for an empty point or stone in this group.

Returns:
The maximum horizontal value.

getMinY

protected int getMinY()
Get the minimum vertical value for an empty point or stone in this group.

Returns:
The minimum vertical value.

getMaxY

protected int getMaxY()
Get the maximum vertical value for an empty point or stone in this group.

Returns:
The maximum vertical value.

removeEmptyPoint

protected void removeEmptyPoint(Point pt)
Remove an empty point from this group.

Parameters:
pt - The empty point to be removed.

removePoints

protected void removePoints(Point[] pts)
Remove multiple empty points from this group.

Parameters:
pts - The empty points to be removed.

removeStones

protected void removeStones(Stone[] st)
Remove some stones from this group.


getTotalStones

protected short getTotalStones()
Get the total number of stones in this group.

Returns:
A short which is the number of stones in this group.

getTotalPoints

protected short getTotalPoints()
Get the number of empty points in this group.

Returns:
A short representing the number of empty points in this group.

getPoints

public Point[] getPoints()
Get all the points which are closest to one of the stones of this group. This includes both points closest to this group, and points equally close to this group and other groups. This just returns empty points, not the stones of the group, or enclosed stones.

Returns:
An array of Point objects.
See Also:
ClosestPoints.getUniquePoints()

getPointsAndStones

public Point[] getPointsAndStones()
Get all of the stones and empty points in this group.

Returns:
An array of Point objects, some of which are Point objects, and others of which are Stone objects.

containsPoint

public boolean containsPoint(Point pt)
Determine whether the group contains the empty point.

Parameters:
pt - The point in question.
Returns:
true if the empty point is in the group, or false.

isInBoundingBox

public boolean isInBoundingBox(Point pt)
Determine if the point is inside of the bounding box for this group.

Parameters:
pt - The point in question.
Returns:
true if it in the bounding box, or false.

containsStone

public boolean containsStone(Stone st)
Determine if the stone is in the group.

Parameters:
st - The stone in question.
Returns:
true if the stone is in the group, or false.

getStones

public Stone[] getStones()
Get all of the stones contained by this polygon.

Returns:
An array of Stone objects.

getAnyStone

public Stone getAnyStone()
Get any stone in the group.

Returns:
A Stone object which belongs to the group.

getColor

public Color getColor()

clone

public Object clone()
Override the Object.clone() method.

Overrides:
clone in class Object
Returns:
A ClosestPointGroup object which is a clone of this one.