net.aerith.misao.util
Class PositionMap

java.lang.Object
  |
  +--net.aerith.misao.util.PositionMap
Direct Known Subclasses:
DefaultMatchingSolver.MatchingPositionMap, TriangleMatchingSolver.TriangleMap

public class PositionMap
extends java.lang.Object

The PositionMap represents a rectangular map of Positions which consists of a list of (x,y) data and the two Positions at corners of the map area.

This class has functions to search data around the specified position. This PositionMap can be divided into some parts. After division properly, the search will be much faster.


Field Summary
protected  boolean accept_out_of_bounds
          True if OutOfBoundsException must not be thrown.
protected  Position bottom_right
          The position at the bottom-right corner.
protected  java.util.Vector list
          The list of (x,y) positions.
protected  java.util.Vector[][] table
          The table of divided parts.
protected  int table_columns
          The number of columns of divided table.
protected  int table_rows
          The number of rows of divided table.
protected  Position top_left
          The position at the top-left corner.
 
Constructor Summary
PositionMap(PositionList list)
          Constructs a PositionMap with the list of positions.
PositionMap(PositionMap original_map)
          Copies the specified PositionMap and constructs a new PositionMap.
PositionMap(Position top_left, Position bottom_right)
          Constructs an empty PositionMap with the positions at corners.
 
Method Summary
 void acceptOutOfBounds()
          Accepts the data out of the area, which will be shifted onto this map area.
 void addPosition(Position new_position)
          Adds a (x,y) position on this map.
 void addPosition(java.util.Vector new_list)
          Adds a list of (x,y) positions on this map.
protected  Position convertPosition(Position position)
          Converts the (x,y) position into the proper system for this map.
 void divide(int new_rows, int new_columns)
          Divides this map into some parts for fast search.
 void divideByCircleCoverage(double radius)
          Divides this map into some parts so that a circle with the specified radius covers each divided part.
 void divideByUnit(double unit_row, double unit_column)
          Divides this map into some parts for fast search, based on the specified unit.
 void exceptOutOfBounds()
          Excepts the data out of the area and the OutOfBoundsException must be thrown.
 java.util.Vector getAllPositions()
          Gets the list of all data in this map.
 double getArea()
          Gets the area of this map.
 Position getBottomLeftCorner()
          Gets the (x,y) of the bottom left corner.
 Position getBottomRightCorner()
          Gets the (x,y) of the bottom right corner.
 Position getCenter()
          Gets the (x,y) of the center.
 java.util.Vector getDividedPositionMapList()
          Gets the list of divided position maps.
 double getHeight()
          Gets the height of this map.
 java.util.Vector getPartialList(Position position)
          Gets the partial list on the divided map where the specified position locates in.
 java.util.Vector getPartialListWithinRadius(Position position, double radius)
          Creates a list of elements in the partial lists on the divided map where the specified position locates in and around within the specified radius.
 java.util.Vector getPartialListWithinSteps(Position position, int row_steps, int column_steps)
          Creates a list of elements in the partial lists on the divided map where the specified position locates in and around within the specified division steps.
 Position getTopLeftCorner()
          Gets the (x,y) of the top left corner.
 Position getTopRightCorner()
          Gets the (x,y) of the top right corner.
 double getWidth()
          Gets the width of this map.
 boolean isOutOfBounds(Position position)
          Checks if the specified position is out of this map area.
protected  java.lang.String paramString()
          Returns a raw string representation of the state of this object, for debugging use.
 boolean removePosition(Position position)
          Removes the specified position object from this map.
 java.lang.String toString()
          Returns a string representation of the state of this object, for debugging use.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

list

protected java.util.Vector list
The list of (x,y) positions.

top_left

protected Position top_left
The position at the top-left corner.

bottom_right

protected Position bottom_right
The position at the bottom-right corner.

table

protected java.util.Vector[][] table
The table of divided parts.

table_rows

protected int table_rows
The number of rows of divided table.

table_columns

protected int table_columns
The number of columns of divided table.

accept_out_of_bounds

protected boolean accept_out_of_bounds
True if OutOfBoundsException must not be thrown.
Constructor Detail

PositionMap

public PositionMap(Position top_left,
                   Position bottom_right)
Constructs an empty PositionMap with the positions at corners.
Parameters:
top_left - the position at top-left corner.
bottom_right - the position at bottom-right corner.

PositionMap

public PositionMap(PositionMap original_map)
Copies the specified PositionMap and constructs a new PositionMap.
Parameters:
original_map - the original map to copy.

PositionMap

public PositionMap(PositionList list)
Constructs a PositionMap with the list of positions. The top-left and bottom-right corner positions are automatically calculated.
Parameters:
list - the list of (x,y) positions.
Method Detail

acceptOutOfBounds

public void acceptOutOfBounds()
Accepts the data out of the area, which will be shifted onto this map area. The OutOfBoundsException must not be thrown.

exceptOutOfBounds

public void exceptOutOfBounds()
Excepts the data out of the area and the OutOfBoundsException must be thrown.

isOutOfBounds

public boolean isOutOfBounds(Position position)
Checks if the specified position is out of this map area.
Parameters:
position - the position to check.
Returns:
true if the specified position is out of this map area.

convertPosition

protected Position convertPosition(Position position)
Converts the (x,y) position into the proper system for this map. This method will be overrided in the subclasses. Thanks to this method, the (x,y) positions in the list do not have to be converted into the linear system in fact and remain original.
Parameters:
position - the original (x,y).
Returns:
the converted position in the system of this map.

addPosition

public void addPosition(Position new_position)
                 throws OutOfBoundsException
Adds a (x,y) position on this map.
Parameters:
new_position - the new (x,y) position.
Throws:
OutOfBoundsException - if the specified position is out of the map area.

addPosition

public void addPosition(java.util.Vector new_list)
                 throws OutOfBoundsException
Adds a list of (x,y) positions on this map.
Parameters:
new_list - the list of new (x,y) positions.
Throws:
OutOfBoundsException - if one of the position in the specified list is out of the map area.

removePosition

public boolean removePosition(Position position)
Removes the specified position object from this map.
Parameters:
position - the position object to be removed.
Returns:
true if the specified position object is in this map.

getWidth

public double getWidth()
Gets the width of this map.
Returns:
the width of this map.

getHeight

public double getHeight()
Gets the height of this map.
Returns:
the height of this map.

getTopLeftCorner

public Position getTopLeftCorner()
Gets the (x,y) of the top left corner.
Returns:
the (x,y) of the top left corner.

getTopRightCorner

public Position getTopRightCorner()
Gets the (x,y) of the top right corner.
Returns:
the (x,y) of the top right corner.

getBottomLeftCorner

public Position getBottomLeftCorner()
Gets the (x,y) of the bottom left corner.
Returns:
the (x,y) of the bottom left corner.

getBottomRightCorner

public Position getBottomRightCorner()
Gets the (x,y) of the bottom right corner.
Returns:
the (x,y) of the bottom right corner.

getCenter

public Position getCenter()
Gets the (x,y) of the center.
Returns:
the (x,y) of the center.

getArea

public double getArea()
Gets the area of this map.
Returns:
the area of this map.

getAllPositions

public java.util.Vector getAllPositions()
Gets the list of all data in this map.
Returns:
the new list which contains all data in this map.

getDividedPositionMapList

public java.util.Vector getDividedPositionMapList()
Gets the list of divided position maps.
Returns:
the list of divided position maps.

getPartialList

public java.util.Vector getPartialList(Position position)
                                throws OutOfBoundsException
Gets the partial list on the divided map where the specified position locates in. If this map is not yet divided, it returns null.
Parameters:
position - the position.
Returns:
the list where the position locates in.
Throws:
OutOfBoundsException - if the specified position is out of the map area.

getPartialListWithinSteps

public java.util.Vector getPartialListWithinSteps(Position position,
                                                  int row_steps,
                                                  int column_steps)
                                           throws OutOfBoundsException
Creates a list of elements in the partial lists on the divided map where the specified position locates in and around within the specified division steps. If this map is not yet divided, it returns null.
Parameters:
position - the position.
row_steps - the number of division steps to search vertically.
column_steps - the number of division steps to search horizontally.
Returns:
the list where the position locates in and around.
Throws:
OutOfBoundsException - if the specified position is out of the map area.

getPartialListWithinRadius

public java.util.Vector getPartialListWithinRadius(Position position,
                                                   double radius)
                                            throws OutOfBoundsException
Creates a list of elements in the partial lists on the divided map where the specified position locates in and around within the specified radius. If this map is not yet divided, it returns null.
Parameters:
position - the position.
radius - the radius to search.
Returns:
the list where the position locates in and around.
Throws:
OutOfBoundsException - if the specified position is out of the map area.

divideByUnit

public void divideByUnit(double unit_row,
                         double unit_column)
Divides this map into some parts for fast search, based on the specified unit.
Parameters:
unit_row - the unit to divide vertically.
unit_column - the unit to divide horizontally.

divide

public void divide(int new_rows,
                   int new_columns)
Divides this map into some parts for fast search.
Parameters:
new_rows - the number to divide vertically.
new_columns - the number to divide horizontally.

divideByCircleCoverage

public void divideByCircleCoverage(double radius)
Divides this map into some parts so that a circle with the specified radius covers each divided part.
Parameters:
radius - the radius of a circle.

paramString

protected java.lang.String paramString()
Returns a raw string representation of the state of this object, for debugging use. It should be invoked from toString method of the subclasses.
Returns:
a string representation of the state of this object.

toString

public java.lang.String toString()
Returns a string representation of the state of this object, for debugging use.
Overrides:
toString in class java.lang.Object
Returns:
a string representation of the state of this object.