distribution/power_law.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "terraingen/distribution/power_law.h" | ||
| 2 | |||
| 3 | #include "terraingen/util/checks.h" | ||
| 4 | |||
| 5 | #include <cmath> | ||
| 6 | #include <stdexcept> | ||
| 7 | |||
| 8 | namespace terraingen { | ||
| 9 | |||
| 10 | 3235 | PowerLawSfd::PowerLawSfd(double coefficient, double exponent, SfdKind kind, DiameterRange range) | |
| 11 | 3235 | : SizeFrequencyDistribution(kind, range), law_{range.min, coefficient, exponent} { | |
| 12 | 3232 | if (!IsPositive(coefficient) || !IsPositive(exponent)) { | |
| 13 | throw std::invalid_argument( | ||
| 14 | 3 | "Power law coefficient and exponent must be positive and finite"); | |
| 15 | } | ||
| 16 | 3232 | } | |
| 17 | |||
| 18 | 25445132 | double PowerLawSfd::CumulativeAt(double diameter) const { | |
| 19 | 25445132 | return law_.Cumulative(diameter); | |
| 20 | } | ||
| 21 | |||
| 22 | 2285065 | double PowerLawSfd::IncrementalAt(double diameter) const { | |
| 23 | 2285065 | return law_.Incremental(diameter); | |
| 24 | } | ||
| 25 | |||
| 26 | 1491318 | double PowerLawSfd::InvertCumulative(double target, double /*dMin*/, double /*dMax*/) const { | |
| 27 | 1491318 | return law_.Invert(target); | |
| 28 | } | ||
| 29 | |||
| 30 | 15 | double PowerLawCoefficientFromKilometres(double coefficient, double exponent) { | |
| 31 | 15 | return coefficient * std::pow(1000.0, exponent) / 1e6; | |
| 32 | } | ||
| 33 | |||
| 34 | } // namespace terraingen | ||
| 35 |