hexgrid

package module
v0.0.0-...-9983485 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2018 License: BSD-3-Clause Imports: 2 Imported by: 1

README

HexGrid GoDoc Build Status

Basics

Configurable hex grid on abstract surface.

Examples

import "github.com/gojuno/go.morton"
import "github.com/gojuno/go.hexgrid"

center := hexgrid.MakePoint(0, 0)
size := hexgrid.MakePoint(20, 10)
grid := hexgrid.MakeGrid(hexgrid.OrientationFlat, center, size, morton.Make64(2, 32))
hex := grid.HexAt(hexgrid.MakePoint(50, 50))
code := grid.HexToCode(hex)
restoredHex := grid.HexFromCode(code)
neighbors := grid.HexNeighbors(hex, 2)
points := []hexgrid.Point{hexgrid.MakePoint(0, 0), hexgrid.MakePoint(0, 10), hexgrid.MakePoint(10, 10), hexgrid.MakePoint(10, 0)}
region := grid.MakeRegion(points)
hexesInRegion := region.Hexes()

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OrientationFlat = Orientation{
	// contains filtered or unexported fields
}
View Source
var OrientationPointy = Orientation{
	// contains filtered or unexported fields
}

Functions

This section is empty.

Types

type FractionalHex

type FractionalHex struct {
	// contains filtered or unexported fields
}

func MakeFractionalHex

func MakeFractionalHex(q float64, r float64) FractionalHex

func (FractionalHex) Q

func (fhex FractionalHex) Q() float64

func (FractionalHex) R

func (fhex FractionalHex) R() float64

func (FractionalHex) S

func (fhex FractionalHex) S() float64

func (FractionalHex) ToHex

func (fhex FractionalHex) ToHex() Hex

type Grid

type Grid struct {
	// contains filtered or unexported fields
}

func MakeGrid

func MakeGrid(orientation Orientation, origin Point, size Point, mort *morton.Morton64) *Grid

func (*Grid) HexAt

func (grid *Grid) HexAt(point Point) Hex

func (*Grid) HexCenter

func (grid *Grid) HexCenter(hex Hex) Point

func (*Grid) HexCorners

func (grid *Grid) HexCorners(hex Hex) [6]Point

func (*Grid) HexFromCode

func (grid *Grid) HexFromCode(code int64) Hex

func (*Grid) HexNeighbors

func (grid *Grid) HexNeighbors(hex Hex, layers int64) []Hex

func (*Grid) HexToCode

func (grid *Grid) HexToCode(hex Hex) int64

func (*Grid) MakeRegion

func (grid *Grid) MakeRegion(geometry []Point) *Region

func (*Grid) MakeRegionFromMultiPolygon

func (grid *Grid) MakeRegionFromMultiPolygon(geometry [][]Point) *Region

type Hex

type Hex struct {
	// contains filtered or unexported fields
}

func MakeHex

func MakeHex(q int64, r int64) Hex

func (Hex) Q

func (hex Hex) Q() int64

func (Hex) R

func (hex Hex) R() int64

func (Hex) S

func (hex Hex) S() int64

type Orientation

type Orientation struct {
	// contains filtered or unexported fields
}

type Point

type Point struct {
	// contains filtered or unexported fields
}

func MakePoint

func MakePoint(x float64, y float64) Point

func (Point) X

func (point Point) X() float64

func (Point) Y

func (point Point) Y() float64

type Region

type Region struct {
	// contains filtered or unexported fields
}

func (*Region) Contains

func (region *Region) Contains(hex Hex) bool

func (*Region) Hexes

func (region *Region) Hexes() []Hex

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL