distribution/production_surface.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "terraingen/distribution/production_surface.h" | ||
| 2 | |||
| 3 | #include <stdexcept> | ||
| 4 | #include <utility> | ||
| 5 | |||
| 6 | namespace terraingen { | ||
| 7 | |||
| 8 | 467 | ProductionSurface::ProductionSurface(std::shared_ptr<const SizeFrequencyDistribution> production, | |
| 9 | 467 | double ageGyr, const Chronology& chronology) | |
| 10 | : SizeFrequencyDistribution(SfdKind::Density, | ||
| 11 | 466 | production ? production->ValidRange() : DiameterRange{}), | |
| 12 | 933 | production_(std::move(production)), ageGyr_(ageGyr) { | |
| 13 | 467 | if (!production_ || production_->Kind() != SfdKind::ProductionRate) { | |
| 14 | 3 | throw std::invalid_argument("A production surface needs a production rate distribution"); | |
| 15 | } | ||
| 16 | 464 | if (!chronology) { | |
| 17 | 2 | throw std::invalid_argument("A production surface needs a chronology"); | |
| 18 | } | ||
| 19 | 462 | SetAllowExtrapolation(production_->AllowsExtrapolation()); | |
| 20 | 462 | scale_ = chronology(ageGyr_) / production_->Cumulative(1000.0); | |
| 21 | 477 | } | |
| 22 | |||
| 23 | 7043468 | double ProductionSurface::CumulativeAt(double diameter) const { | |
| 24 | 7043468 | return scale_ * CumulativeOf(*production_, diameter); | |
| 25 | } | ||
| 26 | |||
| 27 | 6 | double ProductionSurface::IncrementalAt(double diameter) const { | |
| 28 | 6 | return scale_ * IncrementalOf(*production_, diameter); | |
| 29 | } | ||
| 30 | |||
| 31 | 105766 | double ProductionSurface::InvertCumulative(double target, double dMin, double dMax) const { | |
| 32 | 105766 | return InvertCumulativeOf(*production_, target / scale_, dMin, dMax); | |
| 33 | } | ||
| 34 | |||
| 35 | } // namespace terraingen | ||
| 36 |