| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/// @file |
| 2 |
|
|
/// @brief `Crater` and `CraterList`, and `CraterSelection`, which of them a model applies to. |
| 3 |
|
|
#pragma once |
| 4 |
|
|
|
| 5 |
|
|
#include <cstddef> |
| 6 |
|
|
#include <cstdint> |
| 7 |
|
|
#include <functional> |
| 8 |
|
|
#include <limits> |
| 9 |
|
|
#include <string_view> |
| 10 |
|
|
#include <vector> |
| 11 |
|
|
|
| 12 |
|
|
namespace terraingen { |
| 13 |
|
|
|
| 14 |
|
|
/// One crater: centre in surface coordinates, rim-to-rim diameter, age and a stable ID. |
| 15 |
|
|
struct Crater { |
| 16 |
|
821 |
double x = 0.0; ///< Surface x of the centre. |
| 17 |
|
821 |
double y = 0.0; ///< Surface y of the centre. |
| 18 |
|
821 |
double diameter = 0.0; ///< Rim-to-rim diameter (m). |
| 19 |
|
821 |
double ageGyr = 0.0; ///< Age (Gyr). |
| 20 |
|
821 |
std::uint64_t id = 0; ///< Stable ID. |
| 21 |
|
|
/// Placed by hand, identified in imagery or read from a catalog rather than generated; takes |
| 22 |
|
|
/// precedence over generated craters and is never removed by spacing. |
| 23 |
|
821 |
bool manual = false; |
| 24 |
|
|
|
| 25 |
6/12
✗ Branch 0 not taken.
✓ Branch 1 taken 821 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 821 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 821 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 821 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 821 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 821 times.
|
821 |
bool operator==(const Crater&) const = default; |
| 26 |
|
|
}; |
| 27 |
|
|
|
| 28 |
|
|
/// A stable ID for a manual crater that has none, hashed with `Philox4x32`: the same for the same |
| 29 |
|
|
/// crater in every run. |
| 30 |
|
|
/// @param diameter In metres. |
| 31 |
|
|
std::uint64_t ManualCraterId(double x, double y, double diameter); |
| 32 |
|
|
|
| 33 |
|
|
/// Craters stored as one array per field, so each column can be shared with NumPy or a GPU |
| 34 |
|
|
/// without copying. |
| 35 |
|
|
class CraterList { |
| 36 |
|
|
public: |
| 37 |
|
|
/// The number of craters. |
| 38 |
|
271248350 |
std::size_t Size() const { |
| 39 |
|
271248350 |
return id_.size(); |
| 40 |
|
|
} |
| 41 |
|
|
|
| 42 |
|
|
/// Whether the list holds no crater. |
| 43 |
|
3938180 |
bool Empty() const { |
| 44 |
|
3938180 |
return id_.empty(); |
| 45 |
|
|
} |
| 46 |
|
|
|
| 47 |
|
|
/// Reserves room for `count` craters in every column. |
| 48 |
|
|
void Reserve(std::size_t count); |
| 49 |
|
|
|
| 50 |
|
|
/// Appends a crater. |
| 51 |
|
|
void Append(const Crater& crater); |
| 52 |
|
|
|
| 53 |
|
|
/// Appends every crater of `other`, in its order. |
| 54 |
|
|
void Append(const CraterList& other); |
| 55 |
|
|
|
| 56 |
|
|
/// The crater at `index`. |
| 57 |
|
|
/// @throws std::out_of_range if `index` >= `Size()`. |
| 58 |
|
|
Crater At(std::size_t index) const; |
| 59 |
|
|
|
| 60 |
|
|
/// Surface x of every centre. |
| 61 |
|
136934 |
const std::vector<double>& X() const { |
| 62 |
|
136934 |
return x_; |
| 63 |
|
|
} |
| 64 |
|
|
|
| 65 |
|
|
/// Surface y of every centre. |
| 66 |
|
136969 |
const std::vector<double>& Y() const { |
| 67 |
|
136969 |
return y_; |
| 68 |
|
|
} |
| 69 |
|
|
|
| 70 |
|
|
/// Every diameter, in metres. |
| 71 |
|
129891 |
const std::vector<double>& Diameters() const { |
| 72 |
|
129891 |
return diameter_; |
| 73 |
|
|
} |
| 74 |
|
|
|
| 75 |
|
|
/// Every age, in Gyr. |
| 76 |
|
129881 |
const std::vector<double>& AgesGyr() const { |
| 77 |
|
129881 |
return ageGyr_; |
| 78 |
|
|
} |
| 79 |
|
|
|
| 80 |
|
|
/// Every ID. |
| 81 |
|
129945 |
const std::vector<std::uint64_t>& Ids() const { |
| 82 |
|
129945 |
return id_; |
| 83 |
|
|
} |
| 84 |
|
|
|
| 85 |
|
|
/// 1 for manual craters, 0 for generated ones; bytes so it can be shared without copying. |
| 86 |
|
8884923 |
const std::vector<std::uint8_t>& Manual() const { |
| 87 |
|
8884923 |
return manual_; |
| 88 |
|
|
} |
| 89 |
|
|
|
| 90 |
|
|
private: |
| 91 |
|
|
std::vector<double> x_; |
| 92 |
|
|
std::vector<double> y_; |
| 93 |
|
|
std::vector<double> diameter_; |
| 94 |
|
|
std::vector<double> ageGyr_; |
| 95 |
|
|
std::vector<std::uint64_t> id_; |
| 96 |
|
|
std::vector<std::uint8_t> manual_; |
| 97 |
|
|
}; |
| 98 |
|
|
|
| 99 |
|
|
/// The craters `keep(index, crater)` keeps, in their order. |
| 100 |
|
9285 |
template <typename Keep> CraterList FilterCraters(const CraterList& craters, const Keep& keep) { |
| 101 |
|
9285 |
CraterList kept; |
| 102 |
6/6
terraingen::CraterList terraingen::FilterCraters<FilterCraters_KeepsWhatThePredicateAcceptsInOrder_Test::TestBody()::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, FilterCraters_KeepsWhatThePredicateAcceptsInOrder_Test::TestBody()::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 2 taken 1 time.
terraingen::CraterList terraingen::FilterCraters<terraingen::(anonymous namespace)::Generation::CropToRegion(terraingen::CraterList const&, unsigned long) const::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::(anonymous namespace)::Generation::CropToRegion(terraingen::CraterList const&, unsigned long) const::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 2 taken 2950 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::(anonymous namespace)::Generation::KeepLargest(terraingen::CraterList const&, unsigned long&) const::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::(anonymous namespace)::Generation::KeepLargest(terraingen::CraterList const&, unsigned long&) const::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 2 taken 6 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::(anonymous namespace)::Generation::RemoveSpacingConflicts(terraingen::CraterList const&, unsigned long&) const::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::(anonymous namespace)::Generation::RemoveSpacingConflicts(terraingen::CraterList const&, unsigned long&) const::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 2 taken 37 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::BoulderLayer::EjectaCraters(terraingen::Bounds2d const&) const::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::BoulderLayer::EjectaCraters(terraingen::Bounds2d const&) const::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 2 taken 6287 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::ThinBySpacing(terraingen::CraterList const&, terraingen::CraterSpacing const&, terraingen::Surface const&)::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::ThinBySpacing(terraingen::CraterList const&, terraingen::CraterSpacing const&, terraingen::Surface const&)::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 2 taken 4 times.
|
9285 |
kept.Reserve(craters.Size()); |
| 103 |
12/12
terraingen::CraterList terraingen::FilterCraters<FilterCraters_KeepsWhatThePredicateAcceptsInOrder_Test::TestBody()::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, FilterCraters_KeepsWhatThePredicateAcceptsInOrder_Test::TestBody()::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 1 time.
terraingen::CraterList terraingen::FilterCraters<terraingen::(anonymous namespace)::Generation::CropToRegion(terraingen::CraterList const&, unsigned long) const::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::(anonymous namespace)::Generation::CropToRegion(terraingen::CraterList const&, unsigned long) const::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 7283297 times.
✓ Branch 2 taken 2950 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::(anonymous namespace)::Generation::KeepLargest(terraingen::CraterList const&, unsigned long&) const::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::(anonymous namespace)::Generation::KeepLargest(terraingen::CraterList const&, unsigned long&) const::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 14546 times.
✓ Branch 2 taken 6 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::(anonymous namespace)::Generation::RemoveSpacingConflicts(terraingen::CraterList const&, unsigned long&) const::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::(anonymous namespace)::Generation::RemoveSpacingConflicts(terraingen::CraterList const&, unsigned long&) const::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 29901 times.
✓ Branch 2 taken 37 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::BoulderLayer::EjectaCraters(terraingen::Bounds2d const&) const::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::BoulderLayer::EjectaCraters(terraingen::Bounds2d const&) const::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 15065 times.
✓ Branch 2 taken 6287 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::ThinBySpacing(terraingen::CraterList const&, terraingen::CraterSpacing const&, terraingen::Surface const&)::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::ThinBySpacing(terraingen::CraterList const&, terraingen::CraterSpacing const&, terraingen::Surface const&)::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 4 times.
|
7352110 |
for (std::size_t n = 0; n < craters.Size(); ++n) { |
| 104 |
6/6
terraingen::CraterList terraingen::FilterCraters<FilterCraters_KeepsWhatThePredicateAcceptsInOrder_Test::TestBody()::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, FilterCraters_KeepsWhatThePredicateAcceptsInOrder_Test::TestBody()::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 5 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::(anonymous namespace)::Generation::CropToRegion(terraingen::CraterList const&, unsigned long) const::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::(anonymous namespace)::Generation::CropToRegion(terraingen::CraterList const&, unsigned long) const::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 7283297 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::(anonymous namespace)::Generation::KeepLargest(terraingen::CraterList const&, unsigned long&) const::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::(anonymous namespace)::Generation::KeepLargest(terraingen::CraterList const&, unsigned long&) const::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 14546 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::(anonymous namespace)::Generation::RemoveSpacingConflicts(terraingen::CraterList const&, unsigned long&) const::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::(anonymous namespace)::Generation::RemoveSpacingConflicts(terraingen::CraterList const&, unsigned long&) const::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 29901 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::BoulderLayer::EjectaCraters(terraingen::Bounds2d const&) const::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::BoulderLayer::EjectaCraters(terraingen::Bounds2d const&) const::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 15065 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::ThinBySpacing(terraingen::CraterList const&, terraingen::CraterSpacing const&, terraingen::Surface const&)::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::ThinBySpacing(terraingen::CraterList const&, terraingen::CraterSpacing const&, terraingen::Surface const&)::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 11 times.
|
7342825 |
const Crater crater = craters.At(n); |
| 105 |
16/16
terraingen::CraterList terraingen::FilterCraters<FilterCraters_KeepsWhatThePredicateAcceptsInOrder_Test::TestBody()::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, FilterCraters_KeepsWhatThePredicateAcceptsInOrder_Test::TestBody()::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 2 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::(anonymous namespace)::Generation::CropToRegion(terraingen::CraterList const&, unsigned long) const::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::(anonymous namespace)::Generation::CropToRegion(terraingen::CraterList const&, unsigned long) const::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 7283297 times.
✓ Branch 3 taken 7281229 times.
✓ Branch 4 taken 2068 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::(anonymous namespace)::Generation::KeepLargest(terraingen::CraterList const&, unsigned long&) const::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::(anonymous namespace)::Generation::KeepLargest(terraingen::CraterList const&, unsigned long&) const::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 14546 times.
✓ Branch 3 taken 661 times.
✓ Branch 4 taken 13885 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::(anonymous namespace)::Generation::RemoveSpacingConflicts(terraingen::CraterList const&, unsigned long&) const::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::(anonymous namespace)::Generation::RemoveSpacingConflicts(terraingen::CraterList const&, unsigned long&) const::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 29901 times.
✓ Branch 3 taken 16289 times.
✓ Branch 4 taken 13612 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::BoulderLayer::EjectaCraters(terraingen::Bounds2d const&) const::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::BoulderLayer::EjectaCraters(terraingen::Bounds2d const&) const::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 12630 times.
✓ Branch 2 taken 2435 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::ThinBySpacing(terraingen::CraterList const&, terraingen::CraterSpacing const&, terraingen::Surface const&)::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::ThinBySpacing(terraingen::CraterList const&, terraingen::CraterSpacing const&, terraingen::Surface const&)::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 11 times.
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 4 times.
|
7342825 |
if (keep(n, crater)) { |
| 106 |
6/6
terraingen::CraterList terraingen::FilterCraters<FilterCraters_KeepsWhatThePredicateAcceptsInOrder_Test::TestBody()::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, FilterCraters_KeepsWhatThePredicateAcceptsInOrder_Test::TestBody()::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 3 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::(anonymous namespace)::Generation::CropToRegion(terraingen::CraterList const&, unsigned long) const::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::(anonymous namespace)::Generation::CropToRegion(terraingen::CraterList const&, unsigned long) const::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 7281229 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::(anonymous namespace)::Generation::KeepLargest(terraingen::CraterList const&, unsigned long&) const::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::(anonymous namespace)::Generation::KeepLargest(terraingen::CraterList const&, unsigned long&) const::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 661 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::(anonymous namespace)::Generation::RemoveSpacingConflicts(terraingen::CraterList const&, unsigned long&) const::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::(anonymous namespace)::Generation::RemoveSpacingConflicts(terraingen::CraterList const&, unsigned long&) const::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 16289 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::BoulderLayer::EjectaCraters(terraingen::Bounds2d const&) const::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::BoulderLayer::EjectaCraters(terraingen::Bounds2d const&) const::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 12630 times.
terraingen::CraterList terraingen::FilterCraters<terraingen::ThinBySpacing(terraingen::CraterList const&, terraingen::CraterSpacing const&, terraingen::Surface const&)::{lambda(unsigned long, terraingen::Crater const&)#1}>(terraingen::CraterList const&, terraingen::ThinBySpacing(terraingen::CraterList const&, terraingen::CraterSpacing const&, terraingen::Surface const&)::{lambda(unsigned long, terraingen::Crater const&)#1} const&):
✓ Branch 1 taken 7 times.
|
7310819 |
kept.Append(crater); |
| 107 |
|
|
} |
| 108 |
|
|
} |
| 109 |
|
9285 |
return kept; |
| 110 |
|
|
} |
| 111 |
|
|
|
| 112 |
|
|
/// Appends `manual` to `craters`, flagged manual and given a `ManualCraterId` where their ID is 0. |
| 113 |
|
|
/// @param keep Which craters to append; empty for all. |
| 114 |
|
|
/// @throws std::invalid_argument for a crater with a non-finite position, a diameter that is not |
| 115 |
|
|
/// positive and finite, or a negative or non-finite age, whether `keep` accepts it or not. |
| 116 |
|
|
void AppendManualCraters(const CraterList& manual, CraterList& craters, |
| 117 |
|
|
const std::function<bool(const Crater&)>& keep = {}); |
| 118 |
|
|
|
| 119 |
|
|
/// Which craters a model applies to, by diameter, age and whether manual. |
| 120 |
|
|
struct CraterSelection { |
| 121 |
|
43 |
double minDiameter = 0.0; ///< Smallest diameter (m). |
| 122 |
|
43 |
double maxDiameter = std::numeric_limits<double>::infinity(); ///< Largest diameter (m). |
| 123 |
|
43 |
double minAgeGyr = 0.0; ///< Youngest age (Gyr). |
| 124 |
|
43 |
double maxAgeGyr = std::numeric_limits<double>::infinity(); ///< Oldest age (Gyr). |
| 125 |
|
43 |
bool manual = true; ///< Whether manual craters are included. |
| 126 |
|
|
|
| 127 |
|
|
/// Whether a crater is selected: not for a manual crater without `manual`, or a diameter or age |
| 128 |
|
|
/// outside its range. |
| 129 |
|
|
bool Includes(const Crater& crater) const; |
| 130 |
|
|
|
| 131 |
5/10
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 43 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 43 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 43 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 43 times.
|
43 |
bool operator==(const CraterSelection&) const = default; |
| 132 |
|
|
}; |
| 133 |
|
|
|
| 134 |
|
|
/// Checks a crater selection. |
| 135 |
|
|
/// @param what What the selection is for, which starts the error message. |
| 136 |
|
|
/// @throws std::invalid_argument "<what> size and age ranges must satisfy 0 <= min <= max" |
| 137 |
|
|
/// otherwise. |
| 138 |
|
|
void ValidateCraterSelection(const CraterSelection& selection, std::string_view what); |
| 139 |
|
|
|
| 140 |
|
|
} // namespace terraingen |
| 141 |
|
|
|