com.brackeen.javagamebook.bsp2D
Class BSPLine

java.lang.Object
  extended byjava.awt.geom.Line2D
      extended byjava.awt.geom.Line2D.Float
          extended bycom.brackeen.javagamebook.bsp2D.BSPLine
All Implemented Interfaces:
java.lang.Cloneable, java.awt.Shape

public class BSPLine
extends java.awt.geom.Line2D.Float


Nested Class Summary
 
Nested classes inherited from class java.awt.geom.Line2D
java.awt.geom.Line2D.Double, java.awt.geom.Line2D.Float
 
Field Summary
static int BACK
           
 float bottom
          Bottom-most location of a line representing a wall.
static int COLLINEAR
           
static int FRONT
           
 float nx
          X coordinate of the line normal.
 float ny
          Y coordinate of the line normal.
static int SPANNING
           
 float top
          Top-most location of a line representing a wall.
 
Fields inherited from class java.awt.geom.Line2D.Float
x1, x2, y1, y2
 
Constructor Summary
BSPLine()
          Creates a new line from (0,0) to (0,0)
BSPLine(BSPPolygon poly)
          Creates a new BSPLine based on the specified BSPPolygon (only if the BSPPolygon is a vertical wall).
BSPLine(float x1, float y1, float x2, float y2)
          Creates a new BSPLine based on the specified coordinates.
 
