Skip to main content

unbanished_terrain/
heights.rs

1//! A map's heights, owned by the game state (not in the original).
2
3use crate::HeightGrid;
4
5/// A map's heights, owned, as the game state holds them (not in the original, which keeps them
6/// in its terrain): `(size + 1)²` values, row by row, height × 256. [`Heights::grid`] lends them
7/// as a [`HeightGrid`] for queries.
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub struct Heights {
10    /// The cells on each side.
11    pub size: usize,
12    /// The heights, height × 256.
13    pub values: Vec<i16>,
14}
15
16impl Heights {
17    /// The number of samples on each side, `size + 1`.
18    pub fn width(&self) -> usize {
19        self.size + 1
20    }
21
22    /// The heights as a [`HeightGrid`].
23    pub fn grid(&self) -> HeightGrid<'_> {
24        HeightGrid {
25            width: self.width(),
26            heights: &self.values,
27        }
28    }
29}