./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
4 / 4
100.0%
Branches:
7 / 18
38.9%
Functions:
-
-%

include/terraingen/layers/fade.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief Falloff curves, and the fade of features too small to resolve at a sample spacing.
5 #pragma once
6
7 namespace terraingen {
8
9 /// Shape of a falloff from 1 to 0.
10 enum class BlendShape {
11 Linear, ///< Straight ramp; continuous, with kinks at both ends.
12 Smoothstep, ///< Cubic 3t^2 - 2t^3; continuous first derivative.
13 Smootherstep, ///< Quintic 6t^5 - 15t^4 + 10t^3; continuous first and second derivatives.
14 Gaussian, ///< Gaussian falloff with sigma a third of the band, rescaled to end at zero.
15 };
16
17 /// The cubic smoothstep 3t^2 - 2t^3, with `t` clamped to [0, 1].
18 double Smoothstep(double t);
19
20 /// The weight in [0, 1] of a falloff from 1 at or before `start` to 0 at or beyond `end`.
21 /// @param end Above `start`.
22 double Falloff(double x, double start, double end, BlendShape shape);
23
24 /// How features too small to resolve at the sample spacing fade out, by the samples across
25 /// their diameter.
26 6 struct ResolutionFade {
27 double startSamples = 2.0; ///< Samples across at or below which the feature is absent.
28 double endSamples = 4.0; ///< Samples across from which it is whole; above `startSamples`.
29 BlendShape shape = BlendShape::Smoothstep; ///< The curve in between.
30
31 11 bool operator==(const ResolutionFade& other) const {
32
4/12
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 time.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
11 return startSamples == other.startSamples && endSamples == other.endSamples &&
33
3/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
11 shape == other.shape;
34 }
35 };
36
37 /// Checks a resolution fade.
38 /// @throws std::invalid_argument unless 0 <= `startSamples` < `endSamples`, both finite.
39 void ValidateResolutionFade(const ResolutionFade& fade);
40
41 /// The weight of a feature at a sample spacing: 0 up to `fade.startSamples` samples across it, 1
42 /// from `fade.endSamples`, and `fade.shape` in between.
43 /// @param diameter The feature's size, in the units of `spacing`.
44 /// @param spacing Positive.
45 double ResolutionWeight(double diameter, double spacing, const ResolutionFade& fade);
46
47 } // namespace terraingen
48