org.starhope.appius.physica
Class Geometry

java.lang.Object
  extended by org.starhope.appius.physica.Geometry

public class Geometry
extends Object

Collection of useful geometric routines

Author:
brpocock@star-hope.org, edward.winkelman@gmail.com

Constructor Summary
Geometry()
           
 
Method Summary
static void deltaV(AbstractUser toMove, double ddX, double ddY, double rate)
           
static Point2D getExitPoint(AbstractUser u, Room room, double destX, double destY)
          WRITEME: Document this method brpocock@star-hope.org
static Point2D getExitPoint(Line2D line, GeneralPath space)
          Find the first (of what could, potentially, be several) point at which a given line segment crosses any boundary of the supplied space(s).
static Point2D.Double getIntersectionPoint(Line2D line1, Line2D line2)
          intersection point of two line segments
static Coord2D getRandomPointWithin(Polygon space)
           
static long getTimeToTarget(AbstractUser thing, long when)
          WRITEME: Document this method brpocock@star-hope.org
static List<Point2D> getVertices(Polygon inner)
           
static Set<Polygon> simplify(Set<Polygon> positive, Set<Polygon> negative)
           
static GeneralPath squash(Collection<GeneralPath> positive, Collection<GeneralPath> negative)
           
static GeneralPath squash(Set<GeneralPath> positive, Set<GeneralPath> negative)
           
static String stringify(double d1, double d2)
          Stringifies a pair of doubles representing a coordinate point
static String stringify(GeneralPath path)
          Stringifies a general path in the format of (x,y~x,y~~x,y~x,y) Where x,y are coordinate pairs and ~~ denotes discontinuous spaces
static String stringify(Point2D p)
          Stringifies a 2D coordinate point
static GeneralPath stringToGeneralPath(String polyString)
          convert a string into a GeneralPath
static Collection<GeneralPath> stringToGeneralPathSet(String polyString)
          Takes a string and turns it into a collection of GeneralPaths
static Polygon stringToNewPolygon(String string)
           
static Polygon stringToPolygon(String polyString)
          Deprecated. 
private static Area toArea(Set<Polygon> positive)
           
private static GeneralPath toGeneralPath(Area area)
           
static Set<Polygon> toPolygon(Area area)
           
static long updateUserPositioning(AbstractUser thing)
          WRITEME: Document this method brpocock@star-hope.org
static long updateUserPositioning(AbstractUser thing, long when)
          WRITEME: Document this method brpocock@star-hope.org
static long updateUserPositioning(AbstractUser thing, long when, boolean sideEffects)
          Determine the object's current position, and the time until it reaches its target (from now).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Geometry

public Geometry()
Method Detail

deltaV

public static void deltaV(AbstractUser toMove,
                          double ddX,
                          double ddY,
                          double rate)
Parameters:
toMove - WRITEME
ddX - WRITEME
ddY - WRITEME
rate - WRITEME

getExitPoint

public static Point2D getExitPoint(AbstractUser u,
                                   Room room,
                                   double destX,
                                   double destY)
                            throws GameLogicException
WRITEME: Document this method brpocock@star-hope.org

Parameters:
u - the user, currently in a walkable space
room - the room in which the user is standing
destX - WRITEME
destY - WRITEME
Returns:
the point at which the line crosses out of the walkable spaces of the room
Throws:
GameLogicException - if the user isn't in the room

getExitPoint

public static Point2D getExitPoint(Line2D line,
                                   GeneralPath space)
                            throws NotFoundException
Find the first (of what could, potentially, be several) point at which a given line segment crosses any boundary of the supplied space(s).

Parameters:
line - the line to be tested
space - the space against which to test it
Returns:
the point of intersection of the line with any edge of the space
Throws:
NotFoundException - if the line does not cross the boundaries of the space

getIntersectionPoint

public static Point2D.Double getIntersectionPoint(Line2D line1,
                                                  Line2D line2)
intersection point of two line segments

Parameters:
line1 - one line
line2 - another line
Returns:
the point at which those lines intersect, or null if they are parallel

