./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
9 / 13
69.2%
Branches:
5 / 5
100.0%
Functions:
-
-%

src/layers/craters/shaping/crater_kernel.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief Prepared craters turned into the records the crater kernel shapes.
5 #pragma once
6
7 #include "terraingen/geometry/surface.h"
8 #include "terraingen/layers/craters/profiles/profile.h"
9 #include "terraingen/layers/craters/shaping/apply_options.h"
10 #include "terraingen/layers/craters/shaping/prepared.h"
11 #include "terraingen/layers/kernels/craters.h"
12
13 #include <cstdint>
14 #include <memory>
15 #include <vector>
16
17 namespace terraingen {
18
19 /// Cells of the row each crater's profile is tabulated in when the kernel does not know the
20 /// profile (`CraterProfileKind::Tabulated`).
21 constexpr std::uint32_t kProfileTableCells = 512;
22
23 /// The kernel form of `profile` shaped as `options` say. Profiles the kernel knows (Fassett and
24 /// Thomson, Martin, Parkes and Dunstan, complex and diffused forms of them) are evaluated in
25 /// closed form; any other, such as a profile of your own, is tabulated per crater from its
26 /// `Height`.
27 CraterShapeKernel MakeCraterShapeKernel(const CraterProfile& profile,
28 const CraterApplyOptions& options);
29
30 /// The frame in which kernels shape points of body `surface` around `crater` (`BodySplitOffset`),
31 /// its center split (`SplitCoordinate`).
32 CraterFrame MakeCraterFrame(const Surface& surface, const Crater& crater);
33
34 /// `value` as a float, and the float of what that leaves (`SplitDifference`).
35 7614844 inline void SplitCoordinate(double value, float& high, float& low) {
36 7614844 high = static_cast<float>(value);
37
3/3
✓ Branch 1 taken 343615 times.
✓ Branch 3 taken 3216 times.
✓ Branch 4 taken 78697 times.
425535 low = static_cast<float>(value - static_cast<double>(high));
38 }
39
40 /// Surface point `p` as kernels read it: its east and north on a plane, or its position
41 /// (`Surface::Position`) on a body, each split (`SplitCoordinate`).
42 SplitPoint MakeSplitPoint(const Surface& surface, const Vec2d& p);
43
44 /// `lists` as the kernels read them: each list's first entry and entry count appended to
45 /// `heads`, and the entries returned, never empty so a GPU can bind them.
46 std::vector<std::uint32_t> FlattenKernelLists(const std::vector<std::vector<std::uint32_t>>& lists,
47 std::vector<std::uint32_t>& heads);
48
49 /// Craters ready for the kernel: one record per crater, and the values that vary in length.
50
2/2
✓ Branch 1 taken 136 times.
✓ Branch 10 taken 454 times.
479181 struct CraterKernelBatch {
51 std::vector<CraterRecord> records;
52 std::vector<float> data;
53
54 /// Where the kernel reads `data`.
55 6520025 CraterData Data() const {
56 6520025 CraterData view;
57 6429211 view.values = data.data();
58 6520025 return view;
59 }
60 };
61
62 /// Sets the wall terraces of prepared crater `p` on its kernel record, their shape appended to
63 /// `data` (`KernelTerracedRadii`): none below the onset diameter, without `terraces.enabled` or
64 /// once worn below `terraces.minFreshness`. The floor edge is `profile`'s complex floor diameter,
65 /// else Pike's (1980, USGS PP 1046-C, eq. 15) 0.187 D^1.249 km; the bench's share of the
66 /// wall's slope sets benches `terraces.benchSlopeDegrees` steep on its mean slope.
67 void AppendKernelTerraces(const PreparedCrater& p, const CraterTerraces& terraces,
68 const CraterProfile& profile, CraterRecord& record,
69 std::vector<float>& data);
70
71 /// Sets the central peak massifs of prepared crater `p` on its kernel record, appended to `data`
72 /// (`KernelPeakMassifs`): none without `peaks.enabled`, for a `profile` that is not a
73 /// `ComplexCraterProfile` or below its transition diameter. Their roughness fades with the
74 /// crater's freshness, current over fresh depth.
75 void AppendKernelPeaks(const PreparedCrater& p, const CraterPeaks& peaks,
76 const CraterProfile& profile, CraterRecord& record,
77 std::vector<float>& data);
78
79 /// The records of `craters` of `prepared`, in order, with their datums as fitted; `profile`
80 /// tabulated for each when `kernel` asks for it. The data is never empty, so a GPU can bind it.
81 /// @throws std::invalid_argument for a crater state the profile rejects.
82 CraterKernelBatch MakeCraterKernelBatch(const CraterShapeKernel& kernel,
83 const CraterProfile& profile,
84 const std::vector<PreparedCrater>& prepared,
85 const std::vector<std::size_t>& craters,
86 const CraterApplyOptions& options);
87
88 } // namespace terraingen
89