./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
3 / 3
100.0%
Branches:
7 / 9
77.8%
Functions:
-
-%

include/terraingen/layers/craters/shaping/prepared.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief `PreparedCrater`, a crater with everything needed to shape it at one sample spacing.
5 #pragma once
6
7 #include "terraingen/geometry/plane_fit.h"
8 #include "terraingen/layers/craters/crater.h"
9 #include "terraingen/layers/craters/degradation/degradation_model.h"
10 #include "terraingen/layers/craters/shaping/apply_options.h"
11 #include "terraingen/layers/craters/shaping/irregularity.h"
12
13 #include <functional>
14 #include <optional>
15 #include <vector>
16
17 namespace terraingen {
18
19 /// A crater ready to shape at one sample spacing.
20
0/2
✗ Branch 22 not taken.
✗ Branch 23 not taken.
906446 struct PreparedCrater {
21 Crater crater; ///< The crater.
22 double resolution = 1.0; ///< `ResolutionWeight` at the sample spacing.
23 CraterState state; ///< Its degradation state.
24 CraterOutline outline{}; ///< Its outline.
25 std::optional<Plane> datum{}; ///< From `FitCraterDatum`; none without a datum.
26 /// Its asymmetry on the ground beneath (`ShapeOnSlopes`); level without a slope response.
27 CraterSlopeShape slope{};
28 };
29
30 /// How far (m) from its center `prepared` reaches at `reachRadii` radii, stretched by its outline.
31 4107197 inline double CraterReach(const PreparedCrater& prepared, double reachRadii) {
32
7/7
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 7733 times.
✓ Branch 4 taken 1 time.
✓ Branch 4 taken 2787 times.
✓ Branch 5 taken 4946 times.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
4107197 return prepared.outline.MaxScale() * reachRadii * (0.5 * prepared.crater.diameter);
33 }
34
35 struct CraterShapeModels;
36
37 /// Whose outlines and states `PrepareCraters` may reuse from those a thread prepared before: an
38 /// `EvaluationCache::Id` and the layer that owns the craters; a zero `cache` reuses nothing. The
39 /// owner must prepare each crater with the same options, models and reshaping every time.
40 struct PreparedReuse {
41 std::uint64_t cache = 0;
42 const void* owner = nullptr;
43 };
44
45 /// The craters resolved at `spacing`, prepared in `CraterApplyOrder` without datums.
46 /// @param spacing Sample spacing in meters; positive.
47 /// @param models Neither may be null.
48 /// @param threads Threads to prepare the craters over; 0 for every hardware thread.
49 /// @param reshape Changes each outline when set; called on several threads at once.
50 /// @throws std::domain_error as `DegradationModel::State`.
51 /// @throws std::invalid_argument as `ResolvedCraterState`.
52 std::vector<PreparedCrater>
53 PrepareCraters(const CraterList& craters, const CraterApplyOptions& options, double spacing,
54 const CraterShapeModels& models, unsigned threads,
55 const std::function<void(const Crater&, CraterOutline&)>& reshape = {},
56 PreparedReuse reuse = {});
57
58 } // namespace terraingen
59