maze.geometry
Class MazeGeometry

java.lang.Object
  extended bymaze.geometry.MazeGeometry
Direct Known Subclasses:
HexGeometry, RectGeometry

public abstract class MazeGeometry
extends java.lang.Object

Contains facts about the current maze geometry. Also does coordinate transformations to help draw the various maze objects.


Field Summary
protected static boolean Debug
          Debug wallPoly transformations
 int hMax
          Horizontal size of the maze, set by constructor.
 int hScale
          Horizontal scale factor, set by setRect method.
static int MAX_DIRECTIONS
          Maximum number of directions for this geometry
 java.awt.Point origin
          Origin on owning panel or canvas, set by setRect
protected  java.awt.Point[] P1
          Point for one end of a wall in each direction, created by setRect.
protected  java.awt.Point[] P2
          Point for the other end of a wall in each direction, created by setRect.
 int vMax
          Vertical size of the maze, set by constructor.
 int vScale
          Vertical scale factor, set by setRect method.
 
Constructor Summary
MazeGeometry(int h, int v)
          Creates a new MazeGeometry with the given horizontal and vertical size.
 
Method Summary
abstract  Coordinate advance(Coordinate c, int d)
          Computes a new coordinate, given a coordinate and an absolute direction
 Coordinate advance(Coordinate c, int d, int angle)
          Computes a new coordinate, given a coordinate, direction and an angle to turn
protected  double cellHoffset()
          Computes the horizontal offset for the reference corner of each cell.
 java.awt.Polygon cellPoly(int x, int y)
          Computes the screen location for the cell, must be preceeded by call to setRect with correct size of current display area
protected  double cellVoffset()
          Computes the vertical offset for the reference corner of each cell.
 GeoDirectionIterator iterator()
          Creates a GeoDirectionIterator for this particular geometry.
static java.lang.String label(int d)
          Creates a String label for a given direction.
static java.lang.String label(int dir, int angle)
          Creates a string label for a direction given a base direction and and angle to turn.
static int left(int d)
          Returns the direction one step to the "left", counter-clockwise.
static int opp(int d)
          Returns the direction opposite this direction.
static int right(int d)
          Returns the direction one step to the "right", clockwise.
 void setRect(java.awt.Rectangle r)
          Computes the scaling for this geometry, also computes a default tiling for this geometry.
 void setTiling()
          Computes a trivial default tiling for the surface.
 Coordinate start()
          Finds a good starting cell near the center of the maze
 int startDir()
          Finds a good starting pair of directions, must be distinct
static int turn(int dir, int angle)
          Returns a direction offset from a given direction by an angle.
 java.awt.Point wallP1(int x, int y, int dir)
          Returns one endpoint of the wall.
 java.awt.Point wallP2(int x, int y, int dir)
          Returns the other endpoint of the wall.
 java.awt.Polygon wallPoly(int x, int y, int dir)
          Computes the line which frames this wall of the given cell Use the following: Polygon p= wallPoly( x, y, dir ); drawLine( p.xpoints[0], p.ypoints[0], p.xpoints[1], p.ypoints[1] );
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_DIRECTIONS

public static int MAX_DIRECTIONS
Maximum number of directions for this geometry


hMax

public int hMax
Horizontal size of the maze, set by constructor.


vMax

public int vMax
Vertical size of the maze, set by constructor.


hScale

public int hScale
Horizontal scale factor, set by setRect method.


vScale

public int vScale
Vertical scale factor, set by setRect method.


origin

public java.awt.Point origin
Origin on owning panel or canvas, set by setRect


P1

protected java.awt.Point[] P1
Point for one end of a wall in each direction, created by setRect.


P2

protected java.awt.Point[] P2
Point for the other end of a wall in each direction, created by setRect.


Debug

protected static boolean Debug
Debug wallPoly transformations

Constructor Detail

MazeGeometry

public MazeGeometry(int h,
                    int v)
Creates a new MazeGeometry with the given horizontal and vertical size.

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

label

public static java.lang.String label(int d)
Creates a String label for a given direction.

