org.newdawn.slick.geom
Class Line

java.lang.Object
  extended by org.newdawn.slick.geom.Shape
      extended by org.newdawn.slick.geom.Line
All Implemented Interfaces:
java.io.Serializable

public class Line
extends Shape

Implemenation of a bunch of maths functions to do with lines. Note that lines can't be used as dynamic shapes right now - also collision with the end of a line is undefined.

Author:
Kevin Glass
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.newdawn.slick.geom.Shape
boundingCircleRadius, center, maxX, maxY, minX, minY, points, pointsDirty, trianglesDirty, tris, x, y
 
Constructor Summary
Line(float[] start, float[] end)
          Create a new line based on two points
Line(float x, float y)
          Create a new line based on the origin and a single point
Line(float x, float y, boolean inner, boolean outer)
          Create a new line based on the origin and a single point
Line(float x1, float y1, float x2, float y2)
          Create a new line based on two points
Line(float x1, float y1, float dx, float dy, boolean dummy)
          Create a line with relative second point
Line(Vector2f start, Vector2f end)
          Create a new line based on two points
 
Method Summary
 boolean closed()
          True if this is a closed shape
protected  void createPoints()
          Subclasses implement this to create the points of the shape.
 float distance(Vector2f point)
          Get the shortest distance from a point to this line
 float distanceSquared(Vector2f point)
          Get the shortest distance squared from a point to this line
 void getClosestPoint(Vector2f point, Vector2f result)
          Get the closest point on the line to a given point
 float getDX()
          Get the x direction of this line
 float getDY()
          Get the y direction of this line
 Vector2f getEnd()
          Get the end point of the line
 Vector2f getStart()
          Get the start point of the line
 float getX()
          Get the x location of the left side of this shape.
 float getX1()
          Get the x coordinate of the start point
 float getX2()
          Get the x coordinate of the end point
 float getY()
          Get the y position of the top of this shape.
 float getY1()
          Get the y coordinate of the start point
 float getY2()
          Get the y coordinate of the end point
 Vector2f intersect(Line other)
          Intersect this line with another
 Vector2f intersect(Line other, boolean limit)
          Intersect this line with another
 boolean intersect(Line other, boolean limit, Vector2f result)
          Intersect this line with another
 boolean intersects(Shape shape)
          Check if this shape intersects with the shape provided.
 float length()
          Find the length of the line
 float lengthSquared()
          Find the length of the line squared (cheaper and good for comparisons)
 boolean on(Vector2f point)
          Check if the given point is on the line
 void set(float[] start, float[] end)
          Configure the line
 void set(float sx, float sy, float ex, float ey)
          Configure the line without garbage
 void set(Vector2f start, Vector2f end)
          Configure the line
 java.lang.String toString()
           
 Shape transform(Transform transform)
          Apply a transformation and return a new shape.
 
Methods inherited from class org.newdawn.slick.geom.Shape
calculateRadius, calculateTriangles, checkPoints, contains, contains, findCenter, getBoundingCircleRadius, getCenter, getCenterX, getCenterY, getHeight, getLocation, getMaxX, getMaxY, getMinX, getMinY, getNormal, getPoint, getPointCount, getPoints, getTriangles, getWidth, hasVertex, includes, increaseTriangulation, indexOf, preCache, prune, setCenterX, setCenterY, setLocation, setLocation, setX, setY, subtract, union
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Line

public Line(float x,
            float y,
            boolean inner,
            boolean outer)
Create a new line based on the origin and a single point

Parameters:
x - The end point of the line
y - The end point of the line
inner - True if this line blocks on it's inner edge
outer - True if this line blocks on it's outer edge

Line

public Line(float x,
            float y)
Create a new line based on the origin and a single point

Parameters:
x - The end point of the line
y - The end point of the line

Line

public Line(float x1,
            float y1,
            float x2,
            float y2)
Create a new line based on two points

Parameters:
x1 - The x coordinate of the start point
y1 - The y coordinate of the start point
x2 - The x coordinate of the end point
y2 - The y coordinate of the end point

Line

public Line(float x1,
            float y1,
            float dx,
            float dy,
            boolean dummy)
Create a line with relative second point

Parameters:
x1 - The x coordinate of the start point
y1 - The y coordinate of the start point
dx - The x change to get to the second point
dy - The y change to get to the second point
dummy - A dummy value

Line

public Line(float[] start,
            float[] end)
Create a new line based on two points

Parameters:
start - The start point
end - The end point

Line

