Package-level declarations
The package contains utility functions and classes that aid in performing various mathematical operations specific to the program's focus on coordinates and shapes in a hexagonal grid:
Bresenham's Line Algorithm Functions: These functions, named
bresenhamsLine
, implement the Bresenham's line generation algorithm. They can produce a symmetric line of coordinates between two points on a hexagonal grid. It's slightly modified to be symmetric, so that the line is the same when drawn from either point.Line Drawing Functions: The package includes functions like
T.lineTo
that use the Bresenham's line algorithm to draw lines between two given coordinates on a hexagonal grid.Distance Calculation Functions: Functions such as
T.distanceTo
and the standalonedistance
function are used to calculate the distance between two given coordinates on a hexagonal grid.Hexagonal Shape Functions: The package also contains functions like
T.circle
andT.ring
to generate a circular or ring-like arrangement of coordinates around a given point on a hexagonal grid.
Please refer to individual function documentation for more detailed explanations and examples of usage.
Types
Represents the layout of a hexagonal grid. Read more: Redblobgames Layout Examples
Data class representing the orientation of a hexagonal grid. Read more: Redblobgames Layout
Functions
Implements Bresenham's line generation algorithm to plot a line between two points on a hexagonal grid. Calls the provided process function for each point along the line. This function generates a symmetric line, meaning swapping the start and end points won't affect the result.
Uses Bresenham's line generation algorithm to create a path from this coordinate to another.
Calculates the offset of a corner of a hexagon. This is done by first calculating the angle of the corner relative to the layout's start angle, then scaling a unit vector at that angle by the layout's size.
Rounds a point in fractional hexagonal coordinates to the nearest integer coordinates.
Converts a point in hexagonal coordinates to pixel coordinates. This is done by applying the layout's orientation matrix to the hexagonal coordinates, then scaling and translating the result by the layout's size and origin.
Generates a line of points between two given points in a hexagonal grid. The line is generated by calculating the distance between the start and end points, and then interpolating the coordinates for each step along the line. The provided process function is called for each point along the line.
Generates a line of coordinates from this coordinate to another.
Converts a point in pixel coordinates to hexagonal coordinates. This is done by first normalizing the point's coordinates relative to the layout's origin and size, then applying the layout's orientation matrix to the normalized coordinates.
Calculates the corners of a hexagon in pixel coordinates.