layers/material.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "terraingen/layers/material.h" | ||
| 2 | |||
| 3 | #include "terraingen/util/parallel.h" | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <cstddef> | ||
| 7 | |||
| 8 | namespace terraingen { | ||
| 9 | |||
| 10 | 356909 | MaterialShares SoilShares() { | |
| 11 | 356909 | MaterialShares shares{}; | |
| 12 | 356909 | shares[static_cast<std::size_t>(MaterialClass::Soil)] = 1.0; | |
| 13 | 356909 | return shares; | |
| 14 | } | ||
| 15 | |||
| 16 | 991357 | void CoverWith(MaterialShares& shares, MaterialClass material, double cover) { | |
| 17 | 991357 | const double weight = std::clamp(cover, 0.0, 1.0); | |
| 18 | 5948142 | for (double& share : shares) { | |
| 19 | 4956785 | share *= 1.0 - weight; | |
| 20 | } | ||
| 21 | 991357 | shares[static_cast<std::size_t>(material)] += weight; | |
| 22 | 991357 | } | |
| 23 | |||
| 24 | 9 | Raster<double> MaterialSource::MaterialCoverOver(const RasterGrid& grid, double spacing, | |
| 25 | const Ground* ground, unsigned threads) const { | ||
| 26 | 9 | Raster<double> cover(grid.width, grid.height); | |
| 27 | 9 | cover.SetTransform(grid.transform); | |
| 28 | 9 | ParallelFor(grid.height, threads, [&](std::size_t row) { | |
| 29 | 408000 | for (std::size_t col = 0; col < grid.width; ++col) { | |
| 30 | 406311 | const Vec2d centre = cover.CellCenter(col, row); | |
| 31 | 406311 | cover(col, row) = MaterialCoverAt(centre.x, centre.y, spacing, ground); | |
| 32 | } | ||
| 33 | 1689 | }); | |
| 34 | 9 | return cover; | |
| 35 | } | ||
| 36 | |||
| 37 | } // namespace terraingen | ||
| 38 |