TerrainGen coverage


terraingen/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
24 / 24
100.0%
Branches:
17 / 18
94.4%
Functions:
4 / 4
100.0%

layers/noise_relief.cpp
Line Branch Exec Source
1 #include "terraingen/layers/noise_relief.h"
2
3 #include "terraingen/layers/kernel.h"
4 #include "terraingen/raster/cell_loops.h"
5
6 #include <cstddef>
7 #include <utility>
8
9 namespace terraingen {
10
11 293 NoiseRelief::NoiseRelief(SyntheticTerrainParams params, Vec2d origin, Surface surface)
12 293 : params_(std::move(params)), origin_(origin), surface_(surface) {
13
1/1
✓ Branch 1 taken 291 times.
293 ValidateSyntheticTerrain(params_);
14 291 kernel_ = MakeNoiseReliefKernel(params_.layers);
15 297 }
16
17 41773244 void NoiseRelief::ApplySamples(SampleBlock& samples, const LayerContext& context) const {
18
2/2
✓ Branch 1 taken 41772527 times.
✓ Branch 2 taken 717 times.
41773244 if (!surface_.IsBody()) {
19
1/1
✓ Branch 1 taken 41772527 times.
41772527 ApplyKernel(samples, context, kernel_, origin_);
20 41772633 return;
21 }
22 994802 const auto at = [&](float height, const Vec2d& p) {
23 994802 return height + NoiseLayersAt(params_.layers, origin_, surface_, p.x, p.y);
24 717 };
25
2/2
✓ Branch 1 taken 106 times.
✓ Branch 2 taken 611 times.
717 if (Raster<float>* grid = samples.Grid()) {
26
1/1
✓ Branch 1 taken 106 times.
106 MapCells(*grid, context.threads, at);
27 106 return;
28 }
29
2/2
✓ Branch 1 taken 128852 times.
✓ Branch 2 taken 611 times.
129463 for (std::size_t i = 0; i < samples.Size(); ++i) {
30
2/3
✓ Branch 1 taken 128852 times.
✓ Branch 3 taken 128852 times.
✗ Branch 4 not taken.
128852 if (!samples.IsNoData(i)) {
31
2/2
✓ Branch 1 taken 128852 times.
✓ Branch 5 taken 128852 times.
128852 samples.Height(i) = at(samples.Height(i), samples.Position(i));
32 }
33 }
34 }
35
36 6455684 float NoiseLayersAt(const std::vector<NoiseLayer>& layers, const Vec2d& origin,
37 const Surface& surface, double x, double y) {
38
2/2
✓ Branch 1 taken 1126911 times.
✓ Branch 2 taken 5328773 times.
6455684 if (surface.IsBody()) {
39
1/1
✓ Branch 1 taken 1126911 times.
1126911 const Vec3d p = surface.Position({x, y});
40
1/1
✓ Branch 3 taken 1126911 times.
1126911 return EvaluateNoiseLayers3(p.x, p.y, p.z, layers.data(), layers.size());
41 }
42 5328773 return EvaluateNoiseLayers(static_cast<float>(x - origin.x), static_cast<float>(y - origin.y),
43 5328773 layers.data(), layers.size());
44 }
45
46 } // namespace terraingen
47