Method Summary
 void calcNormal()
          Calculates the normal to this line.
 boolean equals(BSPLine line)
          Returns true if the endpoints of this line match the endpoints of the specified line.
 boolean equalsIgnoreOrder(BSPLine line)
          Returns true if the endpoints of this line match the endpoints of the specified line, ignoring endpoint order (if the first point of this line is equal to the second point of the specified line, and vice versa, returns true).
 void flip()
          Flips this line so that the end points are reversed (in other words, (x1,y1) becomes (x2,y2) and vice versa) and the normal is changed to point the opposite direction.
 float getIntersection(java.awt.geom.Line2D.Float line)
          Returns the fraction of intersection along this line.
 java.awt.geom.Point2D.Float getIntersectionPoint(java.awt.geom.Line2D.Float line)
          Returns the interection point of this line with the specified line.
 java.awt.geom.Point2D.Float getIntersectionPoint(java.awt.geom.Line2D.Float line, java.awt.geom.Point2D.Float intersection)
          Returns the interection of this line with the specified line.
 int getSide(BSPPolygon poly)
          Gets the side of this line that the specified polygon is on.
 int getSide(java.awt.geom.Line2D.Float segment)
          Gets the side of this line that the specified line segment is on.
 int getSideThick(float x, float y)
          Gets the side of this line the specified point is on.
 int getSideThin(float x, float y)
          Gets the side of this line the specified point is on.
 void normalize()
          Normalizes the normal of this line (make the normal's length 1).
 void setHeight(float top, float bottom)
          Sets the top and bottom height of this "wall".
 void setLine(double x1, double y1, double x2, double y2)
           
 void setLine(float x1, float y1, float x2, float y2)
           
 void setTo(BSPPolygon poly)
          Sets this BSPLine to the specified BSPPolygon (only if the BSPPolygon is a vertical wall).
 java.lang.String toString()
           
 
Methods inherited from class java.awt.geom.Line2D.Float
getBounds2D, getP1, getP2, getX1, getX2, getY1, getY2
 
Methods inherited from class java.awt.geom.Line2D
clone, contains, contains, contains, contains, getBounds, getPathIterator, getPathIterator, intersects, intersects, intersectsLine, intersectsLine, linesIntersect, ptLineDist, ptLineDist, ptLineDist, ptLineDistSq, ptLineDistSq, ptLineDistSq, ptSegDist, ptSegDist, ptSegDist, ptSegDistSq, ptSegDistSq, ptSegDistSq, relativeCCW, relativeCCW, relativeCCW, setLine, setLine
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BACK

public static final int BACK
See Also:
Constant Field Values

COLLINEAR

public static final int COLLINEAR
See Also:
Constant Field Values

FRONT

public static final int FRONT
See Also:
Constant Field Values

SPANNING

public static final int SPANNING
See Also:
Constant Field Values

nx

public float nx
X coordinate of the line normal.


ny

public float ny
Y coordinate of the line normal.


top

public float top
Top-most location of a line representing a wall.


bottom

public float bottom
Bottom-most location of a line representing a wall.

Constructor Detail

BSPLine

public BSPLine()
Creates a new line from (0,0) to (0,0)


BSPLine

public BSPLine(BSPPolygon poly)
Creates a new BSPLine based on the specified BSPPolygon (only if the BSPPolygon is a vertical wall).


BSPLine

public BSPLine(float x1,
               float y1,
               float x2,
               float y2)
Creates a new BSPLine based on the specified coordinates.

Method Detail

setTo

public void setTo(BSPPolygon poly)
Sets this BSPLine to the specified BSPPolygon (only if the BSPPolygon is a vertical wall).


calcNormal

public void calcNormal()
Calculates the normal to this line.


normalize

public void normalize()
Normalizes the normal of this line (make the normal's length 1).


setLine

public void setLine(float x1,
                    float y1,
                    float x2,
                    float y2)

setLine

public void setLine(double x1,
                    double y1,
                    double x2,
                    double y2)

flip

public void flip()
Flips this line so that the end points are reversed (in other words, (x1,y1) becomes (x2,y2) and vice versa) and the normal is changed to point the opposite direction.


setHeight

public void setHeight(float top,
                      float bottom)
Sets the top and bottom height of this "wall".


equals

public boolean equals(BSPLine line)
Returns true if the endpoints of this line match the endpoints of the specified line. Ignores normal and height values.


equalsIgnoreOrder

public boolean equalsIgnoreOrder(BSPLine line)
Returns true if the endpoints of this line match the endpoints of the specified line, ignoring endpoint order (if the first point of this line is equal to the second point of the specified line, and vice versa, returns true). Ignores normal and height values.


toString

public java.lang.String toString()

getSideThick

public int getSideThick(float x,
                        float y)
Gets the side of this line the specified point is on. This method treats the line as 1-unit thick, so points within this 1-unit border are considered collinear. For this to work correctly, the normal of this line must be normalized, either by setting this line to a polygon or by calling normalize(). Returns either FRONT, BACK, or COLLINEAR.


getSideThin

public int getSideThin(float x,
                       float y)
Gets the side of this line the specified point is on. Because of floating point inaccuracy, a collinear line will be rare. For this to work correctly, the normal of this line must be normalized, either by setting this line to a polygon or by calling normalize(). Returns either FRONT, BACK, or COLLINEAR.


getSide

public int getSide(java.awt.geom.Line2D.Float segment)
Gets the side of this line that the specified line segment is on. Returns either FRONT, BACK, COLINEAR, or SPANNING.


getSide

public int getSide(BSPPolygon poly)
Gets the side of this line that the specified polygon is on. Returns either FRONT, BACK, COLINEAR, or SPANNING.


getIntersection

public float getIntersection(java.awt.geom.Line2D.Float line)
Returns the fraction of intersection along this line. Returns a value from 0 to 1 if the segments intersect. For example, a return value of 0 means the intersection occurs at point (x1, y1), 1 means the intersection occurs at point (x2, y2), and .5 mean the intersection occurs halfway between the two endpoints of this line. Returns -1 if the lines are parallel.


getIntersectionPoint

public java.awt.geom.Point2D.Float getIntersectionPoint(java.awt.geom.Line2D.Float line)
Returns the interection point of this line with the specified line.


getIntersectionPoint

public java.awt.geom.Point2D.Float getIntersectionPoint(java.awt.geom.Line2D.Float line,
                                                        java.awt.geom.Point2D.Float intersection)
Returns the interection of this line with the specified line. If interesection is null, a new point is created.