TerrainGen coverage


terraingen/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
33 / 33
100.0%
Branches:
22 / 23
95.7%
Functions:
7 / 7
100.0%

layers/layer.cpp
Line Branch Exec Source
1 #include "terraingen/layers/layer.h"
2
3 #include "terraingen/raster/cell_loops.h"
4 #include "terraingen/raster/grid.h"
5 #include "terraingen/util/checks.h"
6
7 #include <algorithm>
8 #include <stdexcept>
9 #include <string>
10
11 namespace terraingen {
12
13 48180162 void ValidatePointContext(const LayerContext& context) {
14
1/1
✓ Branch 2 taken 48180150 times.
48180162 RequirePositive(context.spacing, "Sample spacing");
15 48180150 }
16
17 5685736 void RequireGround(const Ground* ground, std::string_view what) {
18
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5685724 times.
5685736 if (ground == nullptr) {
19
3/3
✓ Branch 2 taken 12 times.
✓ Branch 5 taken 12 times.
✓ Branch 8 taken 12 times.
36 throw std::invalid_argument(std::string(what) + " need the ground");
20 }
21 5685724 }
22
23 1613 void Layer::Apply(Raster<float>& heights, const LayerContext& context) const {
24
1/1
✓ Branch 1 taken 1613 times.
1613 SampleBlock samples(heights);
25
1/1
✓ Branch 1 taken 1611 times.
1613 ApplySamples(samples, context);
26 1611 }
27
28 48180159 void Layer::Apply(SampleBlock& samples, const LayerContext& context) const {
29
1/2
✓ Branch 1 taken 48180159 times.
✗ Branch 2 not taken.
48180159 if (!samples.IsGrid()) {
30 48180159 ValidatePointContext(context);
31 }
32 48180149 ApplySamples(samples, context);
33 48180145 }
34
35 1542438 float Layer::ApplyAt(float height, double x, double y, const LayerContext& context) const {
36 1542438 const Vec2d position{x, y};
37
1/1
✓ Branch 3 taken 1542438 times.
1542438 SampleBlock samples({&position, 1}, {&height, 1});
38
1/1
✓ Branch 1 taken 1542425 times.
1542438 Apply(samples, context);
39 1542425 return height;
40 }
41
42 6030004 void FormulaLayer::ApplySamples(SampleBlock& samples, const LayerContext& context) const {
43 6030004 CheckContext(context);
44
2/2
✓ Branch 1 taken 70 times.
✓ Branch 2 taken 6029931 times.
6030001 if (Raster<float>* grid = samples.Grid()) {
45 const double spacing =
46
2/2
✓ Branch 1 taken 70 times.
✓ Branch 4 taken 70 times.
70 std::max(context.spacing, RasterGrid::FromRaster(*grid).Spacing(surface_));
47
1/1
✓ Branch 1 taken 70 times.
70 MapCells(*grid, context.threads, [&](float height, const Vec2d& centre) {
48 10411332 return HeightAt(height, centre.x, centre.y, spacing, context.ground);
49 });
50 70 return;
51 }
52
2/2
✓ Branch 1 taken 6157035 times.
✓ Branch 2 taken 6029931 times.
12186966 for (std::size_t i = 0; i < samples.Size(); ++i) {
53
2/2
✓ Branch 1 taken 6157029 times.
✓ Branch 2 taken 6 times.
6157035 if (!samples.IsNoData(i)) {
54
1/1
✓ Branch 1 taken 6157029 times.
6157029 const Vec2d p = samples.Position(i);
55 6157029 samples.Height(i) =
56
1/1
✓ Branch 2 taken 6157029 times.
6157029 HeightAt(samples.Height(i), p.x, p.y, context.spacing, context.ground);
57 }
58 }
59 }
60
61 } // namespace terraingen
62