hexmap

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

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

Go to latest
Published: Sep 11, 2026 License: CC0-1.0 Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

hexmap

A small Go library for hex-grid geometry, with SVG rendering.

API

  • Point — integer x/y with Plus, Sub, Equals, InBounds, String.
  • Hexagon — Center Point, Radius float64, ID string. Provides Vertices() and pointy-top neighbour helpers: CopyTop, CopyBottom, CopyTopLeft, CopyTopRight, CopyBottomLeft, CopyBottomRight.
  • Map — Width, Height, HexRadius, Units. Hexes(populatePercent) recursively fills the map with hexes (sorted, de-duplicated by centre) and can emit an SVG.

Rendering uses github.com/ajstarks/svgo.

Demo

go run ./cmd > hexes.svg      # a hex plus its six neighbours, labelled

Test

go test ./...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(vs []Point) (xs []int, ys []int)

Types

type Hexagon

type Hexagon struct {
	Center Point
	Radius float64
	ID     string
}

func (Hexagon) BoundingBox

func (hex Hexagon) BoundingBox() (a, b Point)

func (Hexagon) CopyBottom

func (hex Hexagon) CopyBottom() Hexagon

func (Hexagon) CopyBottomLeft

func (hex Hexagon) CopyBottomLeft() Hexagon

func (Hexagon) CopyBottomRight

func (hex Hexagon) CopyBottomRight() Hexagon

func (Hexagon) CopyTop

func (hex Hexagon) CopyTop() Hexagon

func (Hexagon) CopyTopLeft

func (hex Hexagon) CopyTopLeft() Hexagon

func (Hexagon) CopyTopRight

func (hex Hexagon) CopyTopRight() Hexagon

func (Hexagon) Vertices

func (hex Hexagon) Vertices() []Point

type Map

type Map struct {
	Width, Height int
	HexRadius     float64
	Units         string
}

func (Map) Contains

func (m Map) Contains(a Hexagon) bool

func (Map) Hexes

func (m Map) Hexes(populatePercent int) []*Hexagon

func (Map) WriteSVG

func (m Map) WriteSVG(f *os.File, points bool, numberHexes bool, populatePercent int)

type Point

type Point struct {
	X, Y int
}

func (Point) Equals

func (p Point) Equals(q Point) bool

func (Point) InBounds

func (p Point) InBounds(x1, y1, x2, y2 int) bool

func (Point) Plus

func (p Point) Plus(q Point) Point

func (Point) String

func (p Point) String() string

func (Point) Sub

func (p Point) Sub(q Point) Point

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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