src/sources/flat_source.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | #include "terraingen/sources/flat_source.h" | ||
| 4 | |||
| 5 | #include "util/checks.h" | ||
| 6 | |||
| 7 | #include <algorithm> | ||
| 8 | #include <cmath> | ||
| 9 | #include <stdexcept> | ||
| 10 | |||
| 11 | namespace terraingen { | ||
| 12 | |||
| 13 | 212 | FlatSource::FlatSource(std::size_t width, std::size_t height, double pixelSize, float elevation, | |
| 14 | 212 | Vec2d center) | |
| 15 | 212 | : m_elevation(elevation) { | |
| 16 | 212 | if (width == 0 || height == 0) { | |
| 17 | 3 | throw std::invalid_argument("A flat source needs at least one cell in each direction"); | |
| 18 | } | ||
| 19 | 209 | RequirePositive(pixelSize, "Pixel size"); | |
| 20 | 206 | if (!(std::isfinite(elevation) && std::isfinite(center.x) && std::isfinite(center.y))) { | |
| 21 | 2 | throw std::invalid_argument("Elevation and center must be finite"); | |
| 22 | } | ||
| 23 | 204 | const double halfX = 0.5 * static_cast<double>(width) * pixelSize; | |
| 24 | 204 | const double halfY = 0.5 * static_cast<double>(height) * pixelSize; | |
| 25 | 204 | m_grid = {width, height, GeoTransform::NorthUp(center.x - halfX, center.y + halfY, pixelSize)}; | |
| 26 | 204 | } | |
| 27 | |||
| 28 | 1930108 | void FlatSource::FillSamples(SampleBlock& samples, double /*spacing*/, unsigned /*threads*/) const { | |
| 29 | 1930108 | const Span<float> heights = samples.Heights(); | |
| 30 | 1930108 | std::fill(heights.begin(), heights.end(), m_elevation); | |
| 31 | 1930108 | } | |
| 32 | |||
| 33 | } // namespace terraingen | ||
| 34 |