|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.moyoman.util.closestpoint.ClosestPoints
This class manages groups of stones, and certain properties of those groups. For each group of stones, it determines which empty points are closest to it, and which other groups are adjacent to it.
Field Summary | |
private HashMap |
adjacencyInfo
The key is a ClosestPointGroup object, and the value is an ArrayList, which contains ClosestPointGroup objects. |
private ArrayList |
cpg
This contains all of the ClosestPointGroup objects. |
private HashMap |
pointInfo
The key is a Point object, and the value is a PointInfo object. |
private HashMap |
stones
The key is a Stone object, and the value is a ClosestPointGroup object. |
Constructor Summary | |
ClosestPoints()
Create the ClosestPoints object. |
Method Summary | |
void |
addStone(ClosestPointGroup currcpg,
Stone st)
Add a stone to an existing closest point group. |
private void |
clearAdjacencyInfo()
Remove all cached adjacency info. |
Object |
clone()
Override the Object.clone() method. |
void |
combineGroups(ClosestPointGroup[] cpgarr)
Combine two or more groups into one group. |
private void |
computeAdjacencyRelationship(ClosestPointGroup currcpg)
Find the adjacent groups to the specified one, and update the adjacencyInfo variable. |
private Stone[] |
findClosestStones(Point pt)
Find the closest stones to the given point. |
ClosestPointGroup[] |
getAdjacentGroups(ClosestPointGroup currcpg)
Get all of the groups adjacent to a given group. |
private Point[] |
getAdjacentPoints(Point pt)
Get all of the points which are adjacent to the point in question. |
private Point[] |
getConcentricEmptyPoints(Point pt,
int distance)
Get the empty points that form a square around the point at the specified distance. |
short |
getDistance(Point pt)
Return the square of the distance to the closest stone. |
ClosestPointGroup[] |
getEnclosedGroups(ClosestPointGroup currcpg)
Get all of the groups enclosed by a given group. |
double |
getExactDistance(Point pt)
Return the exact distance to the closest stone. |
ClosestPointGroup |
getGroup(Stone st)
Get the ClosestPointGroup that contains the given stone. |
ClosestPointGroup |
getGroupNoException(Stone st)
Get the ClosestPointGroup that contains the given stone. |
ClosestPointGroup[] |
getGroups()
Get all of the groups. |
ClosestPointGroup[] |
getGroups(Point pt)
Get all of the groups which contain the given point. |
HashMap |
getPointInfo()
Get the mapping from Point to PointInfo objects. |
int |
getTotalPoints(ClosestPointGroup cpgrp)
Get the number of empty points as close to or closer to this group than any other. |
float |
getTotalUniquePoints(ClosestPointGroup cpgrp)
Get the total number of unique points for a group. |
Point[] |
getUniquePoints(ClosestPointGroup cpgrp)
Get the points which are closer to this group than any other. |
boolean |
isEmptyPoint(Point pt)
Determine if the point is an empty point. |
boolean |
isStone(Point pt)
Determine if the point contains a stone. |
void |
newGroup(Stone st)
Add a stone to its own closest point group. |
private void |
recomputePoint(Point pt)
Recompute the PointInfo information for a given point. |
private void |
recomputePointInfo(ClosestPointGroup oldcpg)
Remove any information from the PointInfo objects about the old group. |
private ClosestPointGroup |
refresh(ClosestPointGroup cpgrp)
This method returns the corresponding ClosestPointGroup object. |
void |
removeGroup(ClosestPointGroup oldcpg)
Remove the given group. |
private void |
removeGroupInfo(ClosestPointGroup oldcpg)
Remove the group from the global list. |
void |
removeStones(ClosestPointGroup currcpg,
Stone[] starr)
Remove stones from the given group. |
private void |
updateEmptyPoints(Stone st,
ClosestPointGroup currcpg)
Update the PointInfo objects based on the last stone added. |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private ArrayList cpg
private HashMap stones
private HashMap pointInfo
private HashMap adjacencyInfo
Constructor Detail |
public ClosestPoints()
Method Detail |
public void newGroup(Stone st) throws DataAlreadyExistsException
st
- The stone.
DataAlreadyExistsException
- Thrown if the stone is already in a group.private void updateEmptyPoints(Stone st, ClosestPointGroup currcpg)
st
- The stone that was added.currcpg
- The group that the stone belongs to.public short getDistance(Point pt) throws NoSuchDataException
pt
- The empty point for which the distance is being retrieved.
NoSuchDataException
- Thrown if the point is not an empty point.public double getExactDistance(Point pt) throws NoSuchDataException
pt
- The empty point for which the distance is being retrieved.
NoSuchDataException
- Thrown if the point is not an empty point.private Point[] getConcentricEmptyPoints(Point pt, int distance)
pt
- The point in question.distance
- The radius of the square.
public void addStone(ClosestPointGroup currcpg, Stone st) throws DataAlreadyExistsException
currcpg
- The existing ClosestPointGroup object.st
- The stone to be added to the group.
DataAlreadyExistsException
- Thrown if the stone is already in a group.public float getTotalUniquePoints(ClosestPointGroup cpgrp)
cpgrp
- The ClosestPointGroup in question.
public Point[] getUniquePoints(ClosestPointGroup cpgrp)
cpgrp
- THe ClosestPointGroup in question.
public int getTotalPoints(ClosestPointGroup cpgrp)
cpgrp
- THe ClosestPointGroup in question.
private void computeAdjacencyRelationship(ClosestPointGroup currcpg)
currcpg
- The ClosestPointGroup in question.public boolean isEmptyPoint(Point pt)
pt
- The point in question.
public boolean isStone(Point pt)
pt
- The point in question.
private ClosestPointGroup refresh(ClosestPointGroup cpgrp)
It is not clear if the need for this method is a normal result of cloning, or due to a bug. This should be investigated.
cpgrp
- The ClosestPointGroup object.
private void clearAdjacencyInfo()
private Point[] getAdjacentPoints(Point pt)
pt
- The point in question.
public HashMap getPointInfo()
public void combineGroups(ClosestPointGroup[] cpgarr)
public void removeStones(ClosestPointGroup currcpg, Stone[] starr)
currcpg
- - The ClosestPointGroup from which the stones are to be removed.private void removeGroupInfo(ClosestPointGroup oldcpg)
oldcpg
- The group to be removed.public void removeGroup(ClosestPointGroup oldcpg)
oldcpg
- The group to be removed.private void recomputePointInfo(ClosestPointGroup oldcpg)
oldcpg
- The group to be removed.private void recomputePoint(Point pt)
pt
- The point for which the information is to be recomputed.private Stone[] findClosestStones(Point pt)
pt
- The point in question.
public ClosestPointGroup[] getGroups(Point pt)
pt
- The point in question.
public ClosestPointGroup getGroup(Stone st) throws NoSuchDataException
st
- The stone in question.
NoSuchDataException
- Thrown if there is no group for the stone.public ClosestPointGroup getGroupNoException(Stone st)
st
- The stone in question.
public ClosestPointGroup[] getGroups()
public ClosestPointGroup[] getAdjacentGroups(ClosestPointGroup currcpg)
currcpg
- The ClosestPointGroup object in question.
public ClosestPointGroup[] getEnclosedGroups(ClosestPointGroup currcpg)
currcpg
- The ClosestPointGroup object in question.
public Object clone()
clone
in class Object
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |