maze.geometry
Class HexGeometry

java.lang.Object
  extended bymaze.geometry.MazeGeometry
      extended bymaze.geometry.HexGeometry

public class HexGeometry
extends MazeGeometry

Contains facts about the current maze geometry. In this case it is a bounded hexagonal geometry. Methods are available which will transform a coordinate and a direction into a new coordinate. Directions can be absolute directions or a direction and an angle.


Field Summary
 
Fields inherited from class maze.geometry.MazeGeometry
Debug, hMax, hScale, MAX_DIRECTIONS, origin, P1, P2, vMax, vScale
 
Constructor Summary
HexGeometry(int h, int v)
          Creates a new HexGeometry of a given size.
 
Method Summary
 Coordinate advance(Coordinate c, int d)
          Computes a new coordinate, given a coordinate and an absolute direction
protected  double cellRadius()
          Computes the center-to-vertex distance for a cell with this geometry Hexagonal tiling goes from vertex to edge, r is a function of hScale such that the NW vertex to E edge distance = hScale, also the top to bottom edge distance is vScale.
 void setRect(java.awt.Rectangle r)
          Computes the scaling for an alternating coordinate hex geometry, also compute the tiling for this hex geometry.
 int startDir()
          Finds a good starting pair of directions, must be distinct
 java.awt.Point wallP1(int x, int y, int dir)
          Provides a sensible coordinate system for a surface tiled with hexagons by offsetting cell vertexes as needed - P1 is one end of a cell wall
 java.awt.Point wallP2(int x, int y, int dir)
          Provides a sensible coordinate system for a surface tiled with hexagons by offsetting cell vertexes as needed - P2 is the other end of a cell wall
 
Methods inherited from class maze.geometry.MazeGeometry
advance, cellHoffset, cellPoly, cellVoffset, iterator, label, label, left, opp, right, setTiling, start, turn, wallPoly
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HexGeometry

public HexGeometry(int h,
                   int v)
Creates a new HexGeometry of a given size.

Parameters:
h - int horizontal size.
v - int vertical size.
Method Detail

setRect

public void setRect(java.awt.Rectangle r)
Computes the scaling for an alternating coordinate hex geometry, also compute the tiling for this hex geometry.

Overrides:
setRect in class MazeGeometry
Parameters:
r - Rectangle with the overall size of the maze.
See Also:
MazeGeometry.setTiling()

advance

public Coordinate advance(Coordinate c,
                          int d)
Computes a new coordinate, given a coordinate and an absolute direction

Specified by:
advance in class MazeGeometry
Parameters:
c - Coordinate from which to begin.
d - int direction in which to advance.
Returns:
Coordinate for the next location in the given direction.

startDir

public int startDir()
Finds a good starting pair of directions, must be distinct

Overrides:
startDir in class MazeGeometry
Returns:
int starting direction.

cellRadius

protected double cellRadius()
Computes the center-to-vertex distance for a cell with this geometry Hexagonal tiling goes from vertex to edge, r is a function of hScale such that the NW vertex to E edge distance = hScale, also the top to bottom edge distance is vScale. Can't satisfy both, so we take the smaller.

Returns:
double cell radius.

wallP1

public java.awt.Point wallP1(int x,
                             int y,
                             int dir)
Provides a sensible coordinate system for a surface tiled with hexagons by offsetting cell vertexes as needed - P1 is one end of a cell wall

Overrides:
wallP1 in class MazeGeometry
Parameters:
x - int horizontal coordinate
y - int vertical coordinate
dir - int direction
Returns:
new Point in the graphics coordinate space.

wallP2

public java.awt.Point wallP2(int x,
                             int y,
                             int dir)
Provides a sensible coordinate system for a surface tiled with hexagons by offsetting cell vertexes as needed - P2 is the other end of a cell wall

Overrides:
wallP2 in class MazeGeometry
Parameters:
x - int horizontal coordinate
y - int vertical coordinate
dir - int direction
Returns:
new Point in the graphics coordinate space.