ch.aplu.jgamegrid
Class GGLine

java.lang.Object
  extended by ch.aplu.jgamegrid.GGLine

public class GGLine
extends java.lang.Object

Class representing a line segment. Start and endpoint are given by a GGVector.


Constructor Summary
GGLine(GGLine line)
          Creates a new GGLine from given GGLine.
GGLine(GGVector[] vertexes)
          Creates a new GGLine from given start and end point vertexes.
GGLine(GGVector startVector, GGVector endVector)
          Creates a new GGLine from given start and end point.
 
Method Summary
 GGLine clone()
          Returns a new GGLine with same start and end vector.
static java.awt.Point getDividingPoint(java.awt.Point pt1, java.awt.Point pt2, double ratio)
          Returns the point on the line through the point pt1 and the point pt2 that is in distance ratio times the length from pt1 to pt2 from pt1.
 java.awt.Point getEndPoint()
          Returns the end point (GGVector components casted to int).
 GGVector getEndVector()
          Returns the end vector.
 java.awt.Point getStartPoint()
          Returns the start point (GGVector components casted to int).
 GGVector getStartVector()
          Returns the start vector.
 GGVector[] getVertexes()
          Returns the vertexes of the line (startVector, endVector).
 boolean isIntersecting(GGCircle circle)
          Returns true if the current line intersects with the given circle.
 boolean isIntersecting(GGLine line)
          Returns true if the current line segment intersects with the given line segment.
 boolean isIntersecting(GGVector v, double error)
          Returns true if the given point is part of the line segment.
 boolean isIntersecting(GGVector imageCenter, double imageDirection, java.awt.image.BufferedImage image, boolean isRotatable)
          Returns true, if at least one point of the line segment (casted to int values) points to a non-transparant pixel of the given image.
 java.lang.String toString()
          Returns a string that enumerates start and end vector.
 void translate(GGVector v)
          Performs a translation by the given vector.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GGLine

public GGLine(GGLine line)
Creates a new GGLine from given GGLine.

Parameters:
line - the line from where the values of start and end point are copied

GGLine

public GGLine(GGVector startVector,
              GGVector endVector)
Creates a new GGLine from given start and end point.

Parameters:
startVector - the vector to the start of the line
endVector - the vector to the end of the line

GGLine

public GGLine(GGVector[] vertexes)
Creates a new GGLine from given start and end point vertexes.

Parameters:
vertexes - an array of the start and end point vertex
Method Detail

getStartVector

public GGVector getStartVector()
Returns the start vector.

Returns:
a clone of the start point

getEndVector

public GGVector getEndVector()
Returns the end vector.

Returns:
a clone of the end point

getStartPoint

public java.awt.Point getStartPoint()
Returns the start point (GGVector components casted to int).

Returns:
the start point

getEndPoint

public java.awt.Point getEndPoint()
Returns the end point (GGVector components casted to int).

Returns:
the end point

getVertexes

public GGVector[] getVertexes()
Returns the vertexes of the line (startVector, endVector).

Returns:
a clone of the vertexes

translate

public void translate(GGVector v)
Performs a translation by the given vector.

Parameters:
v - the translation vector

clone

public GGLine clone()
Returns a new GGLine with same start and end vector.

Overrides:
clone in class java.lang.Object
Returns:
a clone of the original line

toString

public java.lang.String toString()
Returns a string that enumerates start and end vector.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the line

isIntersecting

public boolean isIntersecting(GGLine line)
Returns true if the current line segment intersects with the given line segment.

Parameters:
line - the line to be checked for intersection with the current line
Returns:
true, if the two lines intersects; otherwise false

isIntersecting

public boolean isIntersecting(GGVector v,
                              double error)
Returns true if the given point is part of the line segment.

Parameters:
v - the vector to be checked if its end-point lays on line segment
error - the error interval for the floating point comparism
Returns:
true, if the point is part of the line segment

isIntersecting

public boolean isIntersecting(GGCircle circle)
Returns true if the current line intersects with the given circle.

Parameters:
circle - the circle to be checked for intersection with the current line
Returns:
true, if the two figures intersects; otherwise false

isIntersecting

public boolean isIntersecting(GGVector imageCenter,
                              double imageDirection,
                              java.awt.image.BufferedImage image,
                              boolean isRotatable)
Returns true, if at least one point of the line segment (casted to int values) points to a non-transparant pixel of the given image.

Parameters:
imageCenter - the vector to the center of the image
imageDirection - the direction of the image (angle of edge ulx --> uly with respect to the positive x-direction (0..2*pi))
image - the buffered image
isRotatable - if true, the imageDirection is considered; otherwise imageDirection = 0 is assumed
Returns:
true, if the line segment intersects with non-transparent pixels of the image

getDividingPoint

public static java.awt.Point getDividingPoint(java.awt.Point pt1,
                                              java.awt.Point pt2,
                                              double ratio)
Returns the point on the line through the point pt1 and the point pt2 that is in distance ratio times the length from pt1 to pt2 from pt1. For ratio < 0 the point is in the opposite direction.

Parameters:
pt1 - the start point of the line section
pt2 - the end point of the line section
ratio - the distance ratio (any negative or positive double value)
Returns:
the dividing point (rounded to int)