./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
8 / 8
100.0%
Branches:
22 / 26
84.6%
Functions:
-
-%

include/terraingen/layers/craters/generation/spacing.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief Keeping craters of similar size apart: conflicts, precedence and thinning.
5 #pragma once
6
7 #include "terraingen/geometry/surface.h"
8 #include "terraingen/layers/craters/crater.h"
9
10 #include <limits>
11 #include <vector>
12
13 namespace terraingen {
14
15 /// Keeps craters of similar size apart: two conflict when their diameters differ by at most
16 /// `diameterRatio` and their centers are closer than `separation` times the larger diameter.
17 struct CraterSpacing {
18
4/4
✓ Branch 1 taken 13 times.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 3 times.
✓ Branch 5 taken 1 time.
85 CraterSpacing() = default;
19 /// Spacing with `diameterRatio` `ratio` and `separation` `minSeparation`.
20
4/5
<unknown function 18>:
✓ Branch 1 taken 2 times.
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
<unknown function 20>:
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
7 CraterSpacing(double ratio, double minSeparation)
21
2/5
✓ Branch 1 taken 1 time.
✗ Branch 3 not taken.
✗ Branch 6 not taken.
✗ Branch 9 not taken.
✓ Branch 14 taken 1 time.
16 : diameterRatio(ratio), separation(minSeparation) {}
22
23 double diameterRatio = 1.5; ///< At least 1.
24 double separation = 0.0; ///< In larger diameters; 0 disables spacing.
25 /// Craters at least this large (m) take precedence over smaller ones whatever their ages, as a
26 /// crater layer sets for the craters that throw secondaries a total map measures; infinite
27 /// ranks by age first. Not part of a configuration.
28 double outrankFrom = std::numeric_limits<double>::infinity();
29
30 /// Whether spacing applies: a positive `separation`.
31 3766973 bool Enabled() const {
32
12/12
<unknown function 18>:
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
<unknown function 31>:
✓ Branch 0 taken 43 times.
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 2 times.
✓ Branch 1 taken 264414 times.
✓ Branch 2 taken 778212 times.
✓ Branch 3 taken 654 times.
✓ Branch 4 taken 2454030 times.
✓ Branch 5 taken 4727 times.
✓ Branch 7 taken 36 times.
✓ Branch 8 taken 264780 times.
3766973 return separation > 0.0;
33 }
34
35 /// Memberwise equality.
36 bool operator==(const CraterSpacing& other) const {
37 return diameterRatio == other.diameterRatio && separation == other.separation &&
38 outrankFrom == other.outrankFrom;
39 }
40 bool operator!=(const CraterSpacing& other) const {
41 return !(*this == other);
42 }
43 };
44
45 /// Checks crater spacing settings.
46 /// @throws std::invalid_argument for a field outside its range (`CheckRanges`).
47 void ValidateCraterSpacing(const CraterSpacing& spacing);
48
49 /// Whether two craters are similar in size and closer than `spacing` allows, measured on
50 /// `surface`.
51 bool CratersConflict(const Crater& a, const Crater& b, const CraterSpacing& spacing,
52 const Surface& surface = {});
53
54 /// Whether `a` takes precedence over `b` when they conflict: a manual crater over a generated one,
55 /// then one at least `outrankFrom` meters across over one smaller, then the younger crater (which
56 /// would have overprinted the older), then the larger, then the smaller ID.
57 bool CraterTakesPrecedence(const Crater& a, const Crater& b,
58 double outrankFrom = std::numeric_limits<double>::infinity());
59
60 /// One flag per crater, true where it conflicts with a crater that takes precedence over it
61 /// (Matern type II thinning); manual craters are never marked.
62 /// @throws std::invalid_argument for invalid `spacing`.
63 std::vector<bool> SpacingConflicts(const CraterList& craters, const CraterSpacing& spacing,
64 const Surface& surface = {});
65
66 /// The craters `SpacingConflicts` does not mark, in their original order.
67 ///
68 /// For results that join across tiles, thin a list extending `SpacingReach` beyond the region and
69 /// crop afterwards, as `GenerateCraters` does.
70 /// @throws std::invalid_argument for invalid `spacing`.
71 CraterList ThinBySpacing(const CraterList& craters, const CraterSpacing& spacing,
72 const Surface& surface = {});
73
74 /// The farthest distance (m) at which a crater of `diameter` can conflict with another, given
75 /// the largest diameter `maxDiameter` of any other (m).
76 double SpacingReach(double diameter, double maxDiameter, const CraterSpacing& spacing);
77
78 } // namespace terraingen
79