./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
16 / 16
100.0%
Branches:
11 / 12
91.7%
Functions:
2 / 2
100.0%

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
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 209 times.
212 : m_elevation(elevation) {
16
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 209 times.
212 if (width == 0 || height == 0) {
17
1/1
✓ Branch 2 taken 3 times.
3 throw std::invalid_argument("A flat source needs at least one cell in each direction");
18 }
19 209 RequirePositive(pixelSize, "Pixel size");
20
5/6
✓ Branch 0 taken 205 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 204 times.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
✓ Branch 5 taken 204 times.
206 if (!(std::isfinite(elevation) && std::isfinite(center.x) && std::isfinite(center.y))) {
21
1/1
✓ Branch 2 taken 2 times.
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