layers/material.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /// @file | ||
| 2 | /// @brief Surface material classes, and `MaterialSource`, the layers that lay one down. | ||
| 3 | #pragma once | ||
| 4 | |||
| 5 | #include "terraingen/layers/ground.h" | ||
| 6 | #include "terraingen/raster/grid.h" | ||
| 7 | #include "terraingen/raster/raster.h" | ||
| 8 | |||
| 9 | #include <array> | ||
| 10 | #include <cstddef> | ||
| 11 | #include <cstdint> | ||
| 12 | |||
| 13 | namespace terraingen { | ||
| 14 | |||
| 15 | /// What the surface is made of at a point. | ||
| 16 | enum class MaterialClass : std::uint8_t { | ||
| 17 | Soil, ///< Unconsolidated regolith, the default everywhere. | ||
| 18 | Sand, ///< Wind-sorted sand: dunes, ripples, sand sheets and fill. | ||
| 19 | Dust, ///< Bright airfall dust. | ||
| 20 | Bedrock, ///< Exposed bedrock and outcrop. | ||
| 21 | Rock, ///< Loose rocks and boulders. | ||
| 22 | }; | ||
| 23 | |||
| 24 | /// The number of `MaterialClass` values. | ||
| 25 | inline constexpr std::size_t kMaterialClasses = 5; | ||
| 26 | |||
| 27 | /// The share of each material class at a point, indexed by `MaterialClass`; they sum to 1. | ||
| 28 | using MaterialShares = std::array<double, kMaterialClasses>; | ||
| 29 | |||
| 30 | /// Shares all of soil, the default before anything covers it. | ||
| 31 | MaterialShares SoilShares(); | ||
| 32 | |||
| 33 | /// Lays `cover`, in [0, 1], of class `material` over `shares`: every other share shrinks by | ||
| 34 | /// (1 - cover), so the shares still sum to 1. | ||
| 35 | void CoverWith(MaterialShares& shares, MaterialClass material, double cover); | ||
| 36 | |||
| 37 | /// A layer that lays a material over the surface beneath it, such as sand from dunes. | ||
| 38 | /// | ||
| 39 | /// `MaterialCoverAt` must be a function of position like the layer's heights, so material maps | ||
| 40 | /// agree on every grid and tile. | ||
| 41 | class MaterialSource { | ||
| 42 | public: | ||
| 43 | 382 | virtual ~MaterialSource() = default; | |
| 44 | |||
| 45 | /// The class the layer lays down. | ||
| 46 | virtual MaterialClass Material() const = 0; | ||
| 47 | |||
| 48 | /// How fully the layer covers world (x, y) with its material, in [0, 1]. | ||
| 49 | /// @param spacing Sample spacing in metres, as the layer's heights are evaluated at. | ||
| 50 | /// @param ground The terrain beneath the layer; layers that read it need it. | ||
| 51 | virtual double MaterialCoverAt(double x, double y, double spacing, | ||
| 52 | const Ground* ground) const = 0; | ||
| 53 | |||
| 54 | /// `MaterialCoverAt` at every cell centre of `grid`. By default cell by cell; layers that | ||
| 55 | /// place features override it to find them once for the whole grid. | ||
| 56 | /// @param spacing Sample spacing in metres, at least the grid's cell size. | ||
| 57 | /// @param threads Worker threads, 0 for all. | ||
| 58 | virtual Raster<double> MaterialCoverOver(const RasterGrid& grid, double spacing, | ||
| 59 | const Ground* ground, unsigned threads) const; | ||
| 60 | }; | ||
| 61 | |||
| 62 | } // namespace terraingen | ||
| 63 |