src/layers/boulders/boulder_clusters.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | /// @file | ||
| 4 | /// @brief Internal: the boulder cluster fields and the lattice means that normalize them. | ||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "terraingen/layers/boulders/boulder_options.h" | ||
| 8 | #include "terraingen/random/streams.h" | ||
| 9 | |||
| 10 | #include <cstdint> | ||
| 11 | |||
| 12 | namespace terraingen { | ||
| 13 | |||
| 14 | /// The distance in radii beyond which a `Thomas` cluster adds nothing. | ||
| 15 | inline constexpr double kThomasReachRadii = 4.0; | ||
| 16 | |||
| 17 | /// The mean of `f(x, y)` over a square `cells` units across from the origin, sampled at the | ||
| 18 | /// centers of a 256 x 256 lattice. | ||
| 19 | 18 | template <typename Function> double LatticeMean(double cells, const Function& f) { | |
| 20 | 18 | constexpr int kSamples = 256; | |
| 21 | 18 | double sum = 0.0; | |
| 22 | 4626 | for (int j = 0; j < kSamples; ++j) { | |
| 23 | 1184256 | for (int i = 0; i < kSamples; ++i) { | |
| 24 | 1179648 | sum += f((i + 0.5) * cells / kSamples, (j + 0.5) * cells / kSamples); | |
| 25 | } | ||
| 26 | } | ||
| 27 | 18 | return sum / (kSamples * kSamples); | |
| 28 | } | ||
| 29 | |||
| 30 | /// A cluster's weight `distance` meters from its center: a Gaussian of the cluster's radius. | ||
| 31 | double ClusterBump(double distance, const BoulderClusters& clusters); | ||
| 32 | |||
| 33 | /// The mean of `ClusterBump` of the nearest cluster center over the plane, which the cluster field | ||
| 34 | /// is divided by to keep the mean density. | ||
| 35 | double MeanClusterBump(const BoulderClusters& clusters); | ||
| 36 | |||
| 37 | /// The mean over the surface of the `Thomas` field, the sum of `ClusterBump` within | ||
| 38 | /// `kThomasReachRadii` of every center, which it is divided by to keep the mean density. | ||
| 39 | /// @param body Whether centers are scattered through space around a body, `spacing`^2 per square | ||
| 40 | /// meter of a plane through them, rather than over a plane. | ||
| 41 | double MeanThomasField(const BoulderClusters& clusters, bool body = false); | ||
| 42 | |||
| 43 | /// The largest a cluster field multiplies the scattered boulder density by; 1 without clusters. | ||
| 44 | /// For `Thomas` it is where as many centers crowd within 3 radii as a one in a million chance | ||
| 45 | /// allows, and the rare points above it are capped to it. | ||
| 46 | double MaxClusterAbundance(const BoulderClusters& clusters); | ||
| 47 | |||
| 48 | } // namespace terraingen | ||
| 49 |