src/distribution/power_law.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | #include "terraingen/distribution/power_law.h" | ||
| 4 | |||
| 5 | #include "util/checks.h" | ||
| 6 | |||
| 7 | #include <cmath> | ||
| 8 | #include <stdexcept> | ||
| 9 | |||
| 10 | namespace terraingen { | ||
| 11 | |||
| 12 | 3276 | PowerLawSfd::PowerLawSfd(double coefficient, double exponent, SfdKind kind, DiameterRange range) | |
| 13 | 3276 | : SizeFrequencyDistribution(kind, range), m_law{range.min, coefficient, exponent} { | |
| 14 | 6544 | if (!IsPositive(coefficient) || !IsPositive(exponent)) { | |
| 15 | 3 | throw std::invalid_argument( | |
| 16 | 3 | "Power law coefficient and exponent must be positive and finite"); | |
| 17 | } | ||
| 18 | 3270 | } | |
| 19 | |||
| 20 | 14984867 | double PowerLawSfd::CumulativeAt(double diameter) const { | |
| 21 | 14984867 | return m_law.Cumulative(diameter); | |
| 22 | } | ||
| 23 | |||
| 24 | 1061951 | double PowerLawSfd::IncrementalAt(double diameter) const { | |
| 25 | 1061951 | return m_law.Incremental(diameter); | |
| 26 | } | ||
| 27 | |||
| 28 | 1575530 | double PowerLawSfd::InvertCumulative(double target, double /*minDiameter*/, | |
| 29 | double /*maxDiameter*/) const { | ||
| 30 | 1575530 | return m_law.Invert(target); | |
| 31 | } | ||
| 32 | |||
| 33 | 195 | double PowerLawCoefficientFromKilometers(double coefficient, double exponent) { | |
| 34 | 195 | return coefficient * std::pow(1000.0, exponent) / 1e6; | |
| 35 | } | ||
| 36 | |||
| 37 | } // namespace terraingen | ||
| 38 |