Parameters:
d - int numeric direction.
Returns:
String code for the direction.

label

public static java.lang.String label(int dir,
                                     int angle)
Creates a string label for a direction given a base direction and and angle to turn.

Parameters:
dir - int base direction.
angle - int number of direction steps to turn.
Returns:
String label for the resulting direciton.

turn

public static int turn(int dir,
                       int angle)
Returns a direction offset from a given direction by an angle.

Parameters:
dir - int base direction.
angle - int number of direction steps to offset the base direction.
Returns:
new direction.

left

public static int left(int d)
Returns the direction one step to the "left", counter-clockwise.

Parameters:
d - int base direction.
Returns:
int direction one step to the left.

right

public static int right(int d)
Returns the direction one step to the "right", clockwise.

Parameters:
d - int base direction.
Returns:
int direction one step to the left.

opp

public static int opp(int d)
Returns the direction opposite this direction.

Parameters:
d - int base direction
Returns:
int direction opposite the base direction.

iterator

public GeoDirectionIterator iterator()
Creates a GeoDirectionIterator for this particular geometry.

Returns:
new GeoDirectionIterator appropriate to this geometry.

advance

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

Parameters:
c - Coordinate starting position
d - int direction of advance
Returns:
new Coordinate offset from the starting coordinate in the direction of the advance.

advance

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

Parameters:
c - Coordinate starting position
d - int direction of advance, used to offset the coordinate.
angle - int offset to the given direction.
Returns:
new Coordinate offset from the starting coordinate in a direction of the advance offset from the given direction by the angle.

start

public Coordinate start()
Finds a good starting cell near the center of the maze

Returns:
Coordinate of a good starting cell.

startDir

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

Returns:
int direction in which to start.

cellVoffset

protected double cellVoffset()
Computes the vertical offset for the reference corner of each cell.

Returns:
double graphic unit distance.

cellHoffset

protected double cellHoffset()
Computes the horizontal offset for the reference corner of each cell.

Returns:
double graphic unit distance.

setTiling

public void setTiling()
Computes a trivial default tiling for the surface. This is only sensible for trivial rectangular or hexagonal surface tilings. Other surface tilings require more elaborate shapes, e.g. alternating octagons and squares, Penrose dart and kite tiles, etc. Subclasses might want to override this.


setRect

public void setRect(java.awt.Rectangle r)
Computes the scaling for this geometry, also computes a default tiling for this geometry. This default works for rectangular, but not alternating coordinate hex tilings.

Parameters:
r - Rectangle with the overall size of the canvas on which the maze will be drawn.
See Also:
setTiling()

cellPoly

public java.awt.Polygon cellPoly(int x,
                                 int y)
Computes the screen location for the cell, must be preceeded by call to setRect with correct size of current display area

Parameters:
x - int horizontal coordinate of cell.
y - int vertical coordinate of cell.
Returns:
new Polygon to draw the cell.

wallPoly

public java.awt.Polygon wallPoly(int x,
                                 int y,
                                 int dir)
Computes the line which frames this wall of the given cell Use the following: Polygon p= wallPoly( x, y, dir ); drawLine( p.xpoints[0], p.ypoints[0], p.xpoints[1], p.ypoints[1] );

Parameters:
x - int horizontal coordinate of the cell.
y - int vertical coordinate of the cell.
dir - int direction of the wall.
Returns:
new Polygon to draw the wall.

wallP1

public java.awt.Point wallP1(int x,
                             int y,
                             int dir)
Returns one endpoint of the wall.

Parameters:
x - int horizontal coordinate of the cell.
y - int vertical coordinate of the cell.
dir - int direction of the wall.
Returns:
New Point for drawing one end of the wall.

wallP2

public java.awt.Point wallP2(int x,
                             int y,
                             int dir)
Returns the other endpoint of the wall.

Parameters:
x - int horizontal coordinate of the cell.
y - int vertical coordinate of the cell.
dir - int direction of the wall.
Returns:
New Point for drawing the other end of the wall.