megamek.common
Class IdealHex

java.lang.Object
  extended by megamek.common.IdealHex

public class IdealHex
extends java.lang.Object

Represents a hex, not in the game but in an ideal coordinate system. Used for Compute.intervening() calculations and a few others. This ideal hex is 2.0 units tall. Tries to keep a cache of IdealHexes requested, as intervening() sure wants a lot of hexes sometimes.


Field Summary
 double cx
           
 double cy
           
static int LEFT
           
static int RIGHT
           
static int STRAIGHT
           
 double[] x
           
 double[] y
           
 
Constructor Summary
IdealHex(Coords c)
           
 
Method Summary
static void ensureCacheSize(int width, int height)
          Ensures that the cache will be at least the specified dimensions.
static IdealHex get(Coords coords)
          Gets a hex from the cache, if it exists in the cache.
 boolean isIntersectedBy(double x0, double y0, double x1, double y1)
          Returns true if this hex is intersected by the line
static int turns(double x0, double y0, double x1, double y1, double x2, double y2)
          Tests whether a line intersects a point or the point passes to the left or right of the line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEFT

public static final int LEFT
See Also:
Constant Field Values

STRAIGHT

public static final int STRAIGHT
See Also:
Constant Field Values

RIGHT

public static final int RIGHT
See Also:
Constant Field Values

x

public double[] x

y

public double[] y

cx

public double cx

cy

public double cy
Constructor Detail

IdealHex

public IdealHex(Coords c)
Method Detail

isIntersectedBy

public boolean isIntersectedBy(double x0,
                               double y0,
                               double x1,
                               double y1)
Returns true if this hex is intersected by the line


turns

public static int turns(double x0,
                        double y0,
                        double x1,
                        double y1,
                        double x2,
                        double y2)
Tests whether a line intersects a point or the point passes to the left or right of the line. Deals with floating point imprecision. Thx deadeye00 (Derek Evans)


ensureCacheSize

public static void ensureCacheSize(int width,
                                   int height)
Ensures that the cache will be at least the specified dimensions. If it is not, a new cache is created. Hopefully this won't happen too much. Must be called at least once before get(), since the initial size is 0.


get

public static IdealHex get(Coords coords)
Gets a hex from the cache, if it exists in the cache. If the hex is not cached yet, creates it. If the cache is too small, does not resize it.