./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
15 / 15
100.0%
Branches:
5 / 5
100.0%
Functions:
4 / 4
100.0%

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
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 310840 times.
310841 const double weight = std::clamp(cover, 0.0, 1.0);
20
2/2
✓ Branch 0 taken 1550800 times.
✓ Branch 1 taken 310841 times.
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
1/1
✓ Branch 1 taken 12 times.
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