TerrainGen coverage


terraingen/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
15 / 15
100.0%
Branches:
15 / 16
93.8%
Functions:
2 / 2
100.0%

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
4/4
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 215 times.
218 if (width == 0 || height == 0) {
15
1/1
✓ Branch 2 taken 3 times.
3 throw std::invalid_argument("A flat source needs at least one cell in each direction");
16 }
17
1/1
✓ Branch 2 taken 213 times.
215 RequirePositive(pixelSize, "Pixel size");
18
7/8
✓ Branch 1 taken 212 times.
✓ Branch 2 taken 1 time.
✓ Branch 4 taken 211 times.
✓ Branch 5 taken 1 time.
✗ Branch 7 not taken.
✓ Branch 8 taken 211 times.
✓ Branch 9 taken 2 times.
✓ Branch 10 taken 211 times.
213 if (!(std::isfinite(elevation) && std::isfinite(centre.x) && std::isfinite(centre.y))) {
19
1/1
✓ Branch 2 taken 2 times.
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
1/1
✓ Branch 5 taken 888 times.
888 std::fill(heights.Values().begin(), heights.Values().end(), elevation_);
28 888 }
29
30 } // namespace terraingen
31