mwg API
    Preparing search index...

    Function pixelToHex

    • The hex cell under a pixel position - the inverse of hexToPixel.

      The answer is the nearest cell centre, searched over the cells around the one the pixel looks like it is in, and that is deliberate: a hexagonal tiling has no ties, the containing cell is the nearest centre, and a search needs no second set of formulas to stay the inverse of the four orientation-and-offset combinations above. A closed-form inverse would be four more chances to be subtly wrong at a hex's edge, where a click has to land somewhere sensible.

      Parameters

      • px: number
      • py: number
      • tileWidth: number
      • tileHeight: number
      • shape: HexShape = {}

      Returns HexCoord