TerrainGen coverage


terraingen/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
27 / 27
100.0%
Branches:
34 / 34
100.0%
Functions:
6 / 6
100.0%

layers/transforms.cpp
Line Branch Exec Source
1 #include "terraingen/layers/transforms.h"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <stdexcept>
6 #include <utility>
7
8 namespace terraingen {
9
10 27 ScaleLayer::ScaleLayer(double scale, double offset) : scale_(scale), offset_(offset) {
11
6/6
✓ Branch 1 taken 26 times.
✓ Branch 2 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 5 taken 25 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 25 times.
27 if (!(std::isfinite(scale) && std::isfinite(offset))) {
12
1/1
✓ Branch 2 taken 2 times.
2 throw std::invalid_argument("Scale and offset must be finite");
13 }
14 27 }
15
16 699150 float ScaleLayer::HeightAt(float height, double /*x*/, double /*y*/, double /*spacing*/,
17 const Ground* /*ground*/) const {
18 699150 return static_cast<float>(static_cast<double>(height) * scale_ + offset_);
19 }
20
21 20 ClampLayer::ClampLayer(std::optional<double> min, std::optional<double> max)
22 20 : min_(min), max_(max) {
23
10/10
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 9 times.
✓ Branch 5 taken 10 times.
✓ Branch 6 taken 1 time.
✓ Branch 8 taken 17 times.
✓ Branch 9 taken 2 times.
✓ Branch 12 taken 1 time.
✓ Branch 13 taken 16 times.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 18 times.
20 if ((min && !std::isfinite(*min)) || (max && !std::isfinite(*max))) {
24
1/1
✓ Branch 2 taken 2 times.
2 throw std::invalid_argument("Clamp bounds must be finite");
25 }
26
8/8
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 2 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 5 times.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 15 times.
18 if (min && max && *min > *max) {
27
1/1
✓ Branch 2 taken 3 times.
3 throw std::invalid_argument("Clamp min must not exceed max");
28 }
29 20 }
30
31 277114 float ClampLayer::HeightAt(float height, double /*x*/, double /*y*/, double /*spacing*/,
32 const Ground* /*ground*/) const {
33 277114 double value = height;
34
2/2
✓ Branch 1 taken 263220 times.
✓ Branch 2 taken 13894 times.
277114 if (min_) {
35 263220 value = std::max(value, *min_);
36 }
37
2/2
✓ Branch 1 taken 277112 times.
✓ Branch 2 taken 2 times.
277114 if (max_) {
38 277112 value = std::min(value, *max_);
39 }
40 277114 return static_cast<float>(value);
41 }
42
43 5 FunctionLayer::FunctionLayer(HeightFunction function, Surface surface)
44 5 : FormulaLayer(surface), function_(std::move(function)) {
45
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 4 times.
5 if (!function_) {
46
1/1
✓ Branch 2 taken 1 time.
1 throw std::invalid_argument("A function layer needs a function");
47 }
48 6 }
49
50 127 float FunctionLayer::HeightAt(float height, double x, double y, double spacing,
51 const Ground* /*ground*/) const {
52 127 return static_cast<float>(function_(x, y, spacing, height));
53 }
54
55 } // namespace terraingen
56