TerrainGen coverage


terraingen/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
25 / 25
100.0%
Branches:
15 / 15
100.0%
Functions:
5 / 5
100.0%

layers/sample_block.cpp
Line Branch Exec Source
1 #include "terraingen/layers/sample_block.h"
2
3 #include "terraingen/raster/grid.h"
4
5 #include <algorithm>
6 #include <cmath>
7 #include <stdexcept>
8
9 namespace terraingen {
10
11 1614 SampleBlock::SampleBlock(Raster<float>& heights) : grid_(&heights), heights_(heights.Values()) {}
12
13 48180160 SampleBlock::SampleBlock(std::span<const Vec2d> positions, std::span<float> heights)
14 48180160 : positions_(positions), heights_(heights) {
15
2/2
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 48180159 times.
48180160 if (positions.size() != heights.size()) {
16
1/1
✓ Branch 2 taken 1 time.
1 throw std::invalid_argument("A sample block needs one height per position");
17 }
18 48180159 }
19
20 1417592999 Vec2d SampleBlock::Position(std::size_t i) const {
21
2/2
✓ Branch 0 taken 136453 times.
✓ Branch 1 taken 1417456546 times.
1417592999 if (grid_ != nullptr) {
22 136453 return grid_->CellCenter(i % grid_->Width(), i / grid_->Width());
23 }
24 1417456546 return positions_[i];
25 }
26
27 50379121 bool SampleBlock::IsNoData(std::size_t i) const {
28
2/2
✓ Branch 0 taken 136325 times.
✓ Branch 1 taken 50242796 times.
50379121 return grid_ != nullptr ? grid_->IsNoData(heights_[i]) : std::isnan(heights_[i]);
29 }
30
31 306458 Bounds2d SampleBlock::Bounds() const {
32
2/2
✓ Branch 0 taken 522 times.
✓ Branch 1 taken 305936 times.
306458 if (grid_ != nullptr) {
33
2/2
✓ Branch 1 taken 522 times.
✓ Branch 4 taken 522 times.
522 return RasterGrid::FromRaster(*grid_).Bounds();
34 }
35
2/2
✓ Branch 1 taken 20360 times.
✓ Branch 2 taken 285576 times.
305936 if (positions_.empty()) {
36 20360 return {};
37 }
38 285576 Bounds2d box = PointBounds(positions_[0].x, positions_[0].y);
39
2/2
✓ Branch 4 taken 1462465 times.
✓ Branch 5 taken 285576 times.
1748041 for (const Vec2d& p : positions_) {
40 1462465 const Bounds2d point = PointBounds(p.x, p.y);
41 1462465 box.minX = std::min(box.minX, point.minX);
42 1462465 box.minY = std::min(box.minY, point.minY);
43 1462465 box.maxX = std::max(box.maxX, point.maxX);
44 1462465 box.maxY = std::max(box.maxY, point.maxY);
45 }
46 285576 return box;
47 }
48
49 } // namespace terraingen
50