./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
7 / 7
100.0%
Branches:
11 / 18
61.1%
Functions:
1 / 1, 1 excl
100.0%

include/terraingen/sources/flat_source.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief A source of constant elevation, the start of a fully synthetic terrain.
5 #pragma once
6
7 #include "terraingen/geometry/surface.h"
8 #include "terraingen/sources/source.h"
9
10 #include <cstddef>
11
12 namespace terraingen {
13
14 /// A level datum at `elevation` over a `width` x `height` north-up grid of square
15 /// `pixelSize` cells centered on `center`: the start of a fully synthetic terrain.
16
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
202 class FlatSource final : public Source {
17 public:
18 /// The flat source over the given grid.
19 /// @param width Columns, at least 1.
20 /// @param height Rows, at least 1.
21 /// @param pixelSize Cell size in world units (meters), positive and finite.
22 /// @param elevation Height of every cell in meters, finite.
23 /// @param center Grid center in world units, finite; the origin by default.
24 /// @throws std::invalid_argument if `width` or `height` is zero, `pixelSize` is not positive
25 /// and finite, or `elevation` or `center` is not finite.
26 FlatSource(std::size_t width, std::size_t height, double pixelSize, float elevation = 0.0f,
27 Vec2d center = {});
28
29 /// The flat source over a grid on `surface` whose cell size is given in meters, as for a site
30 /// on a body: the grid is in the surface's coordinates.
31 /// @param pixelSize Cell size in meters, positive and finite; on a body it is converted to
32 /// degrees along a meridian (`Surface::UnitLength`).
33 /// @param center Grid center in the surface's coordinates (longitude and latitude in degrees on
34 /// a body).
35 /// @throws std::invalid_argument as the constructor in world units.
36 111 FlatSource(std::size_t width, std::size_t height, double pixelSize, float elevation,
37 Vec2d center, const Surface& surface)
38
6/9
✓ Branch 0 taken 10 times.
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 98 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 8 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
123 : FlatSource(width, height, pixelSize / surface.UnitLength(), elevation, center) {}
39
40 /// The grid given at construction.
41 187 RasterGrid Grid() const override {
42
3/3
✓ Branch 1 taken 1 time.
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 1 time.
187 return m_grid;
43 }
44
45 protected:
46 /// Sets every sample to the elevation.
47 void FillSamples(SampleBlock& samples, double spacing, unsigned threads) const override;
48
49 private:
50 RasterGrid m_grid;
51 float m_elevation;
52 };
53
54 } // namespace terraingen
55