hex_toolkit library

Classes

Cube
Smart representation of a hexagon in a hexagonal grid, positioned on three axis. Very practical for a lots of algorithms. Sum of these coordinates is always 0, so technically only q and r are actually necessary (these are called axial coordinates, see Cube.fromAxial)). See https://www.redblobgames.com/grids/hexagons/#coordinates for more information.
Easing
Common easing functions
GridOffset
Rather impractical representation of a hexagon in a hexagonal grid, positioned by q (column) and r (row) coordinates. "Zero" hexagon is in the top left corner. Odd rows (columns) are shifted to the right (down). See https://www.redblobgames.com/grids/hexagons/#coordinates for more information.
Hex
An immutable abstraction of a hexagon in a hexagonal grid.
HexPath
This is a path from one hex to another. It contains the total cost of the path, and the list of hexes that make up the path. See Hex.cheapestPathTo for more details.
PixelPoint
This class represents a point on a screen or canvas. Easily convert it to Flutter Offset (Offset(pixel.x, pixel.y)) or whatever object your framework desires.

Enums

GridLayout
Two possible layouts of a hexagonal grid, which are used to convert between cube and offset coordinates, or when actually drawing the grid. In https://www.redblobgames.com/grids/hexagons/ these are called "odd-r" (pointy) and "odd-q" (flat).

Functions

areaHeight(Iterable<Hex> area) int
areaWidth(Iterable<Hex> area) int
connectedClusters(Iterable<Hex> candidates) List<List<Hex>>
cubeDistance(Cube a, Cube b) int
Distance of two cubes in "steps".
cubeLerp(Cube a, Cube b, double t) Cube
Linear interpolation between two cubes.
cubeLinedraw(Cube a, Cube b) List<Cube>
Returns a list of cubes between two cubes.
cubeRound(double q, double r, double s) Cube
Rounds a 'double' cube to the nearest 'int' cube.
findCheapestPath(Hex from, Hex to, MoveCost costFunction, int maximumDistanceTo) HexPath?
Find the cheapest path from from to to using costFunction. Djikstra's algorithm.
segmentsIterator<T>(List<T> path, int segmentSize) Iterable<Iterable<T>>
Returns moving window of segments of defined size. With path a,b,c,d,e and segmentSize 3, this method returns: [a,b,c, b,c,d, c,d,e]. If the segments size is bigger then the path length, the method returns the whole path as a one segment.
setRandomSeed(int seed) → void
This global function allows you to enforce repeatable random results within this library. You should set this seed only once and before first the 'random' method call.

Typedefs

CubeFilter = bool Function(Cube cube)
Filter function for cube coordinates. Returns true if the cube should be included in the result.
EasingFunction = double Function(double t)
Function type for easing functions
HexFilter = bool Function(Hex hex)
Filter function for hexes. Returns true if the hex should be included in the result.
MoveCost = double Function(Hex from, Hex to)
This function describes the cost of moving from one hex to another. Both hexes are adjacent. The cost is a double value, where double.infinity means that the move is impossible (target hex is a wall). The cost should always be > 0, but this is not enforced.