flatworld.extensions.hexagons.utils Class
Utility module, for making different calculations and tests when hexagon based grid map in use
Item Index
Methods
- _pointInPolygon static
- calcLongDiagonal static
- calcLongDiagonal static
- calcSpecialDistance static
- createHexagonGridCoordinates static
- getClosestHexagonCenter static
- getHexagonPoints static
- hexaHitTest static
- setRadius static
Methods
_pointInPolygon
-
point
-
hitCoords.x
-
hitCoords.y
-
vs
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
ObjectThe coordinates to test against
-
hitCoords.x
IntegerX coordinate
-
hitCoords.y
IntegerY coordinate
-
vs
IntegerThe points of the polygon to test [0] === x-point, [1] === y-point
Returns:
Is the coordinate inside the hexagon or not
calcLongDiagonal
-
{}
Calculates the hexagons: innerDiameter
- Vertical / Flat hexagons height
- Horizontal / pointy hexagons width
calcLongDiagonal
-
{}
outerDiameter
- Vertical / Flat hexagons width
- Horizontal / pointy hexagons height
calcSpecialDistance
-
{}
Parameters:
-
{}
ObjectOPTIONAL
-
radius
FloatUsually the radius of the hexagon
-
createHexagonGridCoordinates
-
gridSize
-
{}
Create Array that holds the coordinates for the size of hexagon grid we want to create.
Returns:
Array that holds the coordinates for the hexagon grid, like [{x: ?, y: ?}]
getClosestHexagonCenter
-
coordinates
Calculates the closest hexagon center coordinates, for the given coordinates. So aligning the given coordinates to proper hexagon coordinates
Parameters:
-
coordinates
ObjectThe coordinate where we want to find the closest hexagon center point
getHexagonPoints
-
radius
-
options
Parameters:
-
radius
Floatradius of the hexagon
-
options
Objectextra options, like generating horizontal hexagon points and how many decimals to round
hexaHitTest
-
points
-
hitCoords
-
offsetCoords
Test do the given coordinates hit the hexagon, given by the points container / array
Parameters:
-
points
PIXI.PointArray of PIXI.points
-
hitCoords
ObjectThe coordinates to test against
-
x
IntegerX coordinate
-
y
IntegerY coordinate
-
-
offsetCoords
ObjectOPTIONAL offsetCoordinates that are added to the hitCoordinates. Separate because these are outside the given array.
-
x
IntegerX coordinate
-
y
IntegerY coordinate
-
Returns:
Is the coordinate inside the hexagon or not