TerrainGen coverage


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

layers/ground.h
Line Branch Exec Source
1 /// @file
2 /// @brief The terrain beneath a layer, readable at any point.
3 #pragma once
4
5 #include "terraingen/util/geometry.h"
6
7 #include <cstddef>
8 #include <functional>
9 #include <span>
10
11 namespace terraingen {
12
13 /// Heights of the ground at world positions, NaN where there is none; thread-safe.
14 using HeightSampler = std::function<float(double x, double y)>;
15
16 /// The terrain beneath a layer (its source and the layers before it), readable anywhere.
17 ///
18 /// Layers that depend on the shape of the ground, such as craters cut to a datum, read it here
19 /// rather than from cells they changed, so they agree on every grid, tile and point.
20 /// Implementations must be deterministic and thread-safe.
21 class Ground {
22 public:
23 46637926 virtual ~Ground() = default;
24
25 /// The ground's height at world (x, y), or NaN where there is no data.
26 /// @param spacing Sample spacing in world units.
27 virtual float HeightAt(double x, double y, double spacing) const = 0;
28
29 /// `HeightAt` at each of `points`, into `heights` of the same size; implementations may read
30 /// them all in one pass, to the same values.
31 676 virtual void HeightsAt(std::span<const Vec2d> points, std::span<float> heights,
32 double spacing) const {
33
2/2
✓ Branch 1 taken 380511 times.
✓ Branch 2 taken 676 times.
381187 for (std::size_t i = 0; i < points.size(); ++i) {
34 380511 heights[i] = HeightAt(points[i].x, points[i].y, spacing);
35 }
36 676 }
37
38 /// A sampler reading `HeightAt` at a fixed spacing; `*this` must outlive it.
39 220550 HeightSampler Sampler(double spacing) const {
40 1497442 return [this, spacing](double x, double y) { return HeightAt(x, y, spacing); };
41 }
42 };
43
44 } // namespace terraingen
45