./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
208 / 209
99.5%
Branches:
146 / 152
96.1%
Functions:
22 / 22, 1 excl
100.0%

src/layers/craters/shaping/irregularity.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 #include "terraingen/layers/craters/shaping/irregularity.h"
4
5 #include "terraingen/layers/craters/crater_fields.h"
6 #include "terraingen/layers/fade.h"
7 #include "terraingen/random/samplers.h"
8 #include "terraingen/util/bits.h"
9 #include "util/fft.h"
10
11 #include <algorithm>
12 #include <cmath>
13 #include <complex>
14 #include <cstddef>
15 #include <cstdint>
16 #include <stdexcept>
17
18 namespace terraingen {
19
20 namespace {
21
22 /// How far a periodic Catmull-Rom spline can overshoot its knots, as a share of their largest
23 /// magnitude.
24 constexpr double kSplineOvershoot = 1.25;
25
26 /// The steepest slope of `Smoothstep`.
27 constexpr double kSmoothstepSlope = 1.5;
28
29 constexpr std::size_t kTableSize = 1024;
30
31 /// y = a D + b in a crater's diameter D (km), with one line up to 20 km and another above, as Du et
32 /// al. (2024, Table 2) fit their breakpoints; and its 1-sigma misfit on each side.
33 struct PiecewiseFit {
34 double a1, b1, sigma1, a2, b2, sigma2;
35
36 275 double At(double kilometers, double z) const {
37 15 return kilometers <= 20.0 ? a1 * kilometers + b1 + z * sigma1
38 260 : a2 * kilometers + b2 + z * sigma2;
39 }
40 };
41
42 /// The rim crest radial distance fits of Du et al. (2024, Table 2).
43 constexpr PiecewiseFit kSlope12{-0.022, 3.3, 0.54, -0.00019, 2.9, 0.22};
44 constexpr PiecewiseFit kLogWavelength2{0.010, -0.57, 0.27, -0.00035, -0.36, 0.27};
45 constexpr PiecewiseFit kLogPower2{0.043, 0.59, 0.55, 0.010, 1.2, 0.75};
46 constexpr PiecewiseFit kLogPower3{0.055, 2.3, 0.58, -0.0026, 3.5, 0.44};
47 constexpr PiecewiseFit kLogPower4{0.066, -1.1, 1.00, 0.0062, 0.059, 0.69};
48 constexpr double kSpectrumSigma = 0.55;
49 constexpr double kSpectrumVertices = 5000.0;
50
51 /// The breakpoints of one crater's rim spectrum, from the fits at its diameter.
52 struct DuSpectrum {
53 double slope;
54 double logWavelength2;
55 double logPower2;
56 double logPower3;
57 double logPower4;
58
59 /// log10 power of harmonic `k`.
60 28105 double LogPower(std::size_t k) const {
61
2/2
✓ Branch 0 taken 55 times.
✓ Branch 1 taken 28050 times.
28105 if (k == 1) {
62 55 return logPower4;
63 }
64
2/2
✓ Branch 0 taken 55 times.
✓ Branch 1 taken 27995 times.
28050 if (k == 2) {
65 55 return logPower3;
66 }
67 27995 const double logPi = std::log10(kPi);
68 27995 const double logWavelength = std::log10(2.0 * kPi / static_cast<double>(k));
69
2/2
✓ Branch 0 taken 942 times.
✓ Branch 1 taken 27053 times.
27995 if (logWavelength >= logWavelength2) {
70 942 return logPower2 + (logWavelength - logWavelength2) / (logPi - logWavelength2) *
71 942 (logPower3 - logPower2);
72 }
73 27053 return logPower2 + slope * (logWavelength - logWavelength2);
74 }
75 };
76
77 /// `table` scaled down so that no value exceeds `maxDeviation` in magnitude.
78 55 void LimitDeviation(std::vector<double>& table, double maxDeviation) {
79 55 double largest = 0.0;
80
2/2
✓ Branch 0 taken 56320 times.
✓ Branch 1 taken 55 times.
56375 for (const double value : table) {
81 56320 largest = std::fmax(largest, std::fabs(value));
82 }
83
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 3 times.
55 if (largest > maxDeviation) {
84
2/2
✓ Branch 0 taken 53248 times.
✓ Branch 1 taken 52 times.
53300 for (double& value : table) {
85 53248 value *= maxDeviation / largest;
86 }
87 }
88 55 }
89
90 55 std::vector<double> DuRimTable(double diameter, bool scatter, double maxDeviation,
91 RandomStream& random) {
92
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 54 times.
55 const double kilometers = std::clamp(diameter / 1000.0, 1.0, 140.0);
93
2/2
✓ Branch 0 taken 265 times.
✓ Branch 1 taken 10 times.
275 const auto draw = [&] { return scatter ? StandardNormal(random) : 0.0; };
94 55 DuSpectrum fit{};
95
2/2
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 52 times.
55 fit.slope = kSlope12.At(kilometers, draw());
96
2/2
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 52 times.
55 fit.logWavelength2 = kLogWavelength2.At(kilometers, draw());
97
2/2
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 52 times.
55 fit.logPower2 = kLogPower2.At(kilometers, draw());
98
2/2
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 52 times.
55 fit.logPower3 = kLogPower3.At(kilometers, draw());
99
2/2
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 52 times.
55 fit.logPower4 = kLogPower4.At(kilometers, draw());
100 55 std::vector<std::complex<double>> spectrum(kTableSize);
101
2/2
✓ Branch 0 taken 28105 times.
✓ Branch 1 taken 55 times.
28160 for (std::size_t k = 1; k < kTableSize / 2; ++k) {
102
3/3
✓ Branch 0 taken 27083 times.
✓ Branch 1 taken 1022 times.
✓ Branch 3 taken 27083 times.
28105 const double noise = scatter ? kSpectrumSigma * StandardNormal(random) : 0.0;
103 28105 const double amplitude =
104 28105 std::sqrt(std::pow(10.0, fit.LogPower(k) + noise) * 2.0 * kPi) / kSpectrumVertices;
105
1/1
✓ Branch 1 taken 28105 times.
28105 const double phase = 2.0 * kPi * random.NextDouble();
106 28105 spectrum[k] = std::complex<double>(0.0, -1.0) * std::polar(amplitude, phase);
107 }
108
1/1
✓ Branch 1 taken 55 times.
55 Fft(spectrum, 1.0);
109
1/1
✓ Branch 1 taken 55 times.
55 std::vector<double> table(kTableSize);
110
2/2
✓ Branch 0 taken 56320 times.
✓ Branch 1 taken 55 times.
56375 for (std::size_t n = 0; n < kTableSize; ++n) {
111 56320 table[n] = spectrum[n].real();
112 }
113 55 LimitDeviation(table, maxDeviation);
114 55 return table;
115 55 }
116
117 /// Harmonics of a rim table the crater kernel follows toward the center one by one, as it does a
118 /// power-law outline's; the table's finer rest fades as fast as the first harmonic past them. Set
119 /// by eye to match the default highest power-law harmonic, not from a measurement.
120 constexpr int kTableBroadHarmonics = 12;
121
122 /// Appends the (amplitude, phase) pairs of harmonics 1 to `kTableBroadHarmonics` of the periodic
123 /// `table` to `data`, as cosines of the angle plus the phase, the way the kernel reads harmonics.
124 22478 void AppendBroadHarmonics(const std::vector<double>& table, std::vector<float>& data) {
125 22478 const double size = static_cast<double>(table.size());
126
2/2
✓ Branch 0 taken 269736 times.
✓ Branch 1 taken 22478 times.
292214 for (int k = 1; k <= kTableBroadHarmonics; ++k) {
127 double re = 0.0;
128 double im = 0.0;
129
2/2
✓ Branch 0 taken 276209664 times.
✓ Branch 1 taken 269736 times.
276479400 for (std::size_t n = 0; n < table.size(); ++n) {
130 276209664 const double angle = 2.0 * kPi * k * static_cast<double>(n) / size;
131 276209664 re += table[n] * std::cos(angle);
132 276209664 im -= table[n] * std::sin(angle);
133 }
134 269736 data.push_back(static_cast<float>(2.0 * std::hypot(re, im) / size));
135 269736 data.push_back(static_cast<float>(std::atan2(im, re)));
136 }
137 22478 }
138
139 /// sum over k of k^-slope squared, from `first` to `last`.
140 316732 double PowerSum(int first, int last, double slope) {
141 316732 double sum = 0.0;
142
2/2
✓ Branch 0 taken 3483497 times.
✓ Branch 1 taken 316732 times.
3800229 for (int k = first; k <= last; ++k) {
143 3483497 sum += std::pow(static_cast<double>(k), -2.0 * slope);
144 }
145 316732 return sum;
146 }
147
148 /// The uniforms an outline is drawn from, in the order drawn.
149 struct OutlineDraws {
150 double rough, elongated, r1, r2, s1, s2, e1, e2, h;
151 };
152
153 336717 OutlineDraws DrawOutline(RandomStream& random) {
154 336717 OutlineDraws draws{};
155 6395438 for (double* draw : {&draws.rough, &draws.elongated, &draws.r1, &draws.r2, &draws.s1, &draws.s2,
156
2/2
✓ Branch 0 taken 3029313 times.
✓ Branch 1 taken 336812 times.
3366125 &draws.e1, &draws.e2, &draws.h}) {
157 3029313 *draw = random.NextDouble();
158 }
159 336812 return draws;
160 }
161
162 /// Adds the power-law harmonics of `irregularity` to `outline`.
163 316682 void AddHarmonics(CraterOutline& outline, const CraterIrregularity& irregularity,
164 const OutlineDraws& draws, RandomStream& random) {
165 316682 const double roughness = irregularity.roughness.Sample(draws.r1, draws.r2);
166 316724 const double slope = irregularity.spectralSlope.Sample(draws.s1, draws.s2);
167 633521 const double norm = roughness * std::sqrt(2.0 / PowerSum(irregularity.minHarmonic,
168 316734 irregularity.maxHarmonic, slope));
169 316787 outline.firstHarmonic = irregularity.minHarmonic;
170
1/2
✓ Branch 0 taken 316787 times.
✗ Branch 1 not taken.
316787 if (roughness > 0.0) {
171
2/2
✓ Branch 0 taken 3480312 times.
✓ Branch 1 taken 316704 times.
3797016 for (int k = irregularity.minHarmonic; k <= irregularity.maxHarmonic; ++k) {
172 3480312 outline.amplitudes.push_back(norm * std::pow(static_cast<double>(k), -slope));
173 3479884 outline.phases.push_back(2.0 * kPi * random.NextDouble());
174 }
175 }
176 316704 }
177
178 /// Checks the radial marks of crater irregularity.
179 /// @throws std::invalid_argument as `ValidateCraterIrregularity`.
180 161500 void ValidateRadialMarks(const CraterIrregularity& irregularity) {
181 161500 ValidateValueDistribution(irregularity.marksAmplitude);
182 161692 const double fade = irregularity.marksFadeRadii;
183
2/2
✓ Branch 0 taken 161691 times.
✓ Branch 1 taken 1 time.
161692 if (!(irregularity.marksInnerRadii - fade >= 0.0 &&
184
2/2
✓ Branch 0 taken 161690 times.
✓ Branch 1 taken 1 time.
161691 irregularity.marksInnerRadii <= irregularity.marksOuterRadii &&
185
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 161689 times.
161690 irregularity.marksOuterRadii + fade <= 1.0)) {
186 3 throw std::invalid_argument("Crater marks need 0 <= inner - fade, inner <= outer and "
187
1/1
✓ Branch 2 taken 3 times.
3 "outer + fade <= 1 radii");
188 }
189
2/2
✓ Branch 1 taken 161678 times.
✓ Branch 2 taken 1 time.
161689 if (!(irregularity.marksAmplitude.Lowest() >= 0.0 &&
190
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 161689 times.
161678 2.0 * kSplineOvershoot * kSmoothstepSlope * irregularity.marksAmplitude.Highest() <
191 fade)) {
192 2 throw std::invalid_argument("Crater mark amplitude must not be negative, and below fade / "
193
1/1
✓ Branch 2 taken 2 times.
2 "3.75 radii so walls cannot fold");
194 }
195 161689 }
196
197 } // namespace
198
199 161330 void ValidateCraterIrregularity(const CraterIrregularity& irregularity) {
200 161330 CheckRanges(irregularity);
201 161786 ValidateValueDistribution(irregularity.roughness);
202 161672 ValidateValueDistribution(irregularity.spectralSlope);
203 161684 ValidateValueDistribution(irregularity.ellipticity);
204 161626 ValidateCraterSelection(irregularity.selection, "Crater irregularity");
205
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 160986 times.
160986 if (irregularity.minHarmonic > irregularity.maxHarmonic) {
206
0/1
✗ Branch 2 not taken.
✗ throw std::invalid_argument("Crater min_harmonic must be at most max_harmonic");
207 }
208 160986 const int harmonics = irregularity.maxHarmonic - irregularity.minHarmonic + 1;
209
2/2
✓ Branch 1 taken 161613 times.
✓ Branch 2 taken 1 time.
160986 if (!(irregularity.roughness.Lowest() >= 0.0 &&
210
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 161266 times.
161613 irregularity.roughness.Highest() * std::sqrt(2.0 * harmonics) < 0.5)) {
211 2 throw std::invalid_argument(
212 "Crater roughness must not be negative, and at most 0.5 / sqrt(2 n) radii for n "
213
1/1
✓ Branch 2 taken 2 times.
2 "harmonics, so rims cannot fold");
214 }
215
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 161511 times.
161266 if (!(irregularity.ellipticity.Lowest() >= 1.0)) {
216
1/1
✓ Branch 2 taken 1 time.
1 throw std::invalid_argument("Crater ellipticity must be at least 1");
217 }
218 161511 ValidateRadialMarks(irregularity);
219 161666 }
220
221 93249 double CraterOutline::Scale(double dx, double dy) const {
222
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 93248 times.
93249 return Round() ? 1.0 : KernelOutline(*this, 1.0).Scale({dx, dy});
223 }
224
225 29276 double CraterOutline::MarkShift(double dx, double dy, double radii) const {
226
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 29276 times.
29276 return marks.empty() ? 0.0 : KernelOutline(*this, 1.0).MarkShift({dx, dy}, radii);
227 }
228
229 4615103 double CraterOutline::MaxScale() const {
230 4615103 double sum = 1.0;
231
2/2
✓ Branch 0 taken 51200 times.
✓ Branch 1 taken 4615103 times.
4666303 for (const double deviation : table) {
232 51200 sum = std::fmax(sum, 1.0 + deviation);
233 }
234
2/2
✓ Branch 0 taken 44331980 times.
✓ Branch 1 taken 4615103 times.
48947083 for (const double amplitude : amplitudes) {
235 44331980 sum += std::fabs(amplitude);
236 }
237 4615103 return std::sqrt(ellipticity) * sum;
238 }
239
240 824323 CraterOutline IrregularOutline(const Crater& crater, const CraterIrregularity& irregularity) {
241 824323 CraterOutline outline;
242
5/5
✓ Branch 0 taken 812729 times.
✓ Branch 1 taken 11669 times.
✓ Branch 3 taken 812675 times.
✓ Branch 5 taken 336766 times.
✓ Branch 6 taken 475909 times.
824398 if (!irregularity.enabled || !irregularity.selection.Includes(crater)) {
243 return outline;
244 }
245
2/2
✓ Branch 0 taken 301410 times.
✓ Branch 1 taken 35356 times.
336766 const IdWords id = SplitId(crater.id);
246
3/3
✓ Branch 0 taken 301410 times.
✓ Branch 1 taken 35356 times.
✓ Branch 3 taken 336727 times.
638176 RandomStream random(irregularity.seed.value_or(0u), kCraterIrregularityStream, id.low, id.high);
247
1/1
✓ Branch 1 taken 336721 times.
336727 const OutlineDraws draws = DrawOutline(random);
248
2/2
✓ Branch 0 taken 23261 times.
✓ Branch 1 taken 313460 times.
336721 if (draws.elongated < irregularity.elongatedShare) {
249
1/1
✓ Branch 1 taken 23260 times.
23261 outline.ellipticity = irregularity.ellipticity.Sample(draws.e1, draws.e2);
250 23260 outline.heading =
251
2/2
✓ Branch 0 taken 1608 times.
✓ Branch 1 taken 21652 times.
23260 irregularity.headingDegrees
252
2/2
✓ Branch 0 taken 1608 times.
✓ Branch 1 taken 21652 times.
23260 ? (*irregularity.headingDegrees * kDegree) +
253 1608 (irregularity.headingSpreadDegrees * kDegree) * (2.0 * draws.h - 1.0)
254 21652 : kPi * draws.h;
255 }
256
4/4
✓ Branch 0 taken 316806 times.
✓ Branch 1 taken 19914 times.
✓ Branch 2 taken 55 times.
✓ Branch 3 taken 316751 times.
336720 if (draws.rough < irregularity.roughShare && irregularity.model == RimRoughnessModel::Du2024) {
257 110 outline.table =
258
1/1
✓ Branch 1 taken 55 times.
55 DuRimTable(crater.diameter, irregularity.scatter, irregularity.maxDeviation, random);
259
2/2
✓ Branch 0 taken 316652 times.
✓ Branch 1 taken 20013 times.
336665 } else if (draws.rough < irregularity.roughShare) {
260
1/1
✓ Branch 1 taken 316703 times.
316652 AddHarmonics(outline, irregularity, draws, random);
261 }
262
2/2
✓ Branch 0 taken 4605 times.
✓ Branch 1 taken 332166 times.
336771 if (irregularity.marksShare > 0.0) {
263
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 4605 times.
✓ Branch 3 taken 4605 times.
4605 RandomStream marks(irregularity.seed.value_or(0u), kCraterMarkStream, id.low, id.high);
264
1/1
✓ Branch 1 taken 4605 times.
4605 const double share = marks.NextDouble();
265
1/1
✓ Branch 1 taken 4605 times.
4605 const double amplitude = irregularity.marksAmplitude.Draw(marks);
266
4/4
✓ Branch 0 taken 1572 times.
✓ Branch 1 taken 3033 times.
✓ Branch 2 taken 1571 times.
✓ Branch 3 taken 1 time.
4605 if (share < irregularity.marksShare && amplitude > 0.0) {
267
1/1
✓ Branch 1 taken 1571 times.
1571 outline.marks.resize(static_cast<std::size_t>(irregularity.marksKnots));
268
2/2
✓ Branch 0 taken 70662 times.
✓ Branch 1 taken 1571 times.
72233 for (double& knot : outline.marks) {
269
1/1
✓ Branch 1 taken 70662 times.
70662 knot = amplitude * (2.0 * marks.NextDouble() - 1.0);
270 }
271 1571 outline.marksInnerRadii = irregularity.marksInnerRadii;
272 1571 outline.marksOuterRadii = irregularity.marksOuterRadii;
273 1571 outline.marksFadeRadii = irregularity.marksFadeRadii;
274 }
275 }
276 return outline;
277 }
278
279 4193 double MaxOutlineScale(const CraterIrregularity& irregularity) {
280
2/2
✓ Branch 0 taken 3482 times.
✓ Branch 1 taken 711 times.
4193 if (!irregularity.enabled) {
281 return 1.0;
282 }
283 3482 const int harmonics = irregularity.maxHarmonic - irregularity.minHarmonic + 1;
284 3482 double rough = 1.0;
285
1/2
✓ Branch 0 taken 3482 times.
✗ Branch 1 not taken.
3482 if (irregularity.roughShare > 0.0) {
286 3482 rough = irregularity.model == RimRoughnessModel::Du2024
287
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 3481 times.
3482 ? 1.0 + irregularity.maxDeviation
288 3481 : 1.0 + irregularity.roughness.Highest() * std::sqrt(2.0 * harmonics);
289 }
290 3482 const double elongated =
291
2/2
✓ Branch 0 taken 3461 times.
✓ Branch 1 taken 21 times.
3482 irregularity.elongatedShare > 0.0 ? std::sqrt(irregularity.ellipticity.Highest()) : 1.0;
292 3482 return rough * elongated;
293 }
294
295 2088667 void AppendKernelOutline(const CraterOutline& outline, CraterRecord& record,
296 std::vector<float>& data) {
297 2088667 record.ellipticity = static_cast<float>(outline.ellipticity);
298 2088667 record.heading = static_cast<float>(outline.heading);
299
2/2
✓ Branch 0 taken 2066189 times.
✓ Branch 1 taken 22478 times.
2088667 record.harmonicOffset = static_cast<std::uint32_t>(data.size());
300
2/2
✓ Branch 0 taken 2066189 times.
✓ Branch 1 taken 22478 times.
2088667 if (outline.table.empty()) {
301 2066189 record.firstHarmonic = static_cast<std::uint32_t>(outline.firstHarmonic);
302 2066189 record.harmonicCount = static_cast<std::uint32_t>(outline.amplitudes.size());
303
2/2
✓ Branch 0 taken 7342926 times.
✓ Branch 1 taken 2066175 times.
9409101 for (std::size_t n = 0; n < outline.amplitudes.size(); ++n) {
304 7342926 data.push_back(static_cast<float>(outline.amplitudes[n]));
305 7342883 data.push_back(static_cast<float>(outline.phases[n]));
306 }
307 } else {
308 22478 record.firstHarmonic = 1u;
309 22478 record.harmonicCount = static_cast<std::uint32_t>(kTableBroadHarmonics);
310 22478 AppendBroadHarmonics(outline.table, data);
311 }
312 2088713 record.tableCount = static_cast<std::uint32_t>(outline.table.size());
313 2088713 record.tableOffset = static_cast<std::uint32_t>(data.size());
314
2/2
✓ Branch 0 taken 23017476 times.
✓ Branch 1 taken 2088709 times.
25106185 for (const double deviation : outline.table) {
315 23017476 data.push_back(static_cast<float>(deviation));
316 }
317
2/2
✓ Branch 0 taken 76380 times.
✓ Branch 1 taken 2012329 times.
2088709 record.markCount = static_cast<std::uint32_t>(outline.marks.size());
318 2088709 record.markOffset = static_cast<std::uint32_t>(data.size());
319
2/2
✓ Branch 0 taken 76380 times.
✓ Branch 1 taken 2012329 times.
2088709 if (!outline.marks.empty()) {
320 534660 for (const double radii :
321
2/2
✓ Branch 0 taken 229140 times.
✓ Branch 1 taken 76380 times.
305520 {outline.marksInnerRadii, outline.marksOuterRadii, outline.marksFadeRadii}) {
322 229140 data.push_back(static_cast<float>(radii));
323 }
324
2/2
✓ Branch 0 taken 3296086 times.
✓ Branch 1 taken 76380 times.
3372466 for (const double knot : outline.marks) {
325 3296086 data.push_back(static_cast<float>(knot));
326 }
327 }
328 2088709 }
329
330 1744910 KernelOutline::KernelOutline(const CraterOutline& outline, double diameter)
331 1744910 : m_round(outline.Round()) {
332 1745137 m_record.diameter = static_cast<float>(diameter);
333 1745137 m_data.clear();
334
1/1
✓ Branch 1 taken 1745150 times.
1745121 AppendKernelOutline(outline, m_record, m_data);
335
2/2
✓ Branch 0 taken 1092526 times.
✓ Branch 1 taken 652624 times.
1745150 if (m_data.empty()) {
336
1/1
✓ Branch 1 taken 1092479 times.
1092526 m_data.push_back(0.0f);
337 }
338 1745103 }
339
340 93249 double KernelOutline::Scale(const Vec2d& offset) const {
341 186498 return static_cast<double>(KernelOutlineScale(Data(), m_record, static_cast<float>(offset.x),
342 93249 static_cast<float>(offset.y)));
343 }
344
345 29278 double KernelOutline::MarkShift(const Vec2d& offset, double radii) const {
346
2/2
✓ Branch 0 taken 29277 times.
✓ Branch 1 taken 1 time.
29278 if (m_record.markCount == 0u) {
347 return 0.0;
348 }
349 29277 return static_cast<double>(KernelMarkShift(Data(), m_record, static_cast<float>(offset.x),
350 29277 static_cast<float>(offset.y),
351 29277 static_cast<float>(radii)));
352 }
353
354 2727768 double KernelOutline::ProfileDistance(const Vec2d& offset) const {
355
2/2
✓ Branch 0 taken 2113773 times.
✓ Branch 1 taken 613995 times.
2727768 if (m_round) {
356 2113773 return std::sqrt(offset.x * offset.x + offset.y * offset.y);
357 }
358 613995 return static_cast<double>(KernelProfileDistance(Data(), m_record, static_cast<float>(offset.x),
359 613995 static_cast<float>(offset.y)));
360 }
361
362 135802 double CraterProfileDistance(const Crater& crater, const CraterOutline& outline, double x, double y,
363 const Surface& surface) {
364 135802 return CraterProfileDistance(crater, outline, surface.Offset({crater.x, crater.y}, {x, y}));
365 }
366
367 135803 double CraterProfileDistance(const Crater& crater, const CraterOutline& outline,
368 const Vec2d& offset) {
369 135803 return KernelOutline(outline, crater.diameter).ProfileDistance(offset);
370 }
371
372 } // namespace terraingen
373