pub struct Terrain {
pub sea_level: f32,
pub heightmap: Grid<f32>,
pub flow_accumulation: Grid<f32>,
pub flow: Grid<f32>,
pub rivers: Grid<u8>,
pub lakes: Grid<u8>,
pub ocean: Grid<u8>,
}Expand description
A generated terrain: elevation plus the hydrology layers derived from it.
All per-cell buffers are Grids, indexed as grid[(x, y)]; their
flat row-major storage is available through Grid::as_slice for
zero-copy hand-off to FFI, GPUs or file formats.
The layers are independent and raw on purpose: this crate decides what
the terrain is, not what it means. Consumers that classify water for
their own rules (salinity, drinkability, navigability) should build on
ocean, lakes and
flow_accumulation rather than on rendered
colours or on elevation thresholds.
Fields§
§sea_level: f32Sea level the terrain was generated with, in [0, 1].
heightmap: Grid<f32>Elevation per cell, in [0, 1].
flow_accumulation: Grid<f32>Raw D8 flow accumulation per cell, in cells of upstream catchment (each cell contributes 1, including itself). Use this to size channels — river width typically scales with the square root of catchment area. All-zero when river extraction is disabled.
flow: Grid<f32>flow_accumulation log-normalised into
[0, 1], which is the more useful form as a moisture proxy for
biome placement. All-zero when river extraction is disabled.
rivers: Grid<u8>River mask per cell: 1 where a river runs, 0 elsewhere.
lakes: Grid<u8>Lake mask per cell: 1 where an inland depression holds standing
water, 0 elsewhere. Rivers vanish beneath lakes and continue from
their outlet. A basin whose floor lies below sea level but which is
cut off from the sea counts as a lake, not ocean.
ocean: Grid<u8>Ocean mask per cell: 1 where the cell is at or below sea level
and connected to the map border through other such cells. Always
computed, including when river extraction is disabled, because it
is a fact about the heightmap rather than a hydrology result.
Implementations§
Source§impl Terrain
impl Terrain
Sourcepub fn builder() -> TerrainBuilder
pub fn builder() -> TerrainBuilder
Starts building a terrain with default parameters.
Sourcepub fn flow_at(&self, x: usize, y: usize) -> f32
pub fn flow_at(&self, x: usize, y: usize) -> f32
Normalised flow accumulation at (x, y), in [0, 1].
Sourcepub fn flow_accumulation_at(&self, x: usize, y: usize) -> f32
pub fn flow_accumulation_at(&self, x: usize, y: usize) -> f32
Raw upstream catchment at (x, y), in cells.
Sourcepub fn is_ocean(&self, x: usize, y: usize) -> bool
pub fn is_ocean(&self, x: usize, y: usize) -> bool
Whether (x, y) is ocean: at or below sea level and connected to
the map border. Enclosed low ground is not ocean.
Sourcepub fn is_water(&self, x: usize, y: usize) -> bool
pub fn is_water(&self, x: usize, y: usize) -> bool
Whether (x, y) is covered by water of any kind: ocean, lake or
river.
Note this is a union of the three masks, not an elevation test — a closed basin below sea level counts as lake, not ocean.
Sourcepub fn to_rgb(&self, style: RenderStyle) -> Vec<u8> ⓘ
pub fn to_rgb(&self, style: RenderStyle) -> Vec<u8> ⓘ
Renders the terrain to a row-major RGB byte buffer
(width * height * 3).
Sourcepub fn save_layer_png<P: AsRef<Path>>(
&self,
layer: Layer,
path: P,
) -> Result<(), RenderError>
pub fn save_layer_png<P: AsRef<Path>>( &self, layer: Layer, path: P, ) -> Result<(), RenderError>
Writes a single Layer as a PNG file: the shaded
render, or one of the raw data layers (elevation and flow as 16-bit
greyscale, masks as 8-bit black/white).
Requires the png cargo feature (enabled by default).
Sourcepub fn save_png<P: AsRef<Path>>(
&self,
path: P,
style: RenderStyle,
) -> Result<(), RenderError>
pub fn save_png<P: AsRef<Path>>( &self, path: P, style: RenderStyle, ) -> Result<(), RenderError>
Renders the terrain and writes it as a PNG file.
Requires the png cargo feature (enabled by default).