TerrainGen coverage


terraingen/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
28 / 29
96.6%
Branches:
19 / 21
90.5%
Functions:
4 / 4
100.0%

layers/fade.cpp
Line Branch Exec Source
1 #include "terraingen/layers/fade.h"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <stdexcept>
6
7 namespace terraingen {
8
9 116031006 double Smoothstep(double t) {
10
1/1
✓ Branch 1 taken 116031006 times.
116031006 t = std::clamp(t, 0.0, 1.0);
11 116031006 return t * t * (3.0 - 2.0 * t);
12 }
13
14 62635004 double Falloff(double x, double start, double end, BlendShape shape) {
15
2/2
✓ Branch 0 taken 7610361 times.
✓ Branch 1 taken 55024643 times.
62635004 if (x <= start) {
16 7610361 return 1.0;
17 }
18
2/2
✓ Branch 0 taken 48259152 times.
✓ Branch 1 taken 6765491 times.
55024643 if (x >= end) {
19 48259152 return 0.0;
20 }
21 6765491 const double t = (x - start) / (end - start);
22
4/5
✓ Branch 0 taken 23241 times.
✓ Branch 1 taken 6675221 times.
✓ Branch 2 taken 61587 times.
✓ Branch 3 taken 5442 times.
✗ Branch 4 not taken.
6765491 switch (shape) {
23 23241 case BlendShape::Linear:
24 23241 return 1.0 - t;
25 6675221 case BlendShape::Smoothstep:
26 6675221 return 1.0 - Smoothstep(t);
27 61587 case BlendShape::Smootherstep:
28 61587 return 1.0 - t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
29 5442 case BlendShape::Gaussian: {
30 5442 constexpr double kSigmas = 3.0;
31 5442 const double tail = std::exp(-0.5 * kSigmas * kSigmas);
32 5442 const double z = kSigmas * t;
33 5442 return (std::exp(-0.5 * z * z) - tail) / (1.0 - tail);
34 }
35 }
36 ✗ return 0.0;
37 }
38
39 247784 void ValidateResolutionFade(const ResolutionFade& fade) {
40
5/6
✓ Branch 1 taken 247784 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 247783 times.
✓ Branch 5 taken 1 time.
✓ Branch 6 taken 17 times.
✓ Branch 7 taken 247767 times.
495567 if (!(std::isfinite(fade.startSamples) && std::isfinite(fade.endSamples) &&
41
4/4
✓ Branch 0 taken 247780 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 13 times.
✓ Branch 3 taken 247767 times.
247783 fade.startSamples >= 0.0 && fade.endSamples > fade.startSamples)) {
42
1/1
✓ Branch 2 taken 17 times.
17 throw std::invalid_argument("Resolution fade must satisfy 0 <= startSamples < endSamples");
43 }
44 247767 }
45
46 61983353 double ResolutionWeight(double diameter, double spacing, const ResolutionFade& fade) {
47 61983353 return 1.0 - Falloff(diameter / spacing, fade.startSamples, fade.endSamples, fade.shape);
48 }
49
50 } // namespace terraingen
51