API Docs for: 0.1.1
Show:

flatworld.extensions.hexagons.utils Class

Utility module, for making different calculations and tests when hexagon based grid map in use

Methods

_pointInPolygon

(
  • point
  • hitCoords.x
  • hitCoords.y
  • vs
)
Boolean private static

credits to: https://github.com/substack/point-in-polygon Tests whether the given point / coordinate is inside the given points. Assuming the points form a polygon

Parameters:

  • point Object

    The coordinates to test against

  • hitCoords.x Integer

    X coordinate

  • hitCoords.y Integer

    Y coordinate

  • vs Integer

    The points of the polygon to test [0] === x-point, [1] === y-point

Returns:

Boolean:

Is the coordinate inside the hexagon or not

calcLongDiagonal

(
  • {}
)
static

Calculates the hexagons: innerDiameter

  • Vertical / Flat hexagons height
  • Horizontal / pointy hexagons width

Parameters:

  • {} Object

    OPTIONAL

    • radius Float

      Usually the radius of the hexagon

    • type String

      If you provide something else than radius, where the calculation is based from

calcLongDiagonal

(
  • {}
)
static

outerDiameter

  • Vertical / Flat hexagons width
  • Horizontal / pointy hexagons height

Parameters:

  • {} Object

    OPTIONAL

    • radius Float

      Usually the radius of the hexagon

    • type String

      If you provide something else than radius, where the calculation is based from

calcSpecialDistance

(
  • {}
)
static

Parameters:

  • {} Object

    OPTIONAL

    • radius Float

      Usually the radius of the hexagon

createHexagonGridCoordinates

(
  • gridSize
  • {}
)
static

Create Array that holds the coordinates for the size of hexagon grid we want to create.

Parameters:

  • gridSize Object
    • rows Object

      The count of rows in the hexagon grid

    • columns Object

      The count of columns in the hexagon grid

  • {} Object

    OPTIONAL configurations in an object

    • radius Number

      The radius of hexagon. Basically the radius of the outer edges / circle of the hexagon.

    • orientation String

      Is it horizontal or vertical hexagon grid. Default: horizontal

Returns:

:

Array that holds the coordinates for the hexagon grid, like [{x: ?, y: ?}]

getClosestHexagonCenter

(
  • coordinates
)
static

Calculates the closest hexagon center coordinates, for the given coordinates. So aligning the given coordinates to proper hexagon coordinates

Parameters:

  • coordinates Object

    The coordinate where we want to find the closest hexagon center point

getHexagonPoints

(
  • radius
  • options
)
static

Parameters:

  • radius Float

    radius of the hexagon

  • options Object

    extra options, like generating horizontal hexagon points and how many decimals to round

hexaHitTest

(
  • points
  • hitCoords
  • offsetCoords
)
Boolean static

Test do the given coordinates hit the hexagon, given by the points container / array

Parameters:

  • points PIXI.Point

    Array of PIXI.points

  • hitCoords Object

    The coordinates to test against

    • x Integer

      X coordinate

    • y Integer

      Y coordinate

  • offsetCoords Object

    OPTIONAL offsetCoordinates that are added to the hitCoordinates. Separate because these are outside the given array.

    • x Integer

      X coordinate

    • y Integer

      Y coordinate

Returns:

Boolean:

Is the coordinate inside the hexagon or not

setRadius

(
  • radius
)
static

Set hexagon radius

Parameters:

  • radius Number

    The radius of the hexagon