Package megamek.common
Class IdealHex
java.lang.Object
megamek.common.IdealHex
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
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidensureCacheSize(int width, int height) Ensures that the cache will be at least the specified dimensions.static IdealHexGets a hex from the cache, if it exists in the cache.booleanisIntersectedBy(double x0, double y0, double x1, double y1) Returns true if this hex is intersected by the linestatic intturns(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.
-
Field Details
-
LEFT
public static final int LEFT- See Also:
-
STRAIGHT
public static final int STRAIGHT- See Also:
-
RIGHT
public static final int RIGHT- See Also:
-
x
public double[] x -
y
public double[] y -
cx
public double cx -
cy
public double cy
-
-
Constructor Details
-
IdealHex
-
-
Method Details
-
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
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.
-