Documentation
¶
Index ¶
- func Borders(width, height int, data []int16, cliffAbove int16, minPixels int) (border, shore []bool)
- func ForeignPixels(width, height int, data []int16, border, shore []bool) []bool
- func HexArea(apothem int) float64
- func HexIndex(g hmz2ele.Grid) []int32
- func RenderPreview(g hmz2ele.Grid, centers []hmz2ele.Hex, hexes []Hex, rivers []hmz2riv.EdgeJSON, ...) (*image.RGBA, error)
- func RiverSlots(g hmz2ele.Grid, rivers *hmz2riv.Rivers) (map[int]bool, error)
- func Slot(g hmz2ele.Grid, col, row int) int
- func Version() semver.Version
- type Biome
- type Depth
- type ElevationJSON
- type Flag
- type GridInfo
- type HeightmapInfo
- type Hex
- type HexJSON
- type Inputs
- type LakeJSON
- type Landform
- type Level
- type MethodInfo
- type PixelStats
- type Place
- type RiversInfo
- type Rules
- type Stats
- type Surface
- type Terrain
- type VolcanoJSON
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Borders ¶
func Borders(width, height int, data []int16, cliffAbove int16, minPixels int) (border, shore []bool)
Borders finds where the raster was cut along a national border rather than along a coast.
An edge pixel is a valid pixel with a no-data pixel among its 8 neighbors. A cliff pixel is an edge pixel above cliffAbove meters. The source was cut to the country's borders, so land there stops above sea level; sea cliffs exist too, but they are short. Border pixels are the cliff pixels in 8-connected chains of at least minPixels.
Borders returns the border pixels and the other edge pixels, the shore.
func ForeignPixels ¶
ForeignPixels reports, for each pixel, whether it is no-data on the far side of a border cut: foreign land, not sea. A no-data pixel is foreign when it is strictly closer to a border pixel than to a shore pixel, measuring distance in the chessboard metric (8-neighbor steps) straight across the raster.
func HexIndex ¶
HexIndex returns, for every pixel of a width × height raster, the slot of the hex that contains the pixel's center, or -1 if that hex is not in the grid.
func RenderPreview ¶
func RenderPreview(g hmz2ele.Grid, centers []hmz2ele.Hex, hexes []Hex, rivers []hmz2riv.EdgeJSON, scale int) (*image.RGBA, error)
RenderPreview draws the hmz2ele preview, then fills each hex with its color (see hexColor), keeping the hex outlines. Rivers are drawn along hex edges.
func RiverSlots ¶
RiverSlots returns the slots of every hex on either side of a river edge.
Types ¶
type Biome ¶
type Biome string
Biome is a hex's ecology. hmz2ter sets only Clear, on hexes with no biome; the climate step sets the rest.
type ElevationJSON ¶
type ElevationJSON struct {
Min int16 `json:"min"`
P5 int16 `json:"p5"`
Median int16 `json:"median"`
P95 int16 `json:"p95"`
Max int16 `json:"max"`
}
ElevationJSON is a hex's elevation percentiles, in meters.
type Flag ¶
type Flag string
Flag marks a feature that combines with a landform.
const ( // Coast is land next to salt water, or salt water next to land. Coast Flag = "coast" // River is land with a river on at least one of its edges. River Flag = "river" // Volcano is land holding a listed volcano. Volcano Flag = "volcano" // InlandSea is salt water in a body cut off from the open sea by a // narrow strait. InlandSea Flag = "inland-sea" // Impassable is set on every cliff and badland hex and on the land // along a border cut. Impassable Flag = "impassable" // FlatSurface is land mostly covered by levels that aren't lakes: a // wetland, salt pan, wide river, or filled void in the source. It is a // hint for the climate step. FlatSurface Flag = "flat-surface" )
type GridInfo ¶
type GridInfo struct {
ApothemPx int `json:"apothem_px"`
SidePx float64 `json:"side_px"`
Columns int `json:"columns"`
Rows int `json:"rows"`
HexCount int `json:"hex_count"`
HexAreaPx float64 `json:"hex_area_px"`
}
GridInfo identifies the hex grid.
type HeightmapInfo ¶
type HeightmapInfo struct {
FileName string `json:"file_name"`
Metadata dem2hm.Metadata `json:"metadata"`
}
HeightmapInfo identifies the heightmap the terrain was classified from.
type Hex ¶
type Hex struct {
Col, Row int
Stats PixelStats
// Center is the hex's center elevation, sampled as hmz2ele does, or nil
// for no-data.
Center *int16
Landform Landform
Surface Surface
Biome Biome
Depth Depth
// SeaDistance is, for salt water, the number of steps from the nearest
// hex that isn't salt water, or -1 if there is none. It is 0 for other
// hexes.
SeaDistance int
Flags []Flag
}
Hex is one hex's terrain.
func Classify ¶
Classify returns every hex in the grid, ordered by row, then column.
A hex is fresh water if more than half its pixels are lake. Otherwise it is land if its center elevation is above 0 m, as in hmz2ele. Otherwise it is a border cut if it has more foreign no-data pixels than other no-data pixels, and salt water if not.
A cut next to land becomes cliffs if it also touches water, another cut, or the grid's edge, and badlands if land surrounds it. Other cuts become salt water.
type HexJSON ¶
type HexJSON struct {
Col int `json:"col"`
Row int `json:"row"`
Landform Landform `json:"landform"`
Surface Surface `json:"surface,omitempty"`
Biome Biome `json:"biome,omitempty"`
Depth Depth `json:"depth,omitempty"`
SeaDistance *int `json:"sea_distance,omitempty"`
Flags []Flag `json:"flags,omitempty"`
Center *int16 `json:"center"`
Pixels int `json:"pixels"`
ValidPixels int `json:"valid_pixels"`
LandFraction float64 `json:"land_fraction"`
Elevation *ElevationJSON `json:"elevation"`
ReliefM *int `json:"relief_m"`
}
HexJSON is one hex. Surface and Biome are omitted while unset; the climate step sets them for land. Elevation and ReliefM are nil for a hex with no valid pixels.
type Inputs ¶
type Inputs struct {
Grid hmz2ele.Grid
Rules Rules
// Centers are hmz2ele's center samples, one per hex in the grid.
Centers []hmz2ele.Hex
// Stats, and the pixel counts below, are indexed by slot.
Stats []PixelStats
// LakePixels and FlatPixels count lake pixels and other level pixels.
LakePixels, FlatPixels []int
// ForeignPixels and SeaPixels count foreign and other no-data pixels.
ForeignPixels, SeaPixels []int
// BorderPixels counts border pixels.
BorderPixels []int
// RiverSlots and VolcanoSlots are the slots with a river edge and with
// a volcano.
RiverSlots, VolcanoSlots map[int]bool
// Volcanoes are the volcanoes' positions in raster pixels, and
// PixelSizeM is the real size of a pixel, in meters.
Volcanoes [][2]float64
PixelSizeM float64
}
Inputs are the per-pixel and per-slot facts that Classify combines.
type LakeJSON ¶
type LakeJSON struct {
Name string `json:"name"`
Seed Place `json:"seed"`
ElevationM int16 `json:"elevation_m"`
Pixels int `json:"pixels"`
}
LakeJSON is one level chosen as a lake by a seed.
type Landform ¶
type Landform string
Landform is a hex's underlying physical geography. The names are the game's.
const ( // LandformEmpty is unset. It is an error in the output. LandformEmpty Landform = "" FreshWater Landform = "fresh-water" SaltWater Landform = "salt-water" Flats Landform = "flats" Plains Landform = "plains" RollingPlains Landform = "rolling-plains" Hills Landform = "hills" Mountains Landform = "mountains" Plateaus Landform = "plateaus" VolcanicHighlands Landform = "volcanic-highlands" // Cliffs and Badlands are border-cut hexes: impassable by normal means. Cliffs Landform = "cliffs" Badlands Landform = "badlands" )
type Level ¶
type Level struct {
// Lake is the name of the lake whose seed lies on the level, or "" if
// no seed does.
Lake string
// Seed is the index of the first seed on the level, or -1.
Seed int
Elevation int16
Pixels int
// SlotPixels counts the level's pixels in each slot.
SlotPixels map[int32]int
}
Level is a connected surface of pixels, 4-connected, that all have the same elevation above 0 m and together cover at least one hex's area.
The source is a surface model whose water bodies were flattened, so lakes are levels. So are wide rivers, coastal wetlands, salt pans, and patches of filled voids, which is why lakes are chosen by seed points.
func FindLevels ¶
func FindLevels(width, height int, data []int16, index []int32, minPixels float64, seeds map[int]int, names []string) ([]Level, error)
FindLevels returns every level of at least minPixels pixels, in raster order of their first pixel. seeds maps a pixel index to a lake seed's index in names; a level holding a seed is that lake. It is an error for a seed to miss every level, or for one level to hold seeds of two different lakes.
type MethodInfo ¶
type MethodInfo struct {
Statistics string `json:"statistics"`
Lakes string `json:"lakes"`
Borders string `json:"borders"`
Cuts string `json:"cuts"`
Sea string `json:"sea"`
InlandSeas string `json:"inland_seas"`
}
MethodInfo describes the rules that Rules doesn't hold.
type PixelStats ¶
type PixelStats struct {
// Pixels is the number of raster pixels in the hex; hexes on the
// raster's edge are clipped.
Pixels int
// Valid is the number of pixels that are not no-data.
Valid int
// Land is the number of valid pixels above 0 m.
Land int
// Min, P5, Median, P95, and Max are nearest-rank percentiles of the
// valid pixels' elevations.
Min, P5, Median, P95, Max int16
}
PixelStats summarizes every pixel in one hex. Elevations are in meters and are zero when the hex has no valid pixels.
func ComputeStats ¶
func ComputeStats(g hmz2ele.Grid, data []int16, index []int32) []PixelStats
ComputeStats returns the statistics of every slot's pixels.
func (PixelStats) Relief ¶
func (s PixelStats) Relief() int
Relief is the spread between the 95th and 5th percentiles.
type Place ¶
Place is a named point, such as a lake seed or a volcano.
type RiversInfo ¶
type RiversInfo struct {
FileName string `json:"file_name"`
Hmz2rivVersion string `json:"hmz2riv_version"`
ThresholdKm2 float64 `json:"threshold_km2"`
}
RiversInfo identifies the hmz2riv output the river flags came from.
type Rules ¶
type Rules struct {
// A land hex's landform comes from its relief (p95 − p5): flats below
// FlatsBelow, plains below PlainsBelow, rolling plains below
// RollingBelow, hills below HillsBelow, and mountains otherwise.
FlatsBelow int `json:"flats_below_m"`
PlainsBelow int `json:"plains_below_m"`
RollingBelow int `json:"rolling_plains_below_m"`
HillsBelow int `json:"hills_below_m"`
// A land hex with a median elevation of at least PlateauMinMedian and
// relief below PlateauBelow is a plateau, whatever its relief class.
PlateauMinMedian int `json:"plateau_min_median_m"`
PlateauBelow int `json:"plateau_below_m"`
// A plateau whose center is within VolcanicRadiusRealKm of a volcano is
// a volcanic highland. The radius is in real (source) kilometers, not
// campaign kilometers, because it describes the ground, and so doesn't
// change with the hex size.
VolcanicRadiusRealKm float64 `json:"volcanic_radius_real_km"`
// Salt water up to ShallowMax hexes from land is shallow, up to OpenMax
// is open, and farther out is deep.
ShallowMax int `json:"shallow_max_hexes"`
OpenMax int `json:"open_max_hexes"`
// A body of salt water is an inland sea if it has at least
// InlandMinHexes hexes and is cut off from the open sea by removing
// the salt water within StraitMax hexes of land. StraitMax matches the
// small boats' range, so they can cross every strait into an inland
// sea.
StraitMax int `json:"strait_max_hexes"`
InlandMinHexes int `json:"inland_min_hexes"`
// A border cut is a chain of at least BorderMinPixels 8-connected land
// pixels, each above CliffAbove meters and touching no-data.
CliffAbove int16 `json:"cliff_above_m"`
BorderMinPixels int `json:"border_min_pixels"`
}
Rules holds the thresholds that classify hexes. Elevations and relief are in meters. Rules about the ground use source units (real meters, kilometers, or pixels); rules about play, such as depth, use hexes.
type Stats ¶
type Stats struct {
Landforms map[Landform]int `json:"landforms"`
Depths map[Depth]int `json:"depths"`
Flags map[Flag]int `json:"flags"`
SeaDistance []int `json:"sea_distance"`
UnreachableSea int `json:"unreachable_sea"`
BorderPixels int `json:"border_pixels"`
ForeignPixels int `json:"foreign_pixels"`
OtherLevels int `json:"other_levels"`
}
Stats counts the hexes. SeaDistance[d] is the number of salt-water hexes d steps from the nearest hex that isn't salt water; UnreachableSea counts salt-water hexes that no such hex reaches.
type Surface ¶
type Surface string
Surface is a hex's surface or hydrological condition. hmz2ter sets only Clear, on hexes whose surface can't change; the climate step sets the rest.
type Terrain ¶
type Terrain struct {
Hmz2terVersion string `json:"hmz2ter_version"`
Heightmap HeightmapInfo `json:"heightmap"`
Grid GridInfo `json:"grid"`
Rivers RiversInfo `json:"rivers"`
Rules Rules `json:"rules"`
Method MethodInfo `json:"method"`
Lakes []LakeJSON `json:"lakes"`
Volcanoes []VolcanoJSON `json:"volcanoes"`
Stats Stats `json:"stats"`
Hexes []HexJSON `json:"hexes"`
}
Terrain is the classified hex grid, as written to JSON.
type VolcanoJSON ¶
VolcanoJSON is a listed volcano and the hex that holds it.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
hmz2ter
command
Command hmz2ter classifies each hex of a flat-top hex grid over a dem2hm heightmap (format 1.1) by landform and water, sets flags such as coast, cliff, and river, and writes the result as JSON, with an optional PNG preview.
|
Command hmz2ter classifies each hex of a flat-top hex grid over a dem2hm heightmap (format 1.1) by landform and water, sets flags such as coast, cliff, and river, and writes the result as JSON, with an optional PNG preview. |