TerrainGen coverage


terraingen/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
4 / 4
100.0%
Branches:
-
-%
Functions:
2 / 2
100.0%

sources/flat_source.h
Line Branch Exec Source
1 /// @file
2 /// @brief A source of constant elevation, the start of a fully synthetic terrain.
3 #pragma once
4
5 #include "terraingen/sources/source.h"
6
7 #include <cstddef>
8
9 namespace terraingen {
10
11 /// A level datum at `elevation` over a `width` x `height` north-up grid of square
12 /// `pixelSize` cells centred on `centre`: the start of a fully synthetic terrain.
13 class FlatSource final : public Source {
14 public:
15 /// The flat source over the given grid.
16 /// @param width Columns, at least 1.
17 /// @param height Rows, at least 1.
18 /// @param pixelSize Cell size in world units (metres), positive and finite.
19 /// @param elevation Height of every cell in metres, finite.
20 /// @param centre Grid centre in world units, finite; the origin by default.
21 /// @throws std::invalid_argument if `width` or `height` is zero, `pixelSize` is not positive
22 /// and finite, or `elevation` or `centre` is not finite.
23 FlatSource(std::size_t width, std::size_t height, double pixelSize, float elevation = 0.0f,
24 Vec2d centre = {});
25
26 /// The grid given at construction.
27 219 RasterGrid Grid() const override {
28 219 return grid_;
29 }
30
31 /// Sets every cell of `heights` to the elevation.
32 void Fill(Raster<float>& heights) const override;
33
34 /// The elevation in metres, everywhere.
35 7788828 float HeightAt(double /*x*/, double /*y*/) const override {
36 7788828 return elevation_;
37 }
38
39 private:
40 RasterGrid grid_;
41 float elevation_;
42 };
43
44 } // namespace terraingen
45