distribution/combined.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "terraingen/distribution/combined.h" | ||
| 2 | |||
| 3 | #include <stdexcept> | ||
| 4 | |||
| 5 | namespace terraingen::detail { | ||
| 6 | |||
| 7 | 2223 | SfdKind CommonKind(std::span<const SizeFrequencyDistribution* const> distributions, | |
| 8 | const std::string& what) { | ||
| 9 | 2223 | if (distributions.empty()) { | |
| 10 | 7 | throw std::invalid_argument(what + " needs at least one distribution"); | |
| 11 | } | ||
| 12 | 6168 | for (const SizeFrequencyDistribution* distribution : distributions) { | |
| 13 | 3962 | if (distribution == nullptr) { | |
| 14 | 6 | throw std::invalid_argument(what + " cannot hold a null distribution"); | |
| 15 | } | ||
| 16 | 3956 | if (distribution->Kind() != distributions.front()->Kind()) { | |
| 17 | 4 | throw std::invalid_argument(what + " needs distributions of one kind"); | |
| 18 | } | ||
| 19 | } | ||
| 20 | 2206 | return distributions.front()->Kind(); | |
| 21 | } | ||
| 22 | |||
| 23 | 1888 | DiameterRange UsableRange(const SizeFrequencyDistribution& distribution) { | |
| 24 | 1888 | return distribution.AllowsExtrapolation() ? DiameterRange{} : distribution.ValidRange(); | |
| 25 | } | ||
| 26 | |||
| 27 | 802 | void CheckJoin(double below, double above, double start, double tolerance, | |
| 28 | bool allowDiscontinuities) { | ||
| 29 | 802 | if (above > below * (1.0 + tolerance)) { | |
| 30 | 8 | throw std::invalid_argument("A cumulative distribution cannot rise at the join at " + | |
| 31 | 12 | std::to_string(start) + " m"); | |
| 32 | } | ||
| 33 | 798 | if (!allowDiscontinuities && above < below * (1.0 - tolerance)) { | |
| 34 | 6 | throw std::invalid_argument("The pieces are discontinuous at " + std::to_string(start) + | |
| 35 | 9 | " m"); | |
| 36 | } | ||
| 37 | 795 | } | |
| 38 | |||
| 39 | } // namespace terraingen::detail | ||
| 40 |