Documentation
¶
Index ¶
- Constants
- Variables
- func Neighbor(col, row int, d Direction) (int, int)
- func Version() semver.Version
- func WritePreview(w io.Writer, g Grid, hexes []Hex, scale int) error
- type Corner
- type Direction
- type Elevations
- type Grid
- type GridInfo
- type HeightmapInfo
- type Hex
- type Raster
- type SamplingInfo
- 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 ¶
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 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.
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 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 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.
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. |