getRandomPointWithin

public static Coord2D getRandomPointWithin(Polygon space)
Parameters:
space - some space
Returns:
a random point within that space

getTimeToTarget

public static long getTimeToTarget(AbstractUser thing,
                                   long when)
WRITEME: Document this method brpocock@star-hope.org

Parameters:
thing - WRITEME
when - WRITEME
Returns:
WRITEME

getVertices

public static List<Point2D> getVertices(Polygon inner)
Parameters:
inner - WRITEME
Returns:
WRITEME

simplify

public static Set<Polygon> simplify(Set<Polygon> positive,
                                    Set<Polygon> negative)
Parameters:
positive - inclusive polys
negative - exclusive polys
Returns:
simplified set

squash

public static GeneralPath squash(Collection<GeneralPath> positive,
                                 Collection<GeneralPath> negative)
Parameters:
positive - positive spaces to collapse
negative - negative spaces to collapse
Returns:
a path explaining them all away

squash

public static GeneralPath squash(Set<GeneralPath> positive,
                                 Set<GeneralPath> negative)
Parameters:
positive - positive spaces to collapse
negative - negative spaces to collapse
Returns:
a path explaining them all away

stringify

public static String stringify(double d1,
                               double d2)
Stringifies a pair of doubles representing a coordinate point

Parameters:
d1 - x ordinate
d2 - y abessa
Returns:
a string x "," y.

stringify

public static String stringify(GeneralPath path)
Stringifies a general path in the format of (x,y~x,y~~x,y~x,y) Where x,y are coordinate pairs and ~~ denotes discontinuous spaces

Parameters:
path - The path to stringify
Returns:
A stringified version of the path

stringify

public static String stringify(Point2D p)
Stringifies a 2D coordinate point

Parameters:
p - a 2D point
Returns:
x "," y.

stringToGeneralPath

public static GeneralPath stringToGeneralPath(String polyString)
convert a string into a GeneralPath

Parameters:
polyString - the polygon string
Returns:
a GeneralPath represented by the polygon string
Throws:
NumberFormatException - if the string has invalid numbers

stringToGeneralPathSet

public static Collection<GeneralPath> stringToGeneralPathSet(String polyString)
Takes a string and turns it into a collection of GeneralPaths

Parameters:
polyString - The string to convert
Returns:
A set of GeneralPaths

stringToNewPolygon

public static Polygon stringToNewPolygon(String string)
Parameters:
string - a polygon specifier string
Returns:
an Appius polygon from the given string

stringToPolygon

@Deprecated
public static Polygon stringToPolygon(String polyString)
Deprecated. 

WRITEME: Document this method brpocock@star-hope.org

Parameters:
polyString - WRITEME
Returns:
WRITEME
Throws:
NumberFormatException - WRITEME

toArea

private static Area toArea(Set<Polygon> positive)
Parameters:
positive - a set of polygons to be included
Returns:
the polygon set as an area

toGeneralPath

private static GeneralPath toGeneralPath(Area area)
Parameters:
area - area
Returns:
path

toPolygon

public static Set<Polygon> toPolygon(Area area)
Parameters:
area - a polygon area
Returns:
a polygon set

updateUserPositioning

public static long updateUserPositioning(AbstractUser thing)
WRITEME: Document this method brpocock@star-hope.org

Parameters:
thing - WRITEME
Returns:
WRITEME

updateUserPositioning

public static long updateUserPositioning(AbstractUser thing,
                                         long when)
WRITEME: Document this method brpocock@star-hope.org

Parameters:
thing - WRITEME
when - WRITEME
Returns:
WRITEME

updateUserPositioning

public static long updateUserPositioning(AbstractUser thing,
                                         long when,
                                         boolean sideEffects)
Determine the object's current position, and the time until it reaches its target (from now). Note that this is the preferred routine to be used to update the position of an object

Parameters:
thing - what is moving
when - what time is it now
sideEffects - if false, don't execute any side-effect corrections: just return the time to travel
Returns:
how long until it gets there