spec

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 9 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

address-block spec

Frozen cell grid and address spec. This directory is the Go module github.com/mcchukwu/address-block/spec; the npm and Dart packages mirror the same grid-2 and cell-address-2 data.

import (
	"fmt"
	spec "github.com/mcchukwu/address-block/spec"
)

cell, _ := spec.CellIDFor(9.05785, 7.49508)
address, _ := spec.EncodeCellAddress(cell)
fmt.Println(address.Words, address.Base32)

Run go test ./... in this directory to check every shared vector.

Release pins

spec/pins.json pins the grid-2 and cell-address-2 files that a release ships. npm run release:dry fails when a pinned file changes or the package versions drift.

Freezing the word list

spec/word-lists.json records every published word list version and its SHA-256. npm run words:freeze fails when the canonical list changes without a new registry entry, or when the TypeScript, Go and Dart constants disagree with the registry.

Documentation

Index

Constants

View Source
const (
	// GridVersion names the frozen latitude band table.
	GridVersion = "grid-2"
	// GridCellMeters is the nominal north-south cell size.
	GridCellMeters = 3
	// GridRowDegrees is the exact latitude height of every row.
	GridRowDegrees = 0.00002713115198871344
	// GridMinLatitude is the southern edge of the grid.
	GridMinLatitude = -89.98
	// GridMaxLatitude is the northern edge of the grid.
	GridMaxLatitude = 89.98
	// GridTableSHA256 pins the band table bytes.
	GridTableSHA256 = "747b27e952656d4e631f20a1d5421303c48da2aa94b8bc3533390042ab7bf1c9"

	// AddressVersion names the frozen address bit layout.
	AddressVersion = "cell-address-2"
	// AddressGridVersion names the grid that addresses point into.
	AddressGridVersion = "grid-2"
	// WordListVersion names the frozen word list.
	WordListVersion = "words-4"
	// WordListSHA256 pins the word list bytes.
	WordListSHA256 = "e3da4fd6ff4498a0fdd48eb0bc0e0b588602d0e039dc9d71233e537ed5991ffa"
)

Variables

View Source
var (
	// GridMinRow is the southernmost row.
	GridMinRow int64
	// GridMaxRow is the northernmost row.
	GridMaxRow int64
	// GridMinColumn is the westernmost reachable column.
	GridMinColumn int64
	// GridMaxColumn is the easternmost reachable column.
	GridMaxColumn int64
	// GridBandCount counts northern and southern bands together.
	GridBandCount int64
	// DistrictRowCount is the number of row districts in the bit layout.
	DistrictRowCount int64
	// DistrictColCount is the number of column districts in the bit layout.
	DistrictColCount int64
)

Functions

func Base32ForCanonical

func Base32ForCanonical(canonical uint64) (string, error)

Base32ForCanonical renders the eleven character short code.

func CanonicalForCell

func CanonicalForCell(cellID string) (uint64, error)

CanonicalForCell packs a cell id into its 48 bit canonical value.

func CanonicalFromBase32

func CanonicalFromBase32(input string) (uint64, error)

CanonicalFromBase32 parses a short code in any accepted spelling.

func CanonicalFromWords

func CanonicalFromWords(input string) (uint64, error)

CanonicalFromWords parses a four word address in any case or spacing.

func CellForCanonical

func CellForCanonical(canonical uint64) (string, error)

CellForCanonical validates a canonical value and returns its cell id.

func CellIDFor

func CellIDFor(lat, lng float64) (string, error)

CellIDFor maps a supported point to its global row:column cell id.

func ColumnRangeForRow

func ColumnRangeForRow(row int64) (int64, int64, error)

ColumnRangeForRow returns the reachable column interval at row.

func ColumnsForRow

func ColumnsForRow(row int64) (int64, error)

ColumnsForRow returns the exact column count of the band containing row.

func DecodeCellAddressBase32

func DecodeCellAddressBase32(input string) (string, error)

DecodeCellAddressBase32 resolves a short code back to its cell id.

func DecodeCellAddressWords

func DecodeCellAddressWords(input string) (string, error)

DecodeCellAddressWords resolves a four word address back to its cell id.

func FormatBase32

func FormatBase32(code string) string

FormatBase32 adds the display hyphens to an eleven character short code.

func WordsForCanonical

func WordsForCanonical(canonical uint64) ([4]string, error)

WordsForCanonical returns the four word address for a canonical value.

Types

type Address

type Address struct {
	CellID    string
	Canonical uint64
	Words     [4]string
	Base32    string
}

Address is every representation of one cell address.

func EncodeCellAddress

func EncodeCellAddress(cellID string) (Address, error)

EncodeCellAddress returns every representation of a cell id.

type Bounds

type Bounds struct {
	South float64
	West  float64
	North float64
	East  float64
}

Bounds is a cell rectangle in degrees.

func CellBoundsFor

func CellBoundsFor(cellID string) (Bounds, error)

CellBoundsFor reconstructs the exact geographic rectangle of a cell id.

type CellAddressError

type CellAddressError struct {
	Code    string
	Message string
}

CellAddressError reports a rejected cell id, word sequence or short code.

func (*CellAddressError) Error

func (e *CellAddressError) Error() string

type Point

type Point struct {
	Lat float64
	Lng float64
}

Point is a latitude and longitude in degrees.

func CellCenterFor

func CellCenterFor(cellID string) (Point, error)

CellCenterFor returns the centre point of a cell.

Directories

Path Synopsis
cmd
verify command
Independent Go verifier for cell-address-1.
Independent Go verifier for cell-address-1.
verify-2 command
Independent Go verifier for grid-2 and cell-address-2.
Independent Go verifier for grid-2 and cell-address-2.

Jump to

Keyboard shortcuts

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