src/layers/craters/crater_layer.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | #include "terraingen/layers/craters/crater_layer.h" | ||
| 4 | |||
| 5 | #include "layers/craters/generation/cell_cache.h" | ||
| 6 | #include "layers/craters/shaping/resolved_state.h" | ||
| 7 | #include "terraingen/distribution/equilibrium.h" | ||
| 8 | #include "terraingen/distribution/neukum.h" | ||
| 9 | #include "terraingen/distribution/power_law.h" | ||
| 10 | #include "terraingen/distribution/spliced.h" | ||
| 11 | #include "terraingen/distribution/summed.h" | ||
| 12 | #include "terraingen/geometry/cells.h" | ||
| 13 | #include "terraingen/layers/craters/ages/steady_state.h" | ||
| 14 | #include "terraingen/layers/craters/crater_fields.h" | ||
| 15 | #include "terraingen/layers/craters/degradation/diffusion.h" | ||
| 16 | #include "terraingen/layers/craters/degradation/diffusivities.h" | ||
| 17 | #include "terraingen/layers/craters/generation/spacing.h" | ||
| 18 | #include "terraingen/layers/craters/profiles/martin_parkes_dunstan.h" | ||
| 19 | #include "terraingen/layers/craters/shaping/morphometry.h" | ||
| 20 | #include "terraingen/layers/source_resolved.h" | ||
| 21 | #include "terraingen/random/stream.h" | ||
| 22 | #include "terraingen/raster/grid.h" | ||
| 23 | #include "util/numerics.h" | ||
| 24 | |||
| 25 | #include <algorithm> | ||
| 26 | #include <cmath> | ||
| 27 | #include <memory> | ||
| 28 | #include <optional> | ||
| 29 | #include <stdexcept> | ||
| 30 | #include <utility> | ||
| 31 | #include <vector> | ||
| 32 | |||
| 33 | namespace terraingen { | ||
| 34 | |||
| 35 | namespace { | ||
| 36 | |||
| 37 | /// The largest primary (m) searched for the smallest one throwing secondaries a map measures, | ||
| 38 | /// about where Singer et al.'s largest secondary stops growing with the primary. | ||
| 39 | constexpr double kLargestThrower = 5e5; | ||
| 40 | |||
| 41 | /// Sets the seed of `options` and the seeds of its apply options to `ReseedWord(seed, 0)` to | ||
| 42 | /// `ReseedWord(seed, 6)`. | ||
| 43 | 50 | void ReseedCraterOptions(CraterLayerOptions& options, std::uint64_t seed) { | |
| 44 | 50 | options.seed = ReseedWord(seed, 0); | |
| 45 | 50 | CraterApplyOptions& apply = options.apply; | |
| 46 | 50 | apply.irregularity.seed = ReseedWord(seed, 1); | |
| 47 | 50 | apply.noise.seed = ReseedWord(seed, 2); | |
| 48 | 50 | apply.texture.seed = ReseedWord(seed, 3); | |
| 49 | 50 | apply.slope.seed = ReseedWord(seed, 4); | |
| 50 | 50 | apply.terraces.seed = ReseedWord(seed, 5); | |
| 51 | 50 | apply.peaks.seed = ReseedWord(seed, 6); | |
| 52 | 50 | } | |
| 53 | |||
| 54 | } // namespace | ||
| 55 | |||
| 56 | 986 | CraterLayer::CraterLayer(CraterModels models, CraterLayerOptions options, TerrainBase base) | |
| 57 | 986 | : m_models(std::move(models)), m_options(std::move(options)), | |
| 58 | 986 | m_given(std::make_shared<const CraterLayerOptions>(m_options)), | |
| 59 | 1972 | m_surface(std::move(base.surface)), m_source(std::move(base.source)) { | |
| 60 | 986 | if (!m_models.degradation) { | |
| 61 | 2 | throw std::invalid_argument("A crater layer needs a degradation model"); | |
| 62 | } | ||
| 63 | 984 | if (!m_models.ages) { | |
| 64 | 6 | m_models.ages = m_models.degradation->AgeModel(); | |
| 65 | } | ||
| 66 | 984 | if (m_options.generateRandom && (!m_models.density || !m_models.ages)) { | |
| 67 | 2 | throw std::invalid_argument("A crater layer generating craters needs a density and ages"); | |
| 68 | } | ||
| 69 | 982 | if (m_options.densityMap && !m_models.density) { | |
| 70 | ✗ | throw std::invalid_argument("A crater density map needs a density"); | |
| 71 | } | ||
| 72 | 984 | m_models.profile = MatchedProfile(std::move(m_models.profile), *m_models.degradation); | |
| 73 | 980 | ValidateCraterSpacing(m_options.generation.spacing); | |
| 74 | 979 | ValidateCraterApplyOptions(m_options.apply); | |
| 75 | 978 | m_options.apply = SeededCraterApply(std::move(m_options.apply), m_options.seed); | |
| 76 | 978 | FollowSource(); | |
| 77 | 976 | m_options.generation.marginRadii = CraterReachRadii(*m_models.profile, m_options.apply) * | |
| 78 | 976 | MaxOutlineScale(m_options.apply.irregularity); | |
| 79 | 976 | const CraterList& manual = m_options.generation.manual; | |
| 80 | 976 | double largestReplacing = 0.0; | |
| 81 | 1745 | for (std::size_t n = 0; n < manual.Size(); ++n) { | |
| 82 | 769 | if (manual.Replace()[n] != 0) { | |
| 83 | 51 | largestReplacing = std::fmax(largestReplacing, manual.Diameters()[n]); | |
| 84 | } | ||
| 85 | } | ||
| 86 | 976 | m_replacementMargin = ReplacementMargin(m_options.apply, *m_models.profile, largestReplacing); | |
| 87 | 976 | m_options.generation.surface = m_surface; | |
| 88 | 976 | m_options.apply.surface = m_surface; | |
| 89 | 976 | m_cells = MakeCells(m_surface); | |
| 90 | 976 | if (m_options.cacheCraters > 0) { | |
| 91 | 975 | m_cache = std::make_shared<CraterCellCache>(m_options.cacheCraters); | |
| 92 | } | ||
| 93 | 985 | for (const SecondaryCraterOptions& secondaries : m_options.secondaries) { | |
| 94 | 9 | ValidateSecondaryCraterOptions(secondaries); | |
| 95 | } | ||
| 96 | 976 | m_candidates = m_models.density; | |
| 97 | 976 | if (m_options.densityMap) { | |
| 98 | 9 | FollowDensityMap(); | |
| 99 | } | ||
| 100 | 975 | SetUpBandCounts(); | |
| 101 | 1023 | } | |
| 102 | |||
| 103 | 975 | void CraterLayer::SetUpBandCounts() { | |
| 104 | 975 | const CraterGenerationOptions& generation = m_options.generation; | |
| 105 | 975 | if (!m_options.generateRandom || !m_candidates) { | |
| 106 | return; | ||
| 107 | } | ||
| 108 | 473 | const double maxDiameter = ResolveMaxDiameter(generation.maxDiameter, *m_candidates); | |
| 109 | 473 | if (std::isfinite(maxDiameter) && maxDiameter > generation.minDiameter && | |
| 110 | generation.minDiameter > 0.0) { | ||
| 111 | 473 | for (const CraterBand& band : | |
| 112 | 2343 | CraterBands(generation.minDiameter, maxDiameter, generation.cellSizeFactor)) { | |
| 113 | 1870 | m_bandCounts.push_back( | |
| 114 | 1870 | {band.low, band.high, m_candidates->ExpectedCount(1.0, band.low, band.high)}); | |
| 115 | 473 | } | |
| 116 | } | ||
| 117 | } | ||
| 118 | |||
| 119 | 25 | LayerPtr CraterLayer::Reseeded(std::uint64_t seed) const { | |
| 120 | 25 | auto layer = std::make_shared<CraterLayer>(*this); | |
| 121 | 25 | ReseedCraterOptions(layer->m_options, seed); | |
| 122 | 25 | auto given = std::make_shared<CraterLayerOptions>(*m_given); | |
| 123 | 25 | ReseedCraterOptions(*given, seed); | |
| 124 | 25 | layer->m_given = std::move(given); | |
| 125 | 25 | if (m_cache) { | |
| 126 | 25 | layer->m_cache = std::make_shared<CraterCellCache>(m_options.cacheCraters); | |
| 127 | } | ||
| 128 | 25 | return layer; | |
| 129 | 25 | } | |
| 130 | |||
| 131 | 10 | LayerPtr CraterLayer::Rebased(const TerrainBase& base) const { | |
| 132 | 10 | return std::make_shared<CraterLayer>(m_models, *m_given, base); | |
| 133 | } | ||
| 134 | |||
| 135 | 134101 | void CraterLayer::CountBands(CraterGenerationOptions& generation) const { | |
| 136 | 134101 | if (m_bandCounts.empty()) { | |
| 137 | return; | ||
| 138 | } | ||
| 139 | 134109 | generation.bandCount = [counts = &m_bandCounts, | |
| 140 | 134101 | density = m_candidates.get()](const CraterBand& band) { | |
| 141 | 1031077 | for (const BandCount& entry : *counts) { | |
| 142 | 1031077 | if (entry.low == band.low && entry.high == band.high) { | |
| 143 | 454928 | return entry.count; | |
| 144 | } | ||
| 145 | } | ||
| 146 | ✗ | return density->ExpectedCount(1.0, band.low, band.high); | |
| 147 | 134101 | }; | |
| 148 | } | ||
| 149 | |||
| 150 | 979 | void ValidateInheritedCraters(const InheritedCraters& inherited) { | |
| 151 | 979 | CheckRanges(inherited); | |
| 152 | 977 | if (inherited.minSourcePixels && inherited.maxSourcePixels && | |
| 153 | 2 | !(*inherited.maxSourcePixels > *inherited.minSourcePixels)) { | |
| 154 | 1 | throw std::invalid_argument( | |
| 155 | 1 | "Inherited craters' max_source_px must be above their min_source_px"); | |
| 156 | } | ||
| 157 | 976 | } | |
| 158 | |||
| 159 | 978 | void CraterLayer::FollowSource() { | |
| 160 | 978 | ValidateSourceResolvesPixels(m_options.sourceResolvesPixels); | |
| 161 | 978 | if (auto limit = LayerResolvedLimit(m_source, m_options.sourceResolvesPixels, m_surface)) { | |
| 162 | 44 | std::shared_ptr<const SurfaceField>& completeness = m_options.generation.completeness; | |
| 163 | 96 | completeness = completeness ? std::make_shared<const MinimumField>(completeness, limit) | |
| 164 | 44 | : std::move(limit); | |
| 165 | } | ||
| 166 | 978 | ValidateInheritedCraters(m_options.inherited); | |
| 167 | 976 | const InheritedCraters& inherited = m_options.inherited; | |
| 168 | 976 | if (inherited.craters.Empty()) { | |
| 169 | 966 | return; | |
| 170 | } | ||
| 171 | 10 | const auto from = LayerResolvedLimit(m_source, | |
| 172 | 10 | inherited.minSourcePixels ? inherited.minSourcePixels | |
| 173 | : m_options.sourceResolvesPixels, | ||
| 174 | 10 | m_surface); | |
| 175 | 10 | const auto upTo = LayerResolvedLimit(m_source, inherited.maxSourcePixels, m_surface); | |
| 176 | ✗ | const CraterList stamped = FilterCraters(inherited.craters, [&](std::size_t, const Crater& c) { | |
| 177 | 228 | return (!from || InSource(from.get(), c.diameter, c.x, c.y)) && | |
| 178 | 49 | !InSource(upTo.get(), c.diameter, c.x, c.y); | |
| 179 | 10 | }); | |
| 180 | 57 | for (std::size_t n = 0; n < stamped.Size(); ++n) { | |
| 181 | 47 | Crater crater = stamped.At(n); | |
| 182 | 47 | if (!TakesRimHeight(*m_models.profile, crater.diameter)) { | |
| 183 | 45 | crater.rimHeight.reset(); | |
| 184 | } | ||
| 185 | 47 | m_options.generation.manual.Append(crater.Replace()); | |
| 186 | } | ||
| 187 | 10 | if (from && inherited.minSourcePixels) { | |
| 188 | 2 | std::shared_ptr<const SurfaceField>& completeness = m_options.generation.completeness; | |
| 189 | 2 | completeness = | |
| 190 | 8 | completeness ? std::make_shared<const MinimumField>(completeness, from) : from; | |
| 191 | } | ||
| 192 | 21 | } | |
| 193 | |||
| 194 | 82 | CraterModels DefaultCraterModels() { | |
| 195 | 82 | const EquilibriumSurface surface{ | |
| 196 | 246 | std::make_shared<SplicedSfd>(ExtendedNeukumProductionFunction()), | |
| 197 | 164 | std::make_shared<PowerLawSfd>(HartmannEquilibrium()), 3.5, NeukumLunarChronology}; | |
| 198 | 82 | const auto ages = surface.Ages(); | |
| 199 | 82 | const auto profile = | |
| 200 | 82 | std::make_shared<DiffusedProfile>(std::make_shared<MartinParkesDunstanProfile>()); | |
| 201 | 82 | return {surface.Density(), ages, | |
| 202 | 328 | MatchedDiffusionDegradation(profile, LunarFreshCraterMorphometry, ages), profile}; | |
| 203 | 492 | } | |
| 204 | |||
| 205 | 49 | std::shared_ptr<CraterLayer> CraterLayer::Manual(CraterList craters, CraterModels models, | |
| 206 | CraterApplyOptions apply, TerrainBase base) { | ||
| 207 | 49 | CraterLayerOptions options; | |
| 208 | 49 | options.generateRandom = false; | |
| 209 | 49 | options.generation.manual = std::move(craters); | |
| 210 | 49 | options.apply = std::move(apply); | |
| 211 | 97 | return std::make_shared<CraterLayer>(std::move(models), std::move(options), std::move(base)); | |
| 212 | 49 | } | |
| 213 | |||
| 214 | 9 | void CraterLayer::FollowDensityMap() { | |
| 215 | 9 | m_scale = std::make_shared<const DensityScale>(*m_options.densityMap, *m_models.density); | |
| 216 | 9 | if (m_scale->Max() > 1.0) { | |
| 217 | 24 | m_candidates = std::make_shared<SummedSfd>( | |
| 218 | 18 | std::vector<WeightedSfd>{{m_scale->Max(), m_models.density}}); | |
| 219 | } | ||
| 220 | 72 | m_options.generation.keepShare = [scale = m_scale](const Crater& crater) { | |
| 221 | 13478 | return scale->At(crater.x, crater.y) / scale->Max(); | |
| 222 | 9 | }; | |
| 223 | 9 | const DensityMap& map = *m_options.densityMap; | |
| 224 | 9 | if (!map.total || map.measure == DensityMeasure::Scale) { | |
| 225 | return; | ||
| 226 | } | ||
| 227 | 5 | for (const SecondaryCraterOptions& secondaries : m_options.secondaries) { | |
| 228 | 2 | m_throwFrom = std::fmin(m_throwFrom, SmallestThrower(map, secondaries)); | |
| 229 | } | ||
| 230 | 3 | if (std::isfinite(m_throwFrom) && m_options.generation.maxCraters) { | |
| 231 | 1 | throw std::invalid_argument("Taking secondaries out of a density map needs every crater, " | |
| 232 | 1 | "not the maxCraters largest"); | |
| 233 | } | ||
| 234 | 2 | m_options.generation.spacing.outrankFrom = m_throwFrom; | |
| 235 | 12 | } | |
| 236 | |||
| 237 | 2 | double CraterLayer::SmallestThrower(const DensityMap& map, | |
| 238 | const SecondaryCraterOptions& secondaries) { | ||
| 239 | 2 | const double smallest = std::fmax(map.minDiameter, secondaries.minDiameter); | |
| 240 | 202 | const auto throws = [&](double diameter) { | |
| 241 | 200 | return LargestSecondary(diameter, secondaries) > smallest; | |
| 242 | 2 | }; | |
| 243 | 2 | if (!throws(kLargestThrower)) { | |
| 244 | return std::numeric_limits<double>::infinity(); | ||
| 245 | } | ||
| 246 | 4 | return std::fmax(BisectLog(1e-3, kLargestThrower, 100, 0.0, throws), | |
| 247 | 2 | secondaries.selection.minDiameter); | |
| 248 | } | ||
| 249 | |||
| 250 | 3 | CraterList CraterLayer::Throwers(const Bounds2d& region) const { | |
| 251 | 3 | CraterGenerationOptions large = m_options.generation; | |
| 252 | 3 | large.minDiameter = std::fmax(large.minDiameter, m_throwFrom); | |
| 253 | 3 | large.minResolvedDiameter = 0.0; | |
| 254 | 3 | CountBands(large); | |
| 255 | 3 | double reach = 0.0; | |
| 256 | 6 | for (const SecondaryCraterOptions& secondaries : m_options.secondaries) { | |
| 257 | 3 | reach = std::fmax(reach, SecondaryOuterRange(MaxFeatureDiameter(), secondaries)); | |
| 258 | } | ||
| 259 | 3 | const Bounds2d around = m_surface.Expand(region, reach); | |
| 260 | 3 | if (large.minDiameter < ResolveMaxDiameter(large.maxDiameter, *m_candidates)) { | |
| 261 | ✗ | return GenerateCachedCraters(m_cache.get(), *m_cells, around, *m_candidates, *m_models.ages, | |
| 262 | ✗ | m_options.seed, large); | |
| 263 | } | ||
| 264 | 3 | return ManualCratersNear(around, 0.0); | |
| 265 | 3 | } | |
| 266 | |||
| 267 | 28684 | CraterList CraterLayer::ManualCratersNear(const Bounds2d& region, double marginRadii) const { | |
| 268 | 28684 | CraterList craters; | |
| 269 | 28688 | AppendManualCraters(m_options.generation.manual, craters, [&](const Crater& crater) { | |
| 270 | 76879 | const Bounds2d near = marginRadii > 0.0 | |
| 271 | 76879 | ? m_surface.Expand(region, 0.5 * marginRadii * crater.diameter) | |
| 272 | 3 | : region; | |
| 273 | 76879 | return m_surface.Contains(near, {crater.x, crater.y}); | |
| 274 | }); | ||
| 275 | 28680 | return craters; | |
| 276 | 4 | } | |
| 277 | |||
| 278 | 3 | CraterKeepShare CraterLayer::KeepShare(const Bounds2d& region) const { | |
| 279 | 2 | struct Thrower { | |
| 280 | Vec2d center; | ||
| 281 | SecondaryDensity density; | ||
| 282 | }; | ||
| 283 | 3 | auto thrown = std::make_shared<std::vector<Thrower>>(); | |
| 284 | 3 | const CraterList throwers = Throwers(region); | |
| 285 | 5 | for (std::size_t n = 0; n < throwers.Size(); ++n) { | |
| 286 | 2 | const Crater crater = throwers.At(n); | |
| 287 | 4 | for (const SecondaryCraterOptions& secondaries : m_options.secondaries) { | |
| 288 | 2 | SecondaryDensity density(crater, secondaries); | |
| 289 | 2 | if (density.Reach() > 0.0) { | |
| 290 | 4 | thrown->push_back({{crater.x, crater.y}, std::move(density)}); | |
| 291 | } | ||
| 292 | 2 | } | |
| 293 | } | ||
| 294 | 3 | const DensityMap& map = *m_options.densityMap; | |
| 295 | 3 | const bool cover = map.measure == DensityMeasure::ArealFraction; | |
| 296 | 9 | return [scale = m_scale, map, cover, thrown, from = m_throwFrom, | |
| 297 | 3 | surface = m_surface](const Crater& crater) { | |
| 298 | 513850 | const double share = scale->At(crater.x, crater.y) / scale->Max(); | |
| 299 | 513850 | if (crater.diameter >= from) { | |
| 300 | return share; | ||
| 301 | } | ||
| 302 | 513850 | double value = MapValueAt(map, crater.x, crater.y); | |
| 303 | 513850 | if (std::isnan(value)) { | |
| 304 | return share; | ||
| 305 | } | ||
| 306 | 1023812 | for (const Thrower& thrower : *thrown) { | |
| 307 | 509962 | const Vec2d offset = surface.Offset(thrower.center, {crater.x, crater.y}); | |
| 308 | 509962 | if (std::hypot(offset.x, offset.y) < thrower.density.Reach()) { | |
| 309 | 559320 | value -= cover ? thrower.density.CoverAt(offset, map.minDiameter, map.maxDiameter) | |
| 310 | 279660 | : thrower.density.At(offset, map.minDiameter, map.maxDiameter); | |
| 311 | } | ||
| 312 | } | ||
| 313 | 513850 | return scale->Scale(value) / scale->Max(); | |
| 314 | 3 | }; | |
| 315 | 8 | } | |
| 316 | |||
| 317 | 162996 | CraterList CraterLayer::Craters(const Bounds2d& region, double spacing, double minDiameter, | |
| 318 | double maxDiameter, unsigned threads) const { | ||
| 319 | 162996 | CraterGenerationOptions generation = m_options.generation; | |
| 320 | 162832 | generation.threads = threads; | |
| 321 | 162832 | if (m_options.generateRandom) { | |
| 322 | 134151 | if (spacing > 0.0) { | |
| 323 | 134093 | generation.minResolvedDiameter = m_options.apply.fade.startSamples * spacing; | |
| 324 | } | ||
| 325 | 134151 | generation.minResolvedDiameter = std::fmax(generation.minResolvedDiameter, minDiameter); | |
| 326 | 134151 | generation.maxBandDiameter = std::fmin(generation.maxBandDiameter, maxDiameter); | |
| 327 | 134151 | if (std::isfinite(m_throwFrom)) { | |
| 328 | 3 | generation.keepShare = KeepShare(region); | |
| 329 | } | ||
| 330 | 134151 | CountBands(generation); | |
| 331 | 268235 | return GenerateCachedCraters(m_cache.get(), *m_cells, region, *m_candidates, *m_models.ages, | |
| 332 | 134205 | m_options.seed, std::move(generation)); | |
| 333 | } | ||
| 334 | 28681 | return ManualCratersNear(region, generation.marginRadii); | |
| 335 | 163054 | } | |
| 336 | |||
| 337 | 159092 | void CraterLayer::ApplySamples(SampleBlock& samples, const LayerContext& context) const { | |
| 338 | 159092 | const Raster<float>* grid = samples.Grid(); | |
| 339 | 159092 | if (grid == nullptr && m_options.apply.datum != CraterDatum::None) { | |
| 340 | 5787 | RequireGround(context.ground, "Point queries of craters with a datum"); | |
| 341 | } | ||
| 342 | 158805 | if (grid == nullptr && m_replacementMargin > 0.0) { | |
| 343 | 5 | RequireGround(context.ground, "Point queries of replacing craters"); | |
| 344 | } | ||
| 345 | 159090 | if (grid == nullptr && m_options.generation.maxCraters) { | |
| 346 | 1 | throw std::invalid_argument( | |
| 347 | 1 | "Point queries cannot use maxCraters, which ranks craters over a whole grid"); | |
| 348 | } | ||
| 349 | 159089 | const double spacing = samples.ResolvedSpacing(context.spacing, m_surface); | |
| 350 | 158956 | const Bounds2d bounds = samples.Bounds(); | |
| 351 | 159297 | const CraterSampling sampling = SamplingFrom(context, spacing, this); | |
| 352 | 159017 | if (grid == nullptr && m_options.apply.datum != CraterDatum::None && context.cache != nullptr && | |
| 353 | 159017 | ApplyCratersOnCachedDatums(samples, Craters(bounds, spacing), m_models.Shape(), | |
| 354 | 4130 | m_options.apply, sampling)) { | |
| 355 | 4016 | return; | |
| 356 | } | ||
| 357 | 155001 | const CraterList craters = | |
| 358 | 155001 | Craters(m_surface.Expand(bounds, GroundReach(spacing)), spacing, 0.0, | |
| 359 | 310145 | std::numeric_limits<double>::infinity(), grid != nullptr ? context.threads : 1); | |
| 360 | 154735 | ApplyCraters(samples, craters, m_models.Shape(), m_options.apply, sampling); | |
| 361 | 159260 | } | |
| 362 | |||
| 363 | 155144 | double CraterLayer::GroundReach(double /*spacing*/) const { | |
| 364 | 155138 | return std::fmax(DatumMargin(m_options.apply, *m_models.profile, MaxFeatureDiameter()), | |
| 365 | 155144 | m_replacementMargin); | |
| 366 | } | ||
| 367 | |||
| 368 | 115 | CraterFeatures CraterLayer::CratersOver(const RasterGrid& grid, double spacing) const { | |
| 369 | 230 | return DescribeCraters(Craters(grid.Bounds(), ListedSpacing(grid, spacing, m_surface)), | |
| 370 | 345 | m_models.Shape()); | |
| 371 | } | ||
| 372 | |||
| 373 | 158872 | double CraterLayer::MaxFeatureDiameter() const { | |
| 374 | 158872 | const CraterGenerationOptions& generation = m_options.generation; | |
| 375 | 158872 | double largest = m_options.generateRandom | |
| 376 | 158872 | ? ResolveMaxDiameter(generation.maxDiameter, *m_models.density) | |
| 377 | : 0.0; | ||
| 378 | 236168 | for (std::size_t n = 0; n < generation.manual.Size(); ++n) { | |
| 379 | 77071 | largest = std::fmax(largest, generation.manual.At(n).diameter); | |
| 380 | } | ||
| 381 | 159097 | return largest; | |
| 382 | } | ||
| 383 | |||
| 384 | } // namespace terraingen | ||
| 385 |