layers/detail.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "terraingen/layers/detail.h" | ||
| 2 | |||
| 3 | #include <cmath> | ||
| 4 | #include <stdexcept> | ||
| 5 | #include <utility> | ||
| 6 | |||
| 7 | namespace terraingen { | ||
| 8 | |||
| 9 | 6 | DetailLayer::DetailLayer(std::shared_ptr<const Source> full, std::shared_ptr<const Source> smooth, | |
| 10 | 6 | double weight, Surface surface) | |
| 11 | 6 | : FormulaLayer(surface), full_(std::move(full)), smooth_(std::move(smooth)), weight_(weight) { | |
| 12 | 6 | if (!full_ || !smooth_) { | |
| 13 | 1 | throw std::invalid_argument("A detail layer needs both sources"); | |
| 14 | } | ||
| 15 | 5 | if (!std::isfinite(weight_)) { | |
| 16 | 1 | throw std::invalid_argument("Detail weight must be finite"); | |
| 17 | } | ||
| 18 | 10 | } | |
| 19 | |||
| 20 | 2291 | float DetailLayer::HeightAt(float height, double x, double y, double /*spacing*/, | |
| 21 | const Ground* /*ground*/) const { | ||
| 22 | 2291 | const float full = full_->HeightAt(x, y); | |
| 23 | 2291 | const float smooth = smooth_->HeightAt(x, y); | |
| 24 | 2291 | if (std::isnan(full) || std::isnan(smooth)) { | |
| 25 | 1 | return height; | |
| 26 | } | ||
| 27 | 2290 | return static_cast<float>(static_cast<double>(height) + | |
| 28 | 2290 | weight_ * (static_cast<double>(full) - static_cast<double>(smooth))); | |
| 29 | } | ||
| 30 | |||
| 31 | } // namespace terraingen | ||
| 32 |