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

include/terraingen/random/random_fields.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief The field list of value distributions and the names of their kinds.
5 #pragma once
6
7 #include "terraingen/random/value_distribution.h"
8 #include "terraingen/util/option_fields.h"
9
10 #include <array>
11 #include <limits>
12
13 namespace terraingen {
14
15 template <> struct EnumNames<ValueDistribution::Kind> {
16 static constexpr std::array<EnumEntry<ValueDistribution::Kind>, 5> kValues{{
17 {"constant", ValueDistribution::Kind::Constant, "Always a."},
18 {"uniform", ValueDistribution::Kind::Uniform, "Uniform between a and b."},
19 {"normal", ValueDistribution::Kind::Normal, "Normal with mean a and standard deviation b."},
20 {"log_normal", ValueDistribution::Kind::LogNormal,
21 "Log-normal with median a and standard deviation b of the natural logarithm."},
22 {"piecewise", ValueDistribution::Kind::Piecewise,
23 "Uniform within each bin between edges, each bin drawn in proportion to its weight."},
24 }};
25 };
26
27 2446742 template <typename IO> void Fields(IO& io, ValueDistribution& distribution) {
28 2446742 io("kind", distribution.kind, "Kind of distribution the value is drawn from.");
29 2445985 io("a", distribution.a,
30 "The constant value, the uniform's lower bound, the normal's mean or the log-normal's "
31 "median.");
32 2443781 io("b", distribution.b,
33 "The uniform's upper bound, or the standard deviation (of the natural logarithm for a "
34 "log-normal); unused for a constant.");
35 2441094 OptionalBound(io, "min", distribution.min,
36 "Lower bound drawn values are clamped to; unset leaves them unbounded below.", {},
37 -std::numeric_limits<double>::infinity());
38 2441822 OptionalBound(io, "max", distribution.max,
39 "Upper bound drawn values are clamped to; unset leaves them unbounded above, "
40 "which normal and log-normal kinds do not allow.");
41 2441945 io("edges", distribution.edges,
42 "With piecewise, the edges of the bins, at least two and strictly increasing; values are "
43 "uniform within each bin. Empty for every other kind.");
44 2441160 io("weights", distribution.weights,
45 "With piecewise, the relative weight of each bin, one fewer than the edges and not all "
46 "zero; each bin draws its share of the total. Empty for every other kind.",
47 2441160 "", AtLeast(0.0));
48 2444543 }
49
50 } // namespace terraingen
51