public Line(Vector2f start,
            Vector2f end)
Create a new line based on two points

Parameters:
start - The start point
end - The end point
Method Detail

set

public void set(float[] start,
                float[] end)
Configure the line

Parameters:
start - The start point of the line
end - The end point of the line

getStart

public Vector2f getStart()
Get the start point of the line

Returns:
The start point of the line

getEnd

public Vector2f getEnd()
Get the end point of the line

Returns:
The end point of the line

length

public float length()
Find the length of the line

Returns:
The the length of the line

lengthSquared

public float lengthSquared()
Find the length of the line squared (cheaper and good for comparisons)

Returns:
The length of the line squared

set

public void set(Vector2f start,
                Vector2f end)
Configure the line

Parameters:
start - The start point of the line
end - The end point of the line

set

public void set(float sx,
                float sy,
                float ex,
                float ey)
Configure the line without garbage

Parameters:
sx - The x coordinate of the start
sy - The y coordinate of the start
ex - The x coordiante of the end
ey - The y coordinate of the end

getDX

public float getDX()
Get the x direction of this line

Returns:
The x direction of this line

getDY

public float getDY()
Get the y direction of this line

Returns:
The y direction of this line

getX

public float getX()
Description copied from class: Shape
Get the x location of the left side of this shape.

Overrides:
getX in class Shape
Returns:
The x location of the left side of this shape.
See Also:
Shape.getX()

getY

public float getY()
Description copied from class: Shape
Get the y position of the top of this shape.

Overrides:
getY in class Shape
Returns:
The y position of the top of this shape.
See Also:
Shape.getY()

getX1

public float getX1()
Get the x coordinate of the start point

Returns:
The x coordinate of the start point

getY1

public float getY1()
Get the y coordinate of the start point

Returns:
The y coordinate of the start point

getX2

public float getX2()
Get the x coordinate of the end point

Returns:
The x coordinate of the end point

getY2

public float getY2()
Get the y coordinate of the end point

Returns:
The y coordinate of the end point

distance

public float distance(Vector2f point)
Get the shortest distance from a point to this line

Parameters:
point - The point from which we want the distance
Returns:
The distance from the line to the point

on

public boolean on(Vector2f point)
Check if the given point is on the line

Parameters:
point - The point to check
Returns:
True if the point is on this line

distanceSquared

public float distanceSquared(Vector2f point)
Get the shortest distance squared from a point to this line

Parameters:
point - The point from which we want the distance
Returns:
The distance squared from the line to the point

getClosestPoint

public void getClosestPoint(Vector2f point,
                            Vector2f result)
Get the closest point on the line to a given point

Parameters:
point - The point which we want to project
result - The point on the line closest to the given point

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

intersect

public Vector2f intersect(Line other)
Intersect this line with another

Parameters:
other - The other line we should intersect with
Returns:
The intersection point or null if the lines are parallel

intersect

public Vector2f intersect(Line other,
                          boolean limit)
Intersect this line with another

Parameters:
other - The other line we should intersect with
limit - True if the collision is limited to the extent of the lines
Returns:
The intersection point or null if the lines don't intersect

intersect

public boolean intersect(Line other,
                         boolean limit,
                         Vector2f result)
Intersect this line with another

Parameters:
other - The other line we should intersect with
limit - True if the collision is limited to the extent of the lines
result - The resulting intersection point if any
Returns:
True if the lines intersect

createPoints

protected void createPoints()
Description copied from class: Shape
Subclasses implement this to create the points of the shape.

Specified by:
createPoints in class Shape
See Also:
Shape.createPoints()

transform

public Shape transform(Transform transform)
Description copied from class: Shape
Apply a transformation and return a new shape. This will not alter the current shape but will return the transformed shape.

Specified by:
transform in class Shape
Parameters:
transform - The transform to be applied
Returns:
The transformed shape.
See Also:
Shape.transform(org.newdawn.slick.geom.Transform)

closed

public boolean closed()
Description copied from class: Shape
True if this is a closed shape

Overrides:
closed in class Shape
Returns:
True if this is a closed shape
See Also:
Shape.closed()

intersects

public boolean intersects(Shape shape)
Description copied from class: Shape
Check if this shape intersects with the shape provided.

Overrides:
intersects in class Shape
Parameters:
shape - The shape to check if it intersects with this one.
Returns:
True if the shapes do intersect, false otherwise.
See Also:
Shape.intersects(org.newdawn.slick.geom.Shape)


Copyright © 2006 New Dawn Software. All Rights Reserved.