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

include/terraingen/layers/source_resolved.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief The feature size from which a source's measured data already holds a layer's features.
5 #pragma once
6
7 #include "terraingen/geometry/surface.h"
8 #include "terraingen/layers/field.h"
9 #include "terraingen/sources/source.h"
10
11 #include <memory>
12 #include <optional>
13
14 namespace terraingen {
15
16 /// The size in meters from which `source` resolves features at each point, `pixelsAcross` times
17 /// its resolution there; infinity where it resolves nothing.
18 /// @param pixelsAcross Source cells across a resolved feature; positive and finite.
19 /// @throws std::invalid_argument for a null source or a bad `pixelsAcross`.
20 std::shared_ptr<const SurfaceField> SourceResolvedLimit(std::shared_ptr<const Source> source,
21 double pixelsAcross,
22 const Surface& surface = {});
23
24 /// `SourceResolvedLimit` of a layer's `sourceResolvesPixels` over `source`, or null when either is
25 /// unset.
26 /// @throws std::invalid_argument as `SourceResolvedLimit`.
27 std::shared_ptr<const SurfaceField> LayerResolvedLimit(const std::shared_ptr<const Source>& source,
28 const std::optional<double>& pixelsAcross,
29 const Surface& surface);
30
31 /// The value of `LayerResolvedLimit` at surface (`x`, `y`) without building the field: the size in
32 /// meters from which `source` resolves features there, infinity when either is unset.
33 double SourceResolvedSize(const Source* source, const std::optional<double>& pixelsAcross,
34 const Surface& surface, double x, double y);
35
36 /// Checks a layer's `sourceResolvesPixels`.
37 /// @throws std::invalid_argument "Source resolves pixels must be positive and finite" for a set
38 /// value that is not.
39 void ValidateSourceResolvesPixels(const std::optional<double>& pixelsAcross);
40
41 /// Whether a feature `size` meters across at surface (`x`, `y`) is already in the source: at least
42 /// `limit` there. False without a limit, or where it is NaN or infinite.
43 33002 inline bool InSource(const SurfaceField* limit, double size, double x, double y) {
44
4/4
✓ Branch 0 taken 566 times.
✓ Branch 1 taken 32436 times.
✓ Branch 3 taken 481 times.
✓ Branch 4 taken 85 times.
33002 return limit != nullptr && size >= limit->ValueAt(x, y);
45 }
46
47 } // namespace terraingen
48