TerrainGen coverage


terraingen/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
19 / 19
100.0%
Branches:
8 / 8
100.0%
Functions:
4 / 4
100.0%

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
1/1
✓ Branch 1 taken 991357 times.
991357 const double weight = std::clamp(cover, 0.0, 1.0);
18
2/2
✓ Branch 0 taken 4956785 times.
✓ Branch 1 taken 991357 times.
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
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 ParallelFor(grid.height, threads, [&](std::size_t row) {
29
2/2
✓ Branch 0 taken 406311 times.
✓ Branch 1 taken 1689 times.
408000 for (std::size_t col = 0; col < grid.width; ++col) {
30 406311 const Vec2d centre = cover.CellCenter(col, row);
31
1/1
✓ Branch 1 taken 406311 times.
406311 cover(col, row) = MaterialCoverAt(centre.x, centre.y, spacing, ground);
32 }
33 1689 });
34 9 return cover;
35 }
36
37 } // namespace terraingen
38