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