distribution/combined.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /// @file | ||
| 2 | /// @brief Checks and lookups shared by the distributions built from others or from pieces. | ||
| 3 | #pragma once | ||
| 4 | |||
| 5 | #include "terraingen/distribution/size_frequency.h" | ||
| 6 | |||
| 7 | #include <cstddef> | ||
| 8 | #include <span> | ||
| 9 | #include <string> | ||
| 10 | #include <vector> | ||
| 11 | |||
| 12 | namespace terraingen::detail { | ||
| 13 | |||
| 14 | /// The kind every one of `distributions` has. | ||
| 15 | /// @param what The combination, for messages, such as "A minimum". | ||
| 16 | /// @throws std::invalid_argument for no inputs, a null input or mixed kinds. | ||
| 17 | SfdKind CommonKind(std::span<const SizeFrequencyDistribution* const> distributions, | ||
| 18 | const std::string& what); | ||
| 19 | |||
| 20 | /// Where `distribution` may be evaluated, in metres: everywhere when it allows extrapolation, | ||
| 21 | /// otherwise its valid range. | ||
| 22 | DiameterRange UsableRange(const SizeFrequencyDistribution& distribution); | ||
| 23 | |||
| 24 | /// Checks the join at `start` (metres) of a piece giving N = `above` after one giving `below`. | ||
| 25 | /// @param tolerance The relative mismatch allowed. | ||
| 26 | /// @param allowDiscontinuities Whether a larger downward jump is allowed. | ||
| 27 | /// @throws std::invalid_argument for a rise, or a drop beyond `tolerance` unless allowed. | ||
| 28 | void CheckJoin(double below, double above, double start, double tolerance, | ||
| 29 | bool allowDiscontinuities); | ||
| 30 | |||
| 31 | /// The index of the piece that applies at `diameter` (metres): the last whose `start` is below it, | ||
| 32 | /// so the lower piece applies at a join. | ||
| 33 | /// @param pieces Pieces with increasing `start`. | ||
| 34 | template <typename Piece> | ||
| 35 | 8252618 | std::size_t IndexOfStart(const std::vector<Piece>& pieces, double diameter) { | |
| 36 | 8252618 | std::size_t index = 0; | |
| 37 | 14444279 | while (index + 1 < pieces.size() && pieces[index + 1].start < diameter) { | |
| 38 | 6191661 | ++index; | |
| 39 | } | ||
| 40 | 8252618 | return index; | |
| 41 | } | ||
| 42 | |||
| 43 | } // namespace terraingen::detail | ||
| 44 |