src/layers/material.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | #include "terraingen/layers/material.h" | ||
| 4 | |||
| 5 | #include "terraingen/raster/cell_loops.h" | ||
| 6 | |||
| 7 | #include <algorithm> | ||
| 8 | #include <cstddef> | ||
| 9 | |||
| 10 | namespace terraingen { | ||
| 11 | |||
| 12 | 108101 | MaterialShares SoilShares() { | |
| 13 | 108101 | MaterialShares shares{}; | |
| 14 | 108101 | shares[static_cast<std::size_t>(MaterialClass::Soil)] = 1.0; | |
| 15 | 108101 | return shares; | |
| 16 | } | ||
| 17 | |||
| 18 | 310841 | void CoverWith(MaterialShares& shares, MaterialClass material, double cover) { | |
| 19 | 310841 | const double weight = std::clamp(cover, 0.0, 1.0); | |
| 20 | 1861641 | for (double& share : shares) { | |
| 21 | 1550800 | share *= 1.0 - weight; | |
| 22 | } | ||
| 23 | 310841 | shares[static_cast<std::size_t>(material)] += weight; | |
| 24 | 310841 | } | |
| 25 | |||
| 26 | 12 | Raster<double> MaterialSource::MaterialCoverOver(const RasterGrid& grid, | |
| 27 | const LayerContext& context) const { | ||
| 28 | 12 | Raster<double> cover(grid); | |
| 29 | 12 | MapCells(cover, context.threads, [&](double, const Vec2d& center) { | |
| 30 | 92373 | return MaterialCoverAt(center.x, center.y, context); | |
| 31 | }); | ||
| 32 | 12 | return cover; | |
| 33 | } | ||
| 34 | |||
| 35 | } // namespace terraingen | ||
| 36 |