Documentation
¶
Index ¶
- Constants
- Variables
- func EdgeVertices(e EdgeKey) (VertexKey, VertexKey)
- func Neighbor(col, row int, d Direction) (int, int)
- func RenderPreview(g Grid, hexes []Hex, scale int) (*image.RGBA, error)
- func Version() semver.Version
- func WritePreview(w io.Writer, g Grid, hexes []Hex, scale int) error
- type Corner
- type Direction
- type EdgeKey
- type Elevations
- type Grid
- func (g Grid) Center(col, row int) (x, y float64)
- func (g Grid) Contains(col, row int) bool
- func (g Grid) East(col, row int) (x, y float64)
- func (g Grid) HexAt(x, y float64) (col, row int)
- func (g Grid) NearestVertex(x, y float64) VertexKey
- func (g Grid) Vertex(k VertexKey) (x, y float64)
- func (g Grid) West(col, row int) (x, y float64)
- type GridInfo
- type HeightmapInfo
- type Hex
- type HexCorner
- type Raster
- type SamplingInfo
- type Side
- type Summary
- type Vertex
- type VertexKey
Constants ¶
const ( // SampleWindow is the side of the square block of pixels sampled around // a point. SampleWindow = 3 // NoDataMajority is the number of no-data pixels in the block that makes // the sample no-data. NoDataMajority = 5 )
Variables ¶
Directions lists every Direction, clockwise from North.
Functions ¶
func EdgeVertices ¶ added in v0.2.0
EdgeVertices returns the edge's two vertices, in clockwise order around the hex that owns it.
func Neighbor ¶
Neighbor returns the column and row of the hex next to (col, row) in the given direction. The result may be outside the grid.
func RenderPreview ¶ added in v0.2.0
RenderPreview draws the preview that WritePreview writes, so callers can draw over it. Preview pixel (px, py) covers raster pixels [px × scale, (px+1) × scale) × [py × scale, (py+1) × scale).
Types ¶
type Corner ¶
type Corner int
Corner names a corner a hex owns.
func (Corner) MarshalText ¶
MarshalText encodes the corner as "west" or "east".
type Direction ¶
type Direction int
Direction names a neighboring hex. Flat-top hexes have no east or west neighbors.
type EdgeKey ¶ added in v0.2.0
EdgeKey identifies an edge by the hex that owns it and which of that hex's three owned sides it is.
func EdgeBetween ¶ added in v0.2.0
EdgeBetween returns the edge joining two vertices, or false if they are not neighbors.
type Elevations ¶
type Elevations struct {
Hmz2eleVersion string `json:"hmz2ele_version"`
Heightmap HeightmapInfo `json:"heightmap"`
Grid GridInfo `json:"grid"`
Sampling SamplingInfo `json:"sampling"`
Hexes []Hex `json:"hexes"`
BoundaryVertices []Vertex `json:"boundary_vertices"`
}
Elevations is the hex grid's sampled elevations, as written to JSON. Elevations are in meters; nil means no-data.
func NewElevations ¶
func NewElevations(fileName string, hm *dem2hm.HeightMap16, g Grid) *Elevations
NewElevations samples the grid and returns the complete JSON document.
type Grid ¶
type Grid struct {
// Apothem is the distance from a hex's center to the middle of a side,
// in pixels. A hex is 2 × Apothem pixels tall.
Apothem int
// Side is the length of a hex side, which is also the distance from the
// center to a corner, in pixels.
Side float64
// Columns and Rows bound the column and row numbers of hexes in the
// grid. Not every (column, row) inside those bounds is in the grid; use
// Contains.
Columns, Rows int
// Width and Height are the raster's dimensions in pixels.
Width, Height int
}
Grid is a flat-top hex grid laid over a raster, with even columns shifted down by half a hex. Hex (0, 0) is in the top-left corner and the first column's west corner is at x = 0.
Geometry uses continuous raster coordinates: pixel (i, j) covers [i, i+1) × [j, j+1).
func NewGrid ¶
NewGrid returns the grid of every hex whose center pixel lies inside a width × height raster.
func (Grid) Center ¶
Center returns the center of the hex in the given column and row. It is defined for any column and row, including hexes outside the grid.
func (Grid) HexAt ¶ added in v0.2.0
HexAt returns the column and row of the hex containing the point. The hex may be outside the grid.
func (Grid) NearestVertex ¶ added in v0.2.0
NearestVertex returns the vertex nearest the point. The nearest vertex is always a corner of the hex containing the point.
type GridInfo ¶
type GridInfo struct {
Layout string `json:"layout"`
ApothemPx int `json:"apothem_px"`
SidePx float64 `json:"side_px"`
Columns int `json:"columns"`
Rows int `json:"rows"`
WidthPx int `json:"width_px"`
HeightPx int `json:"height_px"`
HexCount int `json:"hex_count"`
CornerNote string `json:"corner_note"`
}
GridInfo describes the hex grid. See Grid.
type HeightmapInfo ¶
type HeightmapInfo struct {
FileName string `json:"file_name"`
Metadata dem2hm.Metadata `json:"metadata"`
}
HeightmapInfo identifies the heightmap the elevations were sampled from.
type Hex ¶
type Hex struct {
Col int `json:"col"`
Row int `json:"row"`
Center *int16 `json:"center"`
West *int16 `json:"west"`
East *int16 `json:"east"`
}
Hex is one hex's center elevation and the elevations of the two corners it owns.
type HexCorner ¶ added in v0.2.0
type HexCorner struct {
Col, Row, Corner int
}
HexCorner is a hex and one of its corners, numbered clockwise from east (0°) in y-down raster coordinates: 0 east, 1 south-east, 2 south-west, 3 west, 4 north-west, 5 north-east.
func VertexHexes ¶ added in v0.2.0
VertexHexes returns the three hexes that meet at the vertex, with the vertex's corner number in each.
type Raster ¶
Raster is the elevation data a sample reads: a row-major raster of elevations in meters, with dem2hm.NoDataPixel16 for no-data.
func RasterFromHeightMap ¶
func RasterFromHeightMap(hm *dem2hm.HeightMap16) Raster
RasterFromHeightMap returns a Raster that shares the heightmap's data.
func (Raster) Sample ¶
Sample returns the elevation at (x, y), in meters, taken from the 3 × 3 block of pixels centered on the pixel nearest the point.
The elevation is the median of the valid pixels in the block. With an even number of valid pixels it is the mean of the two middle values, rounded half away from zero. Pixels outside the raster count as no-data. If 5 or more of the 9 pixels are no-data, Sample returns false.
type SamplingInfo ¶
type SamplingInfo struct {
Window int `json:"window"`
Statistic string `json:"statistic"`
NoDataMajority int `json:"no_data_majority"`
}
SamplingInfo describes how each elevation was sampled. See Raster.Sample.
type Side ¶ added in v0.2.0
type Side int
Side names an edge a hex owns. Each hex owns its north, north-east, and south-east edges; its south, south-west, and north-west edges are the north, north-east, and south-east edges of its south, south-west, and north-west neighbors.
func (Side) MarshalText ¶ added in v0.2.0
MarshalText encodes the side as "n", "ne", or "se".
type Summary ¶
type Summary struct {
// Hexes is the number of hexes in the grid.
Hexes int
// Land hexes have a center elevation above sea level (0 m).
Land int
// Low hexes have a valid center elevation at or below sea level.
Low int
// NoData hexes have a no-data center: sea, or foreign land at a border
// cut.
NoData int
// CoastalSea hexes are Low or NoData hexes next to at least one Land hex.
CoastalSea int
}
Summary counts hexes by what their center sample shows.
type Vertex ¶
type Vertex struct {
Col int `json:"col"`
Row int `json:"row"`
Corner Corner `json:"corner"`
Elevation *int16 `json:"elevation"`
}
Vertex is a corner used by a hex in the grid but owned by a hex outside it.
func BuildBoundaryVertices ¶
BuildBoundaryVertices samples every corner that a hex in the grid uses but a hex outside the grid owns. They are ordered by owner row, owner column, then corner.
type VertexKey ¶
VertexKey identifies a vertex by the hex that owns it and which of that hex's two owned corners it is.
func CornerOwner ¶
CornerOwner returns the owner of the hex's corner that lies between the given direction and the next direction clockwise. The north-east corner is between NorthEast and SouthEast, and so on. The owner of a hex's own east and west corners is the hex itself.
Every vertex touches exactly three hexes, and exactly one of them has the vertex as its west or east corner, so each vertex has exactly one owner.
func VertexNeighbors ¶ added in v0.2.0
VertexNeighbors returns the three vertices joined to the vertex by a hex edge.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
hmz2ele
command
Command hmz2ele samples a dem2hm heightmap (format 1.1) at the centers and corners of a flat-top hex grid and writes the elevations as JSON, with an optional PNG preview.
|
Command hmz2ele samples a dem2hm heightmap (format 1.1) at the centers and corners of a flat-top hex grid and writes the elevations as JSON, with an optional PNG preview. |