include/terraingen/distribution/summed.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | /// @file | ||
| 4 | /// @brief Weighted sums of size-frequency distributions. | ||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "terraingen/distribution/size_frequency.h" | ||
| 8 | |||
| 9 | #include <memory> | ||
| 10 | #include <vector> | ||
| 11 | |||
| 12 | namespace terraingen { | ||
| 13 | |||
| 14 | /// One term of a `SummedSfd`: `distribution` scaled by `weight`. | ||
| 15 | 2199 | struct WeightedSfd { | |
| 16 | double weight = 1.0; ///< Positive, finite factor. | ||
| 17 | std::shared_ptr<const SizeFrequencyDistribution> distribution; ///< The scaled distribution. | ||
| 18 | }; | ||
| 19 | |||
| 20 | /// The sum of weighted distributions of one kind, N(>=D) = sum of weight * N_i(>=D), such | ||
| 21 | /// as boulders between craters plus the blocks thrown out by them. | ||
| 22 | /// | ||
| 23 | /// It is valid where every term is: the intersection of their valid ranges, with a term that allows | ||
| 24 | /// extrapolation counting as valid everywhere. | ||
| 25 | 442 | class SummedSfd final : public SizeFrequencyDistribution { | |
| 26 | public: | ||
| 27 | /// The sum of `terms`, all of one kind. | ||
| 28 | /// @throws std::invalid_argument for no terms, a null term, mixed kinds, a weight that is not | ||
| 29 | /// positive and finite, or terms whose valid ranges do not overlap. | ||
| 30 | explicit SummedSfd(std::vector<WeightedSfd> terms); | ||
| 31 | |||
| 32 | /// The weighted terms of the sum. | ||
| 33 | 1 | const std::vector<WeightedSfd>& Terms() const { | |
| 34 | 1 | return m_terms; | |
| 35 | } | ||
| 36 | |||
| 37 | protected: | ||
| 38 | double CumulativeAt(double diameter) const override; | ||
| 39 | double IncrementalAt(double diameter) const override; | ||
| 40 | |||
| 41 | private: | ||
| 42 | /// The sum of `terms`, already checked to share `kind`. | ||
| 43 | SummedSfd(SfdKind kind, std::vector<WeightedSfd>&& terms); | ||
| 44 | |||
| 45 | std::vector<WeightedSfd> m_terms; | ||
| 46 | }; | ||
| 47 | |||
| 48 | } // namespace terraingen | ||
| 49 |