| Line |
Branch |
Exec |
Source |
| 1 |
|
|
// SPDX-License-Identifier: BSD-3-Clause |
| 2 |
|
|
|
| 3 |
|
|
/// @file |
| 4 |
|
|
/// @brief Bisection for where a monotone condition turns true, and Simpson's rule in log x. |
| 5 |
|
|
#pragma once |
| 6 |
|
|
|
| 7 |
|
|
#include <cmath> |
| 8 |
|
|
#include <initializer_list> |
| 9 |
|
|
#include <limits> |
| 10 |
|
|
|
| 11 |
|
|
namespace terraingen { |
| 12 |
|
|
|
| 13 |
|
|
/// The ends of an interval. |
| 14 |
|
|
struct BisectionInterval { |
| 15 |
|
|
double low = 0.0; |
| 16 |
|
|
double high = 0.0; |
| 17 |
|
|
}; |
| 18 |
|
|
|
| 19 |
|
|
/// Halves [`low`, `high`] at most `steps` times around where `above` turns true, keeping `above` |
| 20 |
|
|
/// false at the low end and true at the high end, until the interval is no wider than |
| 21 |
|
|
/// `tolerance`. |
| 22 |
|
|
template <typename Above> |
| 23 |
|
1684 |
BisectionInterval Bisect(double low, double high, int steps, double tolerance, const Above& above) { |
| 24 |
26/40
terraingen::BisectionInterval terraingen::Bisect<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#6}>(double, double, int, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#6} const&):
✓ Branch 0 taken 16575 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16250 times.
✓ Branch 3 taken 325 times.
terraingen::BisectionInterval terraingen::Bisect<Bisect_NarrowsAroundWhereTheConditionTurnsTrue_Test::TestBody()::{lambda(double)#1}>(double, double, int, double, Bisect_NarrowsAroundWhereTheConditionTurnsTrue_Test::TestBody()::{lambda(double)#1} const&):
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
✓ Branch 3 taken 1 time.
terraingen::BisectionInterval terraingen::Bisect<Bisect_NarrowsAroundWhereTheConditionTurnsTrue_Test::TestBody()::{lambda(double)#2}>(double, double, int, double, Bisect_NarrowsAroundWhereTheConditionTurnsTrue_Test::TestBody()::{lambda(double)#2} const&):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
terraingen::BisectionInterval terraingen::Bisect<Bisect_NarrowsAroundWhereTheConditionTurnsTrue_Test::TestBody()::{lambda(double)#3}>(double, double, int, double, Bisect_NarrowsAroundWhereTheConditionTurnsTrue_Test::TestBody()::{lambda(double)#3} const&):
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 time.
terraingen::BisectionInterval terraingen::Bisect<terraingen::AppendKernelTerraces(terraingen::PreparedCrater const&, terraingen::CraterTerraces const&, terraingen::CraterProfile const&, terraingen::CraterRecord&, std::vector<float, std::allocator<float> >&)::{lambda(double)#3}>(double, double, int, double, terraingen::AppendKernelTerraces(terraingen::PreparedCrater const&, terraingen::CraterTerraces const&, terraingen::CraterProfile const&, terraingen::CraterRecord&, std::vector<float, std::allocator<float> >&)::{lambda(double)#3} const&):
✓ Branch 0 taken 2490 times.
✓ Branch 1 taken 83 times.
✓ Branch 2 taken 2490 times.
✗ Branch 3 not taken.
terraingen::BisectionInterval terraingen::Bisect<terraingen::BisectLog<BisectLog_BisectsInLogSpace_Test::TestBody()::{lambda(double)#1}>(double, double, int, double, BisectLog_BisectsInLogSpace_Test::TestBody()::{lambda(double)#1} const&)::{lambda(double)#1}>(double, double, int, double, terraingen::BisectLog<BisectLog_BisectsInLogSpace_Test::TestBody()::{lambda(double)#1}>(double, double, int, double, BisectLog_BisectsInLogSpace_Test::TestBody()::{lambda(double)#1} const&)::{lambda(double)#1} const&):
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
✓ Branch 3 taken 1 time.
terraingen::BisectionInterval terraingen::Bisect<terraingen::BisectLog<BisectLog_BisectsInLogSpace_Test::TestBody()::{lambda(double)#2}>(double, double, int, double, BisectLog_BisectsInLogSpace_Test::TestBody()::{lambda(double)#2} const&)::{lambda(double)#1}>(double, double, int, double, terraingen::BisectLog<BisectLog_BisectsInLogSpace_Test::TestBody()::{lambda(double)#2}>(double, double, int, double, BisectLog_BisectsInLogSpace_Test::TestBody()::{lambda(double)#2} const&)::{lambda(double)#1} const&):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
terraingen::BisectionInterval terraingen::Bisect<terraingen::BisectLog<terraingen::CountLimitDiameter(terraingen::SizeFrequencyDistribution const&, double, double, double, double)::{lambda(double)#1}>(double, double, int, double, terraingen::CountLimitDiameter(terraingen::SizeFrequencyDistribution const&, double, double, double, double)::{lambda(double)#1} const&)::{lambda(double)#1}>(double, double, int, double, terraingen::BisectLog<terraingen::CountLimitDiameter(terraingen::SizeFrequencyDistribution const&, double, double, double, double)::{lambda(double)#1}>(double, double, int, double, terraingen::CountLimitDiameter(terraingen::SizeFrequencyDistribution const&, double, double, double, double)::{lambda(double)#1} const&)::{lambda(double)#1} const&):
✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 86 times.
✓ Branch 3 taken 2 times.
terraingen::BisectionInterval terraingen::Bisect<terraingen::BisectLog<terraingen::CraterLayer::SmallestThrower(terraingen::DensityMap const&, terraingen::SecondaryCraterOptions const&)::{lambda(double)#1}>(double, double, int, double, terraingen::CraterLayer::SmallestThrower(terraingen::DensityMap const&, terraingen::SecondaryCraterOptions const&)::{lambda(double)#1} const&)::{lambda(double)#1}>(double, double, int, double, terraingen::BisectLog<terraingen::CraterLayer::SmallestThrower(terraingen::DensityMap const&, terraingen::SecondaryCraterOptions const&)::{lambda(double)#1}>(double, double, int, double, terraingen::CraterLayer::SmallestThrower(terraingen::DensityMap const&, terraingen::SecondaryCraterOptions const&)::{lambda(double)#1} const&)::{lambda(double)#1} const&):
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 200 times.
✗ Branch 3 not taken.
terraingen::BisectionInterval terraingen::Bisect<terraingen::SizeFrequencyDistribution::InvertCumulative(double, double, double) const::{lambda(double)#2}>(double, double, int, double, terraingen::SizeFrequencyDistribution::InvertCumulative(double, double, double) const::{lambda(double)#2} const&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
77729 |
for (int i = 0; i < steps && high - low > tolerance; ++i) { |
| 25 |
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 19 times.
|
76045 |
const double middle = 0.5 * (low + high); |
| 26 |
11/16
terraingen::BisectionInterval terraingen::Bisect<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#6}>(double, double, int, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#6} const&):
✓ Branch 1 taken 6281 times.
✓ Branch 2 taken 9969 times.
terraingen::BisectionInterval terraingen::Bisect<Bisect_NarrowsAroundWhereTheConditionTurnsTrue_Test::TestBody()::{lambda(double)#1}>(double, double, int, double, Bisect_NarrowsAroundWhereTheConditionTurnsTrue_Test::TestBody()::{lambda(double)#1} const&):
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 19 times.
terraingen::BisectionInterval terraingen::Bisect<Bisect_NarrowsAroundWhereTheConditionTurnsTrue_Test::TestBody()::{lambda(double)#2}>(double, double, int, double, Bisect_NarrowsAroundWhereTheConditionTurnsTrue_Test::TestBody()::{lambda(double)#2} const&):
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
terraingen::BisectionInterval terraingen::Bisect<Bisect_NarrowsAroundWhereTheConditionTurnsTrue_Test::TestBody()::{lambda(double)#3}>(double, double, int, double, Bisect_NarrowsAroundWhereTheConditionTurnsTrue_Test::TestBody()::{lambda(double)#3} const&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
terraingen::BisectionInterval terraingen::Bisect<terraingen::AppendKernelTerraces(terraingen::PreparedCrater const&, terraingen::CraterTerraces const&, terraingen::CraterProfile const&, terraingen::CraterRecord&, std::vector<float, std::allocator<float> >&)::{lambda(double)#3}>(double, double, int, double, terraingen::AppendKernelTerraces(terraingen::PreparedCrater const&, terraingen::CraterTerraces const&, terraingen::CraterProfile const&, terraingen::CraterRecord&, std::vector<float, std::allocator<float> >&)::{lambda(double)#3} const&):
✓ Branch 0 taken 1190 times.
✓ Branch 1 taken 1300 times.
terraingen::BisectionInterval terraingen::Bisect<terraingen::BisectLog<terraingen::CountLimitDiameter(terraingen::SizeFrequencyDistribution const&, double, double, double, double)::{lambda(double)#1}>(double, double, int, double, terraingen::CountLimitDiameter(terraingen::SizeFrequencyDistribution const&, double, double, double, double)::{lambda(double)#1} const&)::{lambda(double)#1}>(double, double, int, double, terraingen::BisectLog<terraingen::CountLimitDiameter(terraingen::SizeFrequencyDistribution const&, double, double, double, double)::{lambda(double)#1}>(double, double, int, double, terraingen::CountLimitDiameter(terraingen::SizeFrequencyDistribution const&, double, double, double, double)::{lambda(double)#1} const&)::{lambda(double)#1} const&):
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 46 times.
terraingen::BisectionInterval terraingen::Bisect<terraingen::BisectLog<terraingen::CraterLayer::SmallestThrower(terraingen::DensityMap const&, terraingen::SecondaryCraterOptions const&)::{lambda(double)#1}>(double, double, int, double, terraingen::CraterLayer::SmallestThrower(terraingen::DensityMap const&, terraingen::SecondaryCraterOptions const&)::{lambda(double)#1} const&)::{lambda(double)#1}>(double, double, int, double, terraingen::BisectLog<terraingen::CraterLayer::SmallestThrower(terraingen::DensityMap const&, terraingen::SecondaryCraterOptions const&)::{lambda(double)#1}>(double, double, int, double, terraingen::CraterLayer::SmallestThrower(terraingen::DensityMap const&, terraingen::SecondaryCraterOptions const&)::{lambda(double)#1} const&)::{lambda(double)#1} const&):
✓ Branch 1 taken 148 times.
✓ Branch 2 taken 52 times.
terraingen::BisectionInterval terraingen::Bisect<terraingen::SizeFrequencyDistribution::InvertCumulative(double, double, double) const::{lambda(double)#2}>(double, double, int, double, terraingen::SizeFrequencyDistribution::InvertCumulative(double, double, double) const::{lambda(double)#2} const&):
✗ Branch 1 not taken.
✗ Branch 2 not taken.
|
76021 |
(above(middle) ? high : low) = middle; |
| 27 |
|
|
} |
| 28 |
|
1684 |
return {low, high}; |
| 29 |
|
|
} |
| 30 |
|
|
|
| 31 |
|
|
/// A bracket [`a`, `b`] of a root of a continuous function, narrowed by the Illinois variant of |
| 32 |
|
|
/// regula falsi; `fa` and `fb` are the function's values at the ends, of opposite signs. |
| 33 |
|
|
struct IllinoisBracket { |
| 34 |
|
|
double a = 0.0; |
| 35 |
|
|
double b = 0.0; |
| 36 |
|
|
double fa = 0.0; |
| 37 |
|
|
double fb = 0.0; |
| 38 |
|
|
int side = 0; |
| 39 |
|
|
|
| 40 |
|
|
/// The next estimate of the root: the secant's zero, or the middle where it leaves the bracket. |
| 41 |
|
8244521 |
double Next() const { |
| 42 |
|
8244521 |
const double c = b - fb * (b - a) / (fb - fa); |
| 43 |
4/4
✓ Branch 0 taken 7630130 times.
✓ Branch 1 taken 614391 times.
✓ Branch 2 taken 1822311 times.
✓ Branch 3 taken 5807819 times.
|
8244521 |
return c > a && c < b ? c : 0.5 * (a + b); |
| 44 |
|
|
} |
| 45 |
|
|
|
| 46 |
|
|
/// Moves the end on the side of `c` to it, given its value `fc`, halving the other end's value |
| 47 |
|
|
/// when the same end moved last time. |
| 48 |
|
6806107 |
void Update(double c, double fc) { |
| 49 |
2/2
✓ Branch 0 taken 4251554 times.
✓ Branch 1 taken 2554553 times.
|
6806107 |
if ((fc < 0.0) == (fa < 0.0)) { |
| 50 |
|
4251554 |
a = c; |
| 51 |
|
4251554 |
fa = fc; |
| 52 |
2/2
✓ Branch 0 taken 1742845 times.
✓ Branch 1 taken 2508709 times.
|
4251554 |
fb *= side == -1 ? 0.5 : 1.0; |
| 53 |
|
4251554 |
side = -1; |
| 54 |
|
|
} else { |
| 55 |
|
2554553 |
b = c; |
| 56 |
|
2554553 |
fb = fc; |
| 57 |
2/2
✓ Branch 0 taken 1563890 times.
✓ Branch 1 taken 990663 times.
|
2554553 |
fa *= side == 1 ? 0.5 : 1.0; |
| 58 |
|
2554553 |
side = 1; |
| 59 |
|
|
} |
| 60 |
|
6806107 |
} |
| 61 |
|
|
}; |
| 62 |
|
|
|
| 63 |
|
|
/// `Bisect` of `above(x) = !(value(x) < target)` for a non-decreasing `value`, to the same |
| 64 |
|
|
/// interval with fewer calls of `value`, which Illinois steps bracket near the crossing. |
| 65 |
|
|
/// @param value Callable as `double(double x)`; non-decreasing over [`low`, `high`], or the |
| 66 |
|
|
/// interval may differ from `Bisect`'s. |
| 67 |
|
|
template <typename Value> |
| 68 |
|
375457 |
BisectionInterval BisectRising(double low, double high, int steps, double tolerance, double target, |
| 69 |
|
|
const Value& value) { |
| 70 |
|
375457 |
constexpr int kEstimateSteps = 12; |
| 71 |
|
375457 |
const double margin = 1e-13 * (high - low); |
| 72 |
|
375457 |
IllinoisBracket bracket{low, high, value(low) - target, value(high) - target}; |
| 73 |
|
375122 |
const bool belowKnown = bracket.fa < 0.0; |
| 74 |
|
375122 |
const bool aboveKnown = !(bracket.fb < 0.0); |
| 75 |
|
375122 |
double below = low; |
| 76 |
|
375122 |
double above = high; |
| 77 |
4/6
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7} const&):
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 69 times.
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8} const&):
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
terraingen::BisectionInterval terraingen::BisectRising<terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1}>(double, double, int, double, double, terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1} const&):
✓ Branch 0 taken 374804 times.
✗ Branch 1 not taken.
|
375122 |
if (belowKnown && aboveKnown) { |
| 78 |
|
|
double c = low; |
| 79 |
4/6
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7} const&):
✓ Branch 0 taken 2846 times.
✓ Branch 1 taken 168 times.
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8} const&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
terraingen::BisectionInterval terraingen::BisectRising<terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1}>(double, double, int, double, double, terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1} const&):
✓ Branch 0 taken 2457544 times.
✓ Branch 1 taken 43275 times.
|
2503833 |
for (int i = 0; i < kEstimateSteps; ++i) { |
| 80 |
|
2460390 |
const double previous = c; |
| 81 |
|
2460390 |
c = bracket.Next(); |
| 82 |
|
2455992 |
bracket.Update(c, value(c) - target); |
| 83 |
8/12
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7} const&):
✓ Branch 0 taken 2590 times.
✓ Branch 1 taken 256 times.
✓ Branch 2 taken 2502 times.
✓ Branch 3 taken 88 times.
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8} const&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
terraingen::BisectionInterval terraingen::BisectRising<terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1}>(double, double, int, double, double, terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1} const&):
✓ Branch 0 taken 2082692 times.
✓ Branch 1 taken 374569 times.
✓ Branch 2 taken 1751446 times.
✓ Branch 3 taken 331246 times.
|
2460107 |
if (i > 0 && std::fabs(c - previous) <= margin) { |
| 84 |
|
|
break; |
| 85 |
|
|
} |
| 86 |
|
|
} |
| 87 |
|
374777 |
const double a = bracket.a; |
| 88 |
|
374777 |
const double b = bracket.b; |
| 89 |
|
374777 |
below = a; |
| 90 |
|
374777 |
above = b; |
| 91 |
4/6
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7} const&):
✓ Branch 0 taken 410 times.
✓ Branch 1 taken 143 times.
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8} const&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
terraingen::BisectionInterval terraingen::BisectRising<terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1}>(double, double, int, double, double, terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1} const&):
✓ Branch 0 taken 402548 times.
✓ Branch 1 taken 11368 times.
|
414469 |
for (const double spread : {margin, 64.0 * margin}) { |
| 92 |
4/6
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7} const&):
✓ Branch 0 taken 313 times.
✓ Branch 1 taken 97 times.
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8} const&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
terraingen::BisectionInterval terraingen::BisectRising<terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1}>(double, double, int, double, double, terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1} const&):
✓ Branch 0 taken 127661 times.
✓ Branch 1 taken 274887 times.
|
402958 |
if (b - a <= 2.0 * spread) { |
| 93 |
|
|
break; |
| 94 |
|
|
} |
| 95 |
8/12
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7} const&):
✓ Branch 0 taken 89 times.
✓ Branch 1 taken 224 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 84 times.
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8} const&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
terraingen::BisectionInterval terraingen::BisectRising<terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1}>(double, double, int, double, double, terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1} const&):
✓ Branch 0 taken 95359 times.
✓ Branch 1 taken 32302 times.
✓ Branch 3 taken 78467 times.
✓ Branch 4 taken 16877 times.
|
127974 |
if (c - spread > a && value(c - spread) < target) { |
| 96 |
|
|
below = c - spread; |
| 97 |
|
|
} |
| 98 |
8/12
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7} const&):
✓ Branch 0 taken 224 times.
✓ Branch 1 taken 89 times.
✓ Branch 3 taken 218 times.
✓ Branch 4 taken 6 times.
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8} const&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
terraingen::BisectionInterval terraingen::BisectRising<terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1}>(double, double, int, double, double, terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1} const&):
✓ Branch 0 taken 32291 times.
✓ Branch 1 taken 95355 times.
✓ Branch 3 taken 29899 times.
✓ Branch 4 taken 2393 times.
|
127959 |
if (c + spread < b && !(value(c + spread) < target)) { |
| 99 |
|
|
above = c + spread; |
| 100 |
|
|
} |
| 101 |
4/6
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7} const&):
✓ Branch 0 taken 297 times.
✓ Branch 1 taken 16 times.
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8} const&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
terraingen::BisectionInterval terraingen::BisectRising<terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1}>(double, double, int, double, double, terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1} const&):
✓ Branch 0 taken 39395 times.
✓ Branch 1 taken 88252 times.
|
127960 |
if (above - below <= 4.0 * spread) { |
| 102 |
|
|
break; |
| 103 |
|
|
} |
| 104 |
|
|
} |
| 105 |
|
|
} |
| 106 |
4/6
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7} const&):
✓ Branch 0 taken 325 times.
✗ Branch 1 not taken.
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8} const&):
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
terraingen::BisectionInterval terraingen::BisectRising<terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1}>(double, double, int, double, double, terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1} const&):
✓ Branch 0 taken 374387 times.
✓ Branch 1 taken 112 times.
|
374825 |
const double aboveFrom = aboveKnown ? above + margin : std::numeric_limits<double>::infinity(); |
| 107 |
5/6
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7} const&):
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 69 times.
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8} const&):
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
terraingen::BisectionInterval terraingen::BisectRising<terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1}>(double, double, int, double, double, terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1} const&):
✓ Branch 0 taken 374483 times.
✓ Branch 1 taken 16 times.
|
374825 |
const double belowTo = belowKnown ? below - margin : -std::numeric_limits<double>::infinity(); |
| 108 |
9/12
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7} const&):
✓ Branch 0 taken 16575 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16250 times.
✓ Branch 3 taken 325 times.
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8} const&):
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 50 times.
✓ Branch 3 taken 1 time.
terraingen::BisectionInterval terraingen::BisectRising<terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1}>(double, double, int, double, double, terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1} const&):
✓ Branch 0 taken 18805284 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18431186 times.
✓ Branch 3 taken 374098 times.
|
18821910 |
for (int i = 0; i < steps && high - low > tolerance; ++i) { |
| 109 |
|
18447486 |
const double middle = 0.5 * (low + high); |
| 110 |
|
18447486 |
bool isAbove = middle >= aboveFrom; |
| 111 |
10/12
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7} const&):
✓ Branch 0 taken 12287 times.
✓ Branch 1 taken 3963 times.
✓ Branch 2 taken 9108 times.
✓ Branch 3 taken 3179 times.
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8} const&):
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 50 times.
✗ Branch 3 not taken.
terraingen::BisectionInterval terraingen::BisectRising<terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1}>(double, double, int, double, double, terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1} const&):
✓ Branch 0 taken 11033205 times.
✓ Branch 1 taken 7397981 times.
✓ Branch 2 taken 3525334 times.
✓ Branch 3 taken 7507871 times.
|
18447486 |
if (!isAbove && !(middle <= belowTo)) { |
| 112 |
|
3534091 |
isAbove = !(value(middle) < target); |
| 113 |
|
|
} |
| 114 |
5/6
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#7} const&):
✓ Branch 0 taken 6281 times.
✓ Branch 1 taken 9969 times.
terraingen::BisectionInterval terraingen::BisectRising<BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8}>(double, double, int, double, double, BisectRising_GivesBisectsIntervalToTheBitWithFewerCallsWhenSmooth_Test::TestBody()::{lambda(double)#8} const&):
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
terraingen::BisectionInterval terraingen::BisectRising<terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1}>(double, double, int, double, double, terraingen::(anonymous namespace)::SampleFormationAge(terraingen::RandomStream&, std::function<double (double)> const&, double)::{lambda(double)#1} const&):
✓ Branch 0 taken 9305338 times.
✓ Branch 1 taken 9125447 times.
|
18447085 |
high = isAbove ? middle : high; |
| 115 |
|
18447085 |
low = isAbove ? low : middle; |
| 116 |
|
|
} |
| 117 |
|
374424 |
return {low, high}; |
| 118 |
|
|
} |
| 119 |
|
|
|
| 120 |
|
|
/// `Bisect` in ln x between positive `low` and `high`, `above` taking x; the high end found. |
| 121 |
|
|
/// @param tolerance Width in ln x. |
| 122 |
|
|
template <typename Above> |
| 123 |
|
6 |
double BisectLog(double low, double high, int steps, double tolerance, const Above& above) { |
| 124 |
|
52 |
return std::exp(Bisect(std::log(low), std::log(high), steps, tolerance, [&](double middle) { |
| 125 |
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 24 times.
|
332 |
return above(std::exp(middle)); |
| 126 |
|
6 |
}).high); |
| 127 |
|
|
} |
| 128 |
|
|
|
| 129 |
|
|
/// Calls `visit(x, weight)` at the nodes of Simpson's rule in ln x over [`low`, `high`], so the |
| 130 |
|
|
/// sum of weight f(x) approximates the integral of f(x) dx; the end nodes are `low` and `high` |
| 131 |
|
|
/// exactly. |
| 132 |
|
|
/// @param low Positive, below `high`. |
| 133 |
|
|
/// @param intervals Even and positive. |
| 134 |
|
|
template <typename Visit> |
| 135 |
|
353 |
void ForEachLogSimpsonNode(double low, double high, int intervals, const Visit& visit) { |
| 136 |
|
353 |
const double a = std::log(low); |
| 137 |
|
353 |
const double h = (std::log(high) - a) / intervals; |
| 138 |
8/8
void terraingen::ForEachLogSimpsonNode<ForEachLogSimpsonNode_IntegratesPowerLawsAcrossDecades_Test::TestBody()::{lambda(double, double)#1}>(double, double, int, ForEachLogSimpsonNode_IntegratesPowerLawsAcrossDecades_Test::TestBody()::{lambda(double, double)#1} const&):
✓ Branch 0 taken 257 times.
✓ Branch 1 taken 1 time.
void terraingen::ForEachLogSimpsonNode<ForEachLogSimpsonNode_StartsAndEndsExactlyAtTheBounds_Test::TestBody()::{lambda(double, double)#1}>(double, double, int, ForEachLogSimpsonNode_StartsAndEndsExactlyAtTheBounds_Test::TestBody()::{lambda(double, double)#1} const&):
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 1 time.
void terraingen::ForEachLogSimpsonNode<terraingen::(anonymous namespace)::ArealFraction(terraingen::SizeFrequencyDistribution const&, double, double)::{lambda(double, double)#1}>(double, double, int, terraingen::(anonymous namespace)::ArealFraction(terraingen::SizeFrequencyDistribution const&, double, double)::{lambda(double, double)#1} const&):
✓ Branch 0 taken 2049 times.
✓ Branch 1 taken 1 time.
void terraingen::ForEachLogSimpsonNode<terraingen::BoulderLayer::UnresolvedNodes(double) const::{lambda(double, double)#1}::operator()(double, double) const::{lambda(double, double)#1}>(double, double, int, terraingen::BoulderLayer::UnresolvedNodes(double) const::{lambda(double, double)#1}::operator()(double, double) const::{lambda(double, double)#1} const&):
✓ Branch 0 taken 5950 times.
✓ Branch 1 taken 350 times.
|
8626 |
for (int i = 0; i <= intervals; ++i) { |
| 139 |
16/16
void terraingen::ForEachLogSimpsonNode<ForEachLogSimpsonNode_IntegratesPowerLawsAcrossDecades_Test::TestBody()::{lambda(double, double)#1}>(double, double, int, ForEachLogSimpsonNode_IntegratesPowerLawsAcrossDecades_Test::TestBody()::{lambda(double, double)#1} const&):
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 255 times.
✓ Branch 3 taken 1 time.
void terraingen::ForEachLogSimpsonNode<ForEachLogSimpsonNode_StartsAndEndsExactlyAtTheBounds_Test::TestBody()::{lambda(double, double)#1}>(double, double, int, ForEachLogSimpsonNode_StartsAndEndsExactlyAtTheBounds_Test::TestBody()::{lambda(double, double)#1} const&):
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 1 time.
void terraingen::ForEachLogSimpsonNode<terraingen::(anonymous namespace)::ArealFraction(terraingen::SizeFrequencyDistribution const&, double, double)::{lambda(double, double)#1}>(double, double, int, terraingen::(anonymous namespace)::ArealFraction(terraingen::SizeFrequencyDistribution const&, double, double)::{lambda(double, double)#1} const&):
✓ Branch 0 taken 2048 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 2047 times.
✓ Branch 3 taken 1 time.
void terraingen::ForEachLogSimpsonNode<terraingen::BoulderLayer::UnresolvedNodes(double) const::{lambda(double, double)#1}::operator()(double, double) const::{lambda(double, double)#1}>(double, double, int, terraingen::BoulderLayer::UnresolvedNodes(double) const::{lambda(double, double)#1}::operator()(double, double) const::{lambda(double, double)#1} const&):
✓ Branch 0 taken 5600 times.
✓ Branch 1 taken 350 times.
✓ Branch 2 taken 5250 times.
✓ Branch 3 taken 350 times.
|
8273 |
const double x = i == 0 ? low : (i == intervals ? high : std::exp(a + h * i)); |
| 140 |
16/16
void terraingen::ForEachLogSimpsonNode<ForEachLogSimpsonNode_IntegratesPowerLawsAcrossDecades_Test::TestBody()::{lambda(double, double)#1}>(double, double, int, ForEachLogSimpsonNode_IntegratesPowerLawsAcrossDecades_Test::TestBody()::{lambda(double, double)#1} const&):
✓ Branch 0 taken 255 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 127 times.
✓ Branch 3 taken 128 times.
void terraingen::ForEachLogSimpsonNode<ForEachLogSimpsonNode_StartsAndEndsExactlyAtTheBounds_Test::TestBody()::{lambda(double, double)#1}>(double, double, int, ForEachLogSimpsonNode_StartsAndEndsExactlyAtTheBounds_Test::TestBody()::{lambda(double, double)#1} const&):
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 8 times.
void terraingen::ForEachLogSimpsonNode<terraingen::(anonymous namespace)::ArealFraction(terraingen::SizeFrequencyDistribution const&, double, double)::{lambda(double, double)#1}>(double, double, int, terraingen::(anonymous namespace)::ArealFraction(terraingen::SizeFrequencyDistribution const&, double, double)::{lambda(double, double)#1} const&):
✓ Branch 0 taken 2047 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1023 times.
✓ Branch 3 taken 1024 times.
void terraingen::ForEachLogSimpsonNode<terraingen::BoulderLayer::UnresolvedNodes(double) const::{lambda(double, double)#1}::operator()(double, double) const::{lambda(double, double)#1}>(double, double, int, terraingen::BoulderLayer::UnresolvedNodes(double) const::{lambda(double, double)#1}::operator()(double, double) const::{lambda(double, double)#1} const&):
✓ Branch 0 taken 5250 times.
✓ Branch 1 taken 700 times.
✓ Branch 2 taken 2450 times.
✓ Branch 3 taken 2800 times.
|
8273 |
const double simpson = (i == 0 || i == intervals) ? 1.0 : (i % 2 == 1 ? 4.0 : 2.0); |
| 141 |
|
8273 |
visit(x, simpson * h / 3.0 * x); |
| 142 |
|
|
} |
| 143 |
|
353 |
} |
| 144 |
|
|
|
| 145 |
|
|
} // namespace terraingen |
| 146 |
|
|
|