com.threerings.geom
Class GeomUtil

java.lang.Object
  extended by com.threerings.geom.GeomUtil

public class GeomUtil
extends Object

General geometry utilities.


Constructor Summary
GeomUtil()
           
 
Method Summary
static int dot(int vsx, int vsy, int v1ex, int v1ey, int v2ex, int v2ey)
          Computes and returns the dot product of the two vectors.
static int dot(int v1sx, int v1sy, int v1ex, int v1ey, int v2sx, int v2sy, int v2ex, int v2ey)
          Computes and returns the dot product of the two vectors.
static int dot(Point vs, Point v1e, Point v2e)
          Computes and returns the dot product of the two vectors.
static int dot(Point v1s, Point v1e, Point v2s, Point v2e)
          Computes and returns the dot product of the two vectors.
static Rectangle getTile(int width, int height, int tileWidth, int tileHeight, int tileIndex)
          Returns the rectangle containing the specified tile in the supplied larger rectangle.
static void getTile(int width, int height, int tileWidth, int tileHeight, int tileIndex, Rectangle bounds)
          Fills in the bounds of the specified tile in the supplied larger rectangle.
static Rectangle grow(Rectangle source, Rectangle target)
          Adds the target rectangle to the bounds of the source rectangle.
static boolean lineIntersection(Point2D p1, Point2D p2, boolean seg1, Point2D p3, Point2D p4, boolean seg2, Point2D result)
          Calculate the intersection of two lines.
static Point nearestToLine(Point p1, Point p2, Point p3, Point n)
          Computes the point nearest to the specified point p3 on the line defined by the two points p1 and p2.
static void shiftToContain(Rectangle tainer, Rectangle tained)
          Shifts the position of the tainer rectangle to ensure that it contains the tained rectangle.
static int whichSide(Point p1, double theta, Point p2)
          Returns less than zero if p2 is on the left hand side of the line created by p1 and theta and greater than zero if it is on the right hand side.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GeomUtil

public GeomUtil()
Method Detail

dot

public static int dot(Point v1s,
                      Point v1e,
                      Point v2s,
                      Point v2e)
Computes and returns the dot product of the two vectors.

Parameters:
v1s - the starting point of the first vector.
v1e - the ending point of the first vector.
v2s - the starting point of the second vector.
v2e - the ending point of the second vector.

dot

public static int dot(int v1sx,
                      int v1sy,
                      int v1ex,
                      int v1ey,
                      int v2sx,
                      int v2sy,
                      int v2ex,
                      int v2ey)
Computes and returns the dot product of the two vectors. See dot(Point,Point,Point,Point) for an explanation of the arguments


dot

public static int dot(Point vs,
                      Point v1e,
                      Point v2e)
Computes and returns the dot product of the two vectors. The vectors are assumed to start with the same coordinate and end with different coordinates.

Parameters:
vs - the starting point of both vectors.
v1e - the ending point of the first vector.
v2e - the ending point of the second vector.

dot

public static int dot(int vsx,
                      int vsy,
                      int v1ex,
                      int v1ey,
                      int v2ex,
                      int v2ey)
Computes and returns the dot product of the two vectors. See dot(Point,Point,Point) for an explanation of the arguments


nearestToLine

public static Point nearestToLine(Point p1,
                                  Point p2,
                                  Point p3,
                                  Point n)
Computes the point nearest to the specified point p3 on the line defined by the two points p1 and p2. The computed point is stored into n. Note: p1 and p2 must not be coincident.

Parameters:
p1 - one point on the line.
p2 - another point on the line (not equal to p1).
p3 - the point to which we wish to be most near.
n - the point on the line defined by p1 and p2 that is nearest to p.
Returns:
the point object supplied via n.

lineIntersection

public static boolean lineIntersection(Point2D p1,
                                       Point2D p2,
                                       boolean seg1,
                                       Point2D p3,
                                       Point2D p4,
                                       boolean seg2,
                                       Point2D result)
Calculate the intersection of two lines. Either line may be considered as a line segment, and the intersecting point is only considered valid if it lies upon the segment. Note that Point extends Point2D.

Parameters:
p1 - and p2 the coordinates of the first line.
seg1 - if the first line should be considered a segment.
p3 - and p4 the coordinates of the second line.
seg2 - if the second line should be considered a segment.
result - the point that will be filled in with the intersecting point.
Returns:
true if result was filled in, or false if the lines are parallel or the point of intersection lies outside of a segment.

whichSide

public static int whichSide(Point p1,
                            double theta,
                            Point p2)
Returns less than zero if p2 is on the left hand side of the line created by p1 and theta and greater than zero if it is on the right hand side. In theory, it will return zero if the point is on the line, but due to rounding errors it almost always decides that it's not exactly on the line.

Parameters:
p1 - the point on the line whose side we're checking.
theta - the (logical) angle defining the line.
p2 - the point that lies on one side or the other of the line.

shiftToContain

public static void shiftToContain(Rectangle tainer,
                                  Rectangle tained)
Shifts the position of the tainer rectangle to ensure that it contains the tained rectangle. The tainer rectangle must be larger than or equal to the size of the tained rectangle.


grow

public static Rectangle grow(Rectangle source,
                             Rectangle target)
Adds the target rectangle to the bounds of the source rectangle. If the source rectangle is null, a new rectangle is created that is the size of the target rectangle.

Returns:
the source rectangle.

getTile

public static Rectangle getTile(int width,
                                int height,
                                int tileWidth,
                                int tileHeight,
                                int tileIndex)
Returns the rectangle containing the specified tile in the supplied larger rectangle. Tiles go from left to right, top to bottom.


getTile

public static void getTile(int width,
                           int height,
                           int tileWidth,
                           int tileHeight,
                           int tileIndex,
                           Rectangle bounds)
Fills in the bounds of the specified tile in the supplied larger rectangle. Tiles go from left to right, top to bottom.