./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
15 / 15
100.0%
Branches:
2 / 2
100.0%
Functions:
5 / 5
100.0%

src/layers/craters/ages/freshness_ages.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 #include "terraingen/layers/craters/ages/freshness_ages.h"
4
5 #include "util/checks.h"
6
7 #include <cmath>
8 #include <utility>
9
10 namespace terraingen {
11
12 namespace {
13
14 24 ValueDistribution ClampedToUnit(ValueDistribution freshness) {
15 24 freshness.min = std::fmax(freshness.min, 0.0);
16 24 freshness.max = std::fmin(freshness.max, 1.0);
17 24 ValidateValueDistribution(freshness);
18 18 return freshness;
19 }
20
21 } // namespace
22
23 24 FreshnessAges::FreshnessAges(ValueDistribution freshness, double lifetimeGyr)
24
1/1
✓ Branch 2 taken 18 times.
30 : m_freshness(ClampedToUnit(std::move(freshness))), m_lifetimeGyr(lifetimeGyr) {
25
1/1
✓ Branch 1 taken 15 times.
18 RequirePositive(m_lifetimeGyr, "Lifetime");
26 18 }
27
28 160867 double FreshnessAges::SampleFreshness(RandomStream& random) const {
29 160867 return m_freshness.Draw(random);
30 }
31
32 280995 double FreshnessAges::LifetimeAt(double /*diameter*/) const {
33 280995 return m_lifetimeGyr;
34 }
35
36 140666 double FreshnessAges::SampleAgeAt(RandomStream& random, double /*diameter*/,
37 double lifetimeGyr) const {
38 140666 return (1.0 - SampleFreshness(random)) * lifetimeGyr;
39 }
40
41 } // namespace terraingen
42