TerrainGen coverage


terraingen/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
35 / 35
100.0%
Branches:
20 / 20
100.0%
Functions:
6 / 6
100.0%

raster/cell_loops.cpp
Line Branch Exec Source
1 #include "terraingen/raster/cell_loops.h"
2
3 #include <cmath>
4 #include <limits>
5
6 namespace terraingen {
7
8 namespace {
9
10 683900 std::size_t ClampTo(double value, std::size_t limit) {
11
1/1
✓ Branch 1 taken 683900 times.
683900 return static_cast<std::size_t>(std::clamp(value, 0.0, static_cast<double>(limit)));
12 }
13
14 } // namespace
15
16 170975 PixelWindow PixelWindowIn(const RasterGrid& grid, const Bounds2d& box) {
17 170975 const GeoTransform& transform = grid.transform;
18 170975 constexpr double kInf = std::numeric_limits<double>::infinity();
19 170975 double colMin = kInf;
20 170975 double colMax = -kInf;
21 170975 double rowMin = kInf;
22 170975 double rowMax = -kInf;
23
2/2
✓ Branch 2 taken 341950 times.
✓ Branch 3 taken 170975 times.
512925 for (const double wx : {box.minX, box.maxX}) {
24
2/2
✓ Branch 2 taken 683900 times.
✓ Branch 3 taken 341950 times.
1025850 for (const double wy : {box.minY, box.maxY}) {
25
1/1
✓ Branch 1 taken 683900 times.
683900 const Vec2d pixel = transform.WorldToPixel(wx, wy);
26 683900 colMin = std::fmin(colMin, pixel.x);
27 683900 colMax = std::fmax(colMax, pixel.x);
28 683900 rowMin = std::fmin(rowMin, pixel.y);
29 683900 rowMax = std::fmax(rowMax, pixel.y);
30 }
31 }
32 170975 return {ClampTo(std::floor(colMin), grid.width), ClampTo(std::ceil(colMax), grid.width),
33 170975 ClampTo(std::floor(rowMin), grid.height), ClampTo(std::ceil(rowMax), grid.height)};
34 }
35
36 3 PixelWindow PixelWindowIn(const Raster<float>& raster, const Bounds2d& box) {
37
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 return PixelWindowIn(RasterGrid::FromRaster(raster), box);
38 }
39
40 167902 std::vector<PixelWindow> PixelWindowsIn(const RasterGrid& grid, const Bounds2d& box,
41 const Surface& surface) {
42 167902 std::vector<PixelWindow> windows;
43 170972 const auto add = [&](double shift) {
44 const PixelWindow window =
45
1/1
✓ Branch 1 taken 170972 times.
170972 PixelWindowIn(grid, {box.minX + shift, box.minY, box.maxX + shift, box.maxY});
46
2/2
✓ Branch 1 taken 136003 times.
✓ Branch 2 taken 34969 times.
170972 if (!window.Empty()) {
47
1/1
✓ Branch 1 taken 136003 times.
136003 windows.push_back(window);
48 }
49 170972 };
50
2/2
✓ Branch 1 taken 166367 times.
✓ Branch 2 taken 1535 times.
167902 if (!surface.IsBody()) {
51
1/1
✓ Branch 1 taken 166367 times.
166367 add(0.0);
52 166367 return windows;
53 }
54
2/2
✓ Branch 2 taken 4605 times.
✓ Branch 3 taken 1535 times.
6140 for (const double shift : {-360.0, 0.0, 360.0}) {
55
1/1
✓ Branch 1 taken 4605 times.
4605 add(shift);
56 }
57 1535 return windows;
58 }
59
60 167227 std::vector<PixelWindow> PixelWindowsIn(const Raster<float>& raster, const Bounds2d& box,
61 const Surface& surface) {
62
2/2
✓ Branch 1 taken 167227 times.
✓ Branch 4 taken 167227 times.
167227 return PixelWindowsIn(RasterGrid::FromRaster(raster), box, surface);
63 }
64
65 } // namespace terraingen
66