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

include/terraingen/layers/craters/rays.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief The directions of a crater's rays, shared by its secondaries and its bright streaks.
5 #pragma once
6
7 #include "terraingen/layers/craters/crater.h"
8 #include "terraingen/random/value_distribution.h"
9
10 #include <cstdint>
11 #include <vector>
12
13 namespace terraingen {
14
15 /// How many rays a crater has and how wide they are, after Elliott et al. (2018), drawn from the
16 /// crater's ID and `seed`; layers given the same layout see the same rays.
17 struct RayLayout {
18 std::uint32_t seed = 0; ///< Seed of the directions.
19 /// Rays per crater, 0 to 64.
20 ValueDistribution count{ValueDistribution::Normal(10.7, 3.1).Clamped(6.0, 20.0)};
21 /// Angular width 2 radii from the center, in (0, 180) degrees.
22 ValueDistribution widthDegrees{ValueDistribution::Normal(22.0, 8.3).Clamped(5.4, 38.6)};
23
24 /// Memberwise equality.
25 1 bool operator==(const RayLayout& other) const {
26
2/4
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 return seed == other.seed && count == other.count && widthDegrees == other.widthDegrees;
27 }
28 bool operator!=(const RayLayout& other) const {
29 return !(*this == other);
30 }
31 };
32
33 /// Checks a ray layout.
34 /// @throws std::invalid_argument for a field outside its range (`CheckRanges`), invalid
35 /// distributions, a count that can be below 0 or above
36 /// 64, or widths outside (0, 180) degrees.
37 void ValidateRayLayout(const RayLayout& layout);
38
39 /// One ray of a crater.
40 struct RayDirection {
41 double azimuth = 0.0; ///< Radians counter-clockwise from east.
42 double sinHalfWidth = 0.0; ///< Sine of half its angular width 2 radii from the center.
43 std::uint32_t key = 0; ///< Varies what lies along the ray.
44 };
45
46 /// The rays of `crater` under `layout`, at uniform random azimuths.
47 std::vector<RayDirection> RayDirections(const Crater& crater, const RayLayout& layout);
48
49 } // namespace terraingen
50