Class IdealHex

java.lang.Object
megamek.common.IdealHex

public class IdealHex extends 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

    Fields
    Modifier and Type
    Field
    Description
    double
     
    double
     
    static final int
     
    static final int
     
    static final int
     
    double[]
     
    double[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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 Details

  • Constructor Details

    • IdealHex

      public IdealHex(Coords c)
  • 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

      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.