sources/flat_source.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "terraingen/sources/flat_source.h" | ||
| 2 | |||
| 3 | #include "terraingen/util/checks.h" | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <cmath> | ||
| 7 | #include <stdexcept> | ||
| 8 | |||
| 9 | namespace terraingen { | ||
| 10 | |||
| 11 | 218 | FlatSource::FlatSource(std::size_t width, std::size_t height, double pixelSize, float elevation, | |
| 12 | 218 | Vec2d centre) | |
| 13 | 218 | : elevation_(elevation) { | |
| 14 | 218 | if (width == 0 || height == 0) { | |
| 15 | 3 | throw std::invalid_argument("A flat source needs at least one cell in each direction"); | |
| 16 | } | ||
| 17 | 215 | RequirePositive(pixelSize, "Pixel size"); | |
| 18 | 213 | if (!(std::isfinite(elevation) && std::isfinite(centre.x) && std::isfinite(centre.y))) { | |
| 19 | 2 | throw std::invalid_argument("Elevation and centre must be finite"); | |
| 20 | } | ||
| 21 | 211 | const double halfX = 0.5 * static_cast<double>(width) * pixelSize; | |
| 22 | 211 | const double halfY = 0.5 * static_cast<double>(height) * pixelSize; | |
| 23 | 211 | grid_ = {width, height, GeoTransform::NorthUp(centre.x - halfX, centre.y + halfY, pixelSize)}; | |
| 24 | 218 | } | |
| 25 | |||
| 26 | 888 | void FlatSource::Fill(Raster<float>& heights) const { | |
| 27 | 888 | std::fill(heights.Values().begin(), heights.Values().end(), elevation_); | |
| 28 | 888 | } | |
| 29 | |||
| 30 | } // namespace terraingen | ||
| 31 |