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 standalone distance 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 and T.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

Link copied to clipboard
data class Layout(val orientation: Orientation = Orientation(), val size: Point = Point(), val origin: Point = Point())
Link copied to clipboard
data class Orientation(val f0: Float = 0.0f, val f1: Float = 0.0f, val f2: Float = 0.0f, val f3: Float = 0.0f, val b0: Float = 0.0f, val b1: Float = 0.0f, val b2: Float = 0.0f, val b3: Float = 0.0f, val startAngle: Float = 0.0f)
Link copied to clipboard
data class Point(val x: Float = 0.0f, val y: Float = 0.0f)

Functions

Link copied to clipboard
fun bresenhamsLine(startQ: Int, startR: Int, endQ: Int, endR: Int, process: (x: Int, y: Int) -> Unit)

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.

Link copied to clipboard

Uses Bresenham's line generation algorithm to create a path from this coordinate to another.

Link copied to clipboard
fun circle(originQ: Int = 0, originR: Int = 0, radius: Int, callback: (Int, Int) -> Unit)

Calls the provided callback on each point within a hexagonal area defined by provided origin and radius.

Link copied to clipboard

Generates a list of coordinates forming a circular region at this coordinate with a given radius.

Link copied to clipboard
fun distance(fromQ: Int, fromR: Int, toQ: Int, toR: Int): Int

Calculates the hexagonal distance between two points given by their (q, r) coordinates.

Link copied to clipboard
infix fun <T : AxisPoint> T.distanceTo(other: AxisPoint): Int

Calculates the hexagonal distance from this coordinate to another.

Link copied to clipboard
fun flatHexHeight(radius: Int): Int
Link copied to clipboard
fun flatHexWidth(radius: Int): Int
Link copied to clipboard
fun hexCornerOffset(layout: Layout, corner: Int): Point
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
infix fun <T : Coordinates<T>, FromHexCoordinates<T>> T.lineTo(other: Coordinates<*>): List<T>

Generates a line of coordinates from this coordinate to another.

Link copied to clipboard
Link copied to clipboard
fun pointyHexHeight(radius: Int): Int
Link copied to clipboard
fun pointyHexWidth(radius: Int): Int
Link copied to clipboard
Link copied to clipboard
fun ring(originQ: Int = 0, originR: Int = 0, radius: Int, callback: (Int, Int) -> Unit)

Calls the provided callback on each point forming a ring in a hexagonal grid defined by provided origin and radius.