Skip to content

gojuno/HexGridSwift

Repository files navigation

HexGrid

Basics

Configurable hex grid on abstract surface.

Examples

import Morton
import HexGrid

let center = Point(x: 0.0, y: 0.0)
let size = Point(x: 20.0, y: 10.0)
let grid = Grid(orientation: OrientationFlat, origin: center, size: size, mort: try! Morton64(dimensions: 2, bits: 32))
let hex: Hex = grid.hexAt(Point(x: 50.0, y: 50.0))
let code: Int64 = try! grid.hexToCode(hex)
let restoredHex: Hex = grid.hexFromCode(code)
let neighbors: [Hex] = grid.hexNeighbors(hex, layers: 2)