| Line |
Branch |
Exec |
Source |
| 1 |
|
|
// SPDX-License-Identifier: BSD-3-Clause |
| 2 |
|
|
|
| 3 |
|
|
/// @file |
| 4 |
|
|
/// @brief Checks and lookups shared by distributions composed of others or of pieces. |
| 5 |
|
|
#pragma once |
| 6 |
|
|
|
| 7 |
|
|
#include "terraingen/distribution/size_frequency.h" |
| 8 |
|
|
#include "terraingen/util/span.h" |
| 9 |
|
|
|
| 10 |
|
|
#include <cmath> |
| 11 |
|
|
#include <cstddef> |
| 12 |
|
|
#include <memory> |
| 13 |
|
|
#include <string> |
| 14 |
|
|
#include <utility> |
| 15 |
|
|
#include <vector> |
| 16 |
|
|
|
| 17 |
|
|
namespace terraingen::detail { |
| 18 |
|
|
|
| 19 |
|
|
/// The distribution a shared pointer holds. |
| 20 |
|
|
inline const SizeFrequencyDistribution* |
| 21 |
|
1758 |
Distribution(const std::shared_ptr<const SizeFrequencyDistribution>& part) { |
| 22 |
|
1758 |
return part.get(); |
| 23 |
|
|
} |
| 24 |
|
|
|
| 25 |
|
|
/// The distribution a part holds as its `distribution` member. |
| 26 |
|
2539 |
template <typename Part> const SizeFrequencyDistribution* Distribution(const Part& part) { |
| 27 |
|
2539 |
return part.distribution.get(); |
| 28 |
|
|
} |
| 29 |
|
|
|
| 30 |
|
|
/// The distributions of `parts`: shared pointers, or structs holding one as `distribution`. |
| 31 |
|
|
template <typename Part> |
| 32 |
3/3
std::vector<terraingen::SizeFrequencyDistribution const*, std::allocator<terraingen::SizeFrequencyDistribution const*> > terraingen::detail::Distributions<std::shared_ptr<terraingen::SizeFrequencyDistribution const> >(std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > > const&):
✓ Branch 1 taken 445 times.
std::vector<terraingen::SizeFrequencyDistribution const*, std::allocator<terraingen::SizeFrequencyDistribution const*> > terraingen::detail::Distributions<terraingen::SfdPiece>(std::vector<terraingen::SfdPiece, std::allocator<terraingen::SfdPiece> > const&):
✓ Branch 1 taken 746 times.
std::vector<terraingen::SizeFrequencyDistribution const*, std::allocator<terraingen::SizeFrequencyDistribution const*> > terraingen::detail::Distributions<terraingen::WeightedSfd>(std::vector<terraingen::WeightedSfd, std::allocator<terraingen::WeightedSfd> > const&):
✓ Branch 1 taken 448 times.
|
1639 |
std::vector<const SizeFrequencyDistribution*> Distributions(const std::vector<Part>& parts) { |
| 33 |
3/3
std::vector<terraingen::SizeFrequencyDistribution const*, std::allocator<terraingen::SizeFrequencyDistribution const*> > terraingen::detail::Distributions<std::shared_ptr<terraingen::SizeFrequencyDistribution const> >(std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > > const&):
✓ Branch 1 taken 445 times.
std::vector<terraingen::SizeFrequencyDistribution const*, std::allocator<terraingen::SizeFrequencyDistribution const*> > terraingen::detail::Distributions<terraingen::SfdPiece>(std::vector<terraingen::SfdPiece, std::allocator<terraingen::SfdPiece> > const&):
✓ Branch 1 taken 746 times.
std::vector<terraingen::SizeFrequencyDistribution const*, std::allocator<terraingen::SizeFrequencyDistribution const*> > terraingen::detail::Distributions<terraingen::WeightedSfd>(std::vector<terraingen::WeightedSfd, std::allocator<terraingen::WeightedSfd> > const&):
✓ Branch 1 taken 448 times.
|
1639 |
std::vector<const SizeFrequencyDistribution*> distributions; |
| 34 |
3/3
std::vector<terraingen::SizeFrequencyDistribution const*, std::allocator<terraingen::SizeFrequencyDistribution const*> > terraingen::detail::Distributions<std::shared_ptr<terraingen::SizeFrequencyDistribution const> >(std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > > const&):
✓ Branch 1 taken 445 times.
std::vector<terraingen::SizeFrequencyDistribution const*, std::allocator<terraingen::SizeFrequencyDistribution const*> > terraingen::detail::Distributions<terraingen::SfdPiece>(std::vector<terraingen::SfdPiece, std::allocator<terraingen::SfdPiece> > const&):
✓ Branch 1 taken 746 times.
std::vector<terraingen::SizeFrequencyDistribution const*, std::allocator<terraingen::SizeFrequencyDistribution const*> > terraingen::detail::Distributions<terraingen::WeightedSfd>(std::vector<terraingen::WeightedSfd, std::allocator<terraingen::WeightedSfd> > const&):
✓ Branch 1 taken 448 times.
|
1639 |
distributions.reserve(parts.size()); |
| 35 |
7/7
std::vector<terraingen::SizeFrequencyDistribution const*, std::allocator<terraingen::SizeFrequencyDistribution const*> > terraingen::detail::Distributions<std::shared_ptr<terraingen::SizeFrequencyDistribution const> >(std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > > const&):
✓ Branch 1 taken 882 times.
✓ Branch 3 taken 882 times.
✓ Branch 4 taken 445 times.
std::vector<terraingen::SizeFrequencyDistribution const*, std::allocator<terraingen::SizeFrequencyDistribution const*> > terraingen::detail::Distributions<terraingen::SfdPiece>(std::vector<terraingen::SfdPiece, std::allocator<terraingen::SfdPiece> > const&):
✓ Branch 0 taken 1487 times.
✓ Branch 1 taken 746 times.
std::vector<terraingen::SizeFrequencyDistribution const*, std::allocator<terraingen::SizeFrequencyDistribution const*> > terraingen::detail::Distributions<terraingen::WeightedSfd>(std::vector<terraingen::WeightedSfd, std::allocator<terraingen::WeightedSfd> > const&):
✓ Branch 0 taken 528 times.
✓ Branch 1 taken 448 times.
|
4536 |
for (const Part& part : parts) { |
| 36 |
3/3
std::vector<terraingen::SizeFrequencyDistribution const*, std::allocator<terraingen::SizeFrequencyDistribution const*> > terraingen::detail::Distributions<std::shared_ptr<terraingen::SizeFrequencyDistribution const> >(std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > > const&):
✓ Branch 1 taken 882 times.
std::vector<terraingen::SizeFrequencyDistribution const*, std::allocator<terraingen::SizeFrequencyDistribution const*> > terraingen::detail::Distributions<terraingen::SfdPiece>(std::vector<terraingen::SfdPiece, std::allocator<terraingen::SfdPiece> > const&):
✓ Branch 1 taken 1487 times.
std::vector<terraingen::SizeFrequencyDistribution const*, std::allocator<terraingen::SizeFrequencyDistribution const*> > terraingen::detail::Distributions<terraingen::WeightedSfd>(std::vector<terraingen::WeightedSfd, std::allocator<terraingen::WeightedSfd> > const&):
✓ Branch 1 taken 528 times.
|
2897 |
distributions.push_back(Distribution(part)); |
| 37 |
|
|
} |
| 38 |
|
1639 |
return distributions; |
| 39 |
|
|
} |
| 40 |
|
|
|
| 41 |
|
|
/// The kind every one of `distributions` has. |
| 42 |
|
|
/// @param what The combination, for messages, such as "A minimum". |
| 43 |
|
|
/// @throws std::invalid_argument for no inputs, a null input or mixed kinds. |
| 44 |
|
|
SfdKind CommonKind(Span<const SizeFrequencyDistribution* const> distributions, |
| 45 |
|
|
const std::string& what); |
| 46 |
|
|
|
| 47 |
|
|
/// Where `distribution` may be evaluated, in meters: everywhere when it allows extrapolation, |
| 48 |
|
|
/// otherwise its valid range. |
| 49 |
|
|
DiameterRange UsableRange(const SizeFrequencyDistribution& distribution); |
| 50 |
|
|
|
| 51 |
|
|
/// The diameters in meters every one of `ranges` holds. |
| 52 |
|
|
/// @throws std::invalid_argument with `message` if no diameter is in all of them. |
| 53 |
|
|
DiameterRange IntersectRanges(Span<const DiameterRange> ranges, const std::string& message); |
| 54 |
|
|
|
| 55 |
|
|
/// The diameters in meters where `range(distribution)` holds for every distribution of `parts`. |
| 56 |
|
|
/// @throws std::invalid_argument with `message` if no diameter is in all of them. |
| 57 |
|
|
template <typename Part, typename Range> |
| 58 |
3/3
terraingen::DiameterRange terraingen::detail::IntersectRanges<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, IntersectRanges_IntersectsTheRangesOfParts_Test::TestBody()::{lambda(terraingen::SizeFrequencyDistribution const&)#1}>(std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > > const&, IntersectRanges_IntersectsTheRangesOfParts_Test::TestBody()::{lambda(terraingen::SizeFrequencyDistribution const&)#1} const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):
✓ Branch 1 taken 1 time.
terraingen::DiameterRange terraingen::detail::IntersectRanges<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, terraingen::MinimumSfd::MinimumSfd(terraingen::SfdKind, std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > >&&)::{lambda(terraingen::SizeFrequencyDistribution const&)#1}>(std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > > const&, terraingen::MinimumSfd::MinimumSfd(terraingen::SfdKind, std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > >&&)::{lambda(terraingen::SizeFrequencyDistribution const&)#1} const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):
✓ Branch 1 taken 437 times.
terraingen::DiameterRange terraingen::detail::IntersectRanges<terraingen::WeightedSfd, terraingen::DiameterRange (terraingen::SizeFrequencyDistribution const&)>(std::vector<terraingen::WeightedSfd, std::allocator<terraingen::WeightedSfd> > const&, terraingen::DiameterRange ( const&)(terraingen::SizeFrequencyDistribution const&), std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):
✓ Branch 1 taken 444 times.
|
882 |
DiameterRange IntersectRanges(const std::vector<Part>& parts, const Range& range, |
| 59 |
|
|
const std::string& message) { |
| 60 |
3/3
terraingen::DiameterRange terraingen::detail::IntersectRanges<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, IntersectRanges_IntersectsTheRangesOfParts_Test::TestBody()::{lambda(terraingen::SizeFrequencyDistribution const&)#1}>(std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > > const&, IntersectRanges_IntersectsTheRangesOfParts_Test::TestBody()::{lambda(terraingen::SizeFrequencyDistribution const&)#1} const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):
✓ Branch 1 taken 1 time.
terraingen::DiameterRange terraingen::detail::IntersectRanges<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, terraingen::MinimumSfd::MinimumSfd(terraingen::SfdKind, std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > >&&)::{lambda(terraingen::SizeFrequencyDistribution const&)#1}>(std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > > const&, terraingen::MinimumSfd::MinimumSfd(terraingen::SfdKind, std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > >&&)::{lambda(terraingen::SizeFrequencyDistribution const&)#1} const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):
✓ Branch 1 taken 437 times.
terraingen::DiameterRange terraingen::detail::IntersectRanges<terraingen::WeightedSfd, terraingen::DiameterRange (terraingen::SizeFrequencyDistribution const&)>(std::vector<terraingen::WeightedSfd, std::allocator<terraingen::WeightedSfd> > const&, terraingen::DiameterRange ( const&)(terraingen::SizeFrequencyDistribution const&), std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):
✓ Branch 1 taken 444 times.
|
882 |
std::vector<DiameterRange> ranges; |
| 61 |
3/3
terraingen::DiameterRange terraingen::detail::IntersectRanges<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, IntersectRanges_IntersectsTheRangesOfParts_Test::TestBody()::{lambda(terraingen::SizeFrequencyDistribution const&)#1}>(std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > > const&, IntersectRanges_IntersectsTheRangesOfParts_Test::TestBody()::{lambda(terraingen::SizeFrequencyDistribution const&)#1} const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):
✓ Branch 1 taken 1 time.
terraingen::DiameterRange terraingen::detail::IntersectRanges<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, terraingen::MinimumSfd::MinimumSfd(terraingen::SfdKind, std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > >&&)::{lambda(terraingen::SizeFrequencyDistribution const&)#1}>(std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > > const&, terraingen::MinimumSfd::MinimumSfd(terraingen::SfdKind, std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > >&&)::{lambda(terraingen::SizeFrequencyDistribution const&)#1} const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):
✓ Branch 1 taken 437 times.
terraingen::DiameterRange terraingen::detail::IntersectRanges<terraingen::WeightedSfd, terraingen::DiameterRange (terraingen::SizeFrequencyDistribution const&)>(std::vector<terraingen::WeightedSfd, std::allocator<terraingen::WeightedSfd> > const&, terraingen::DiameterRange ( const&)(terraingen::SizeFrequencyDistribution const&), std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):
✓ Branch 1 taken 444 times.
|
882 |
ranges.reserve(parts.size()); |
| 62 |
8/8
terraingen::DiameterRange terraingen::detail::IntersectRanges<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, IntersectRanges_IntersectsTheRangesOfParts_Test::TestBody()::{lambda(terraingen::SizeFrequencyDistribution const&)#1}>(std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > > const&, IntersectRanges_IntersectsTheRangesOfParts_Test::TestBody()::{lambda(terraingen::SizeFrequencyDistribution const&)#1} const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):
✓ Branch 1 taken 2 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 1 time.
terraingen::DiameterRange terraingen::detail::IntersectRanges<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, terraingen::MinimumSfd::MinimumSfd(terraingen::SfdKind, std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > >&&)::{lambda(terraingen::SizeFrequencyDistribution const&)#1}>(std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > > const&, terraingen::MinimumSfd::MinimumSfd(terraingen::SfdKind, std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > >&&)::{lambda(terraingen::SizeFrequencyDistribution const&)#1} const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):
✓ Branch 1 taken 874 times.
✓ Branch 3 taken 874 times.
✓ Branch 4 taken 437 times.
terraingen::DiameterRange terraingen::detail::IntersectRanges<terraingen::WeightedSfd, terraingen::DiameterRange (terraingen::SizeFrequencyDistribution const&)>(std::vector<terraingen::WeightedSfd, std::allocator<terraingen::WeightedSfd> > const&, terraingen::DiameterRange ( const&)(terraingen::SizeFrequencyDistribution const&), std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):
✓ Branch 0 taken 524 times.
✓ Branch 1 taken 444 times.
|
2282 |
for (const Part& part : parts) { |
| 63 |
3/3
terraingen::DiameterRange terraingen::detail::IntersectRanges<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, IntersectRanges_IntersectsTheRangesOfParts_Test::TestBody()::{lambda(terraingen::SizeFrequencyDistribution const&)#1}>(std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > > const&, IntersectRanges_IntersectsTheRangesOfParts_Test::TestBody()::{lambda(terraingen::SizeFrequencyDistribution const&)#1} const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):
✓ Branch 1 taken 2 times.
terraingen::DiameterRange terraingen::detail::IntersectRanges<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, terraingen::MinimumSfd::MinimumSfd(terraingen::SfdKind, std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > >&&)::{lambda(terraingen::SizeFrequencyDistribution const&)#1}>(std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > > const&, terraingen::MinimumSfd::MinimumSfd(terraingen::SfdKind, std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > >&&)::{lambda(terraingen::SizeFrequencyDistribution const&)#1} const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):
✓ Branch 1 taken 874 times.
terraingen::DiameterRange terraingen::detail::IntersectRanges<terraingen::WeightedSfd, terraingen::DiameterRange (terraingen::SizeFrequencyDistribution const&)>(std::vector<terraingen::WeightedSfd, std::allocator<terraingen::WeightedSfd> > const&, terraingen::DiameterRange ( const&)(terraingen::SizeFrequencyDistribution const&), std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):
✓ Branch 1 taken 524 times.
|
1924 |
ranges.push_back(range(*Distribution(part))); |
| 64 |
|
|
} |
| 65 |
3/3
terraingen::DiameterRange terraingen::detail::IntersectRanges<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, IntersectRanges_IntersectsTheRangesOfParts_Test::TestBody()::{lambda(terraingen::SizeFrequencyDistribution const&)#1}>(std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > > const&, IntersectRanges_IntersectsTheRangesOfParts_Test::TestBody()::{lambda(terraingen::SizeFrequencyDistribution const&)#1} const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):
✓ Branch 2 taken 1 time.
terraingen::DiameterRange terraingen::detail::IntersectRanges<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, terraingen::MinimumSfd::MinimumSfd(terraingen::SfdKind, std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > >&&)::{lambda(terraingen::SizeFrequencyDistribution const&)#1}>(std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > > const&, terraingen::MinimumSfd::MinimumSfd(terraingen::SfdKind, std::vector<std::shared_ptr<terraingen::SizeFrequencyDistribution const>, std::allocator<std::shared_ptr<terraingen::SizeFrequencyDistribution const> > >&&)::{lambda(terraingen::SizeFrequencyDistribution const&)#1} const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):
✓ Branch 2 taken 436 times.
terraingen::DiameterRange terraingen::detail::IntersectRanges<terraingen::WeightedSfd, terraingen::DiameterRange (terraingen::SizeFrequencyDistribution const&)>(std::vector<terraingen::WeightedSfd, std::allocator<terraingen::WeightedSfd> > const&, terraingen::DiameterRange ( const&)(terraingen::SizeFrequencyDistribution const&), std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):
✓ Branch 2 taken 443 times.
|
1762 |
return IntersectRanges(ranges, message); |
| 66 |
|
882 |
} |
| 67 |
|
|
|
| 68 |
|
|
/// Checks the starts of pieces in meters: the first at `range.min`, the rest finite and strictly |
| 69 |
|
|
/// increasing below `range.max`. |
| 70 |
|
|
/// @param what What the pieces are called in messages, such as "Segment". |
| 71 |
|
|
/// @throws std::invalid_argument for no starts or starts that break those rules. |
| 72 |
|
|
void CheckStarts(Span<const double> starts, const DiameterRange& range, const std::string& what); |
| 73 |
|
|
|
| 74 |
|
|
/// The valid range of a distribution made of `pieces`: from the first one's `start` (0 without |
| 75 |
|
|
/// pieces) to `maxDiameter`. |
| 76 |
|
|
template <typename Piece> |
| 77 |
4/4
terraingen::DiameterRange terraingen::detail::PieceRange<terraingen::PowerLawSegment>(std::vector<terraingen::PowerLawSegment, std::allocator<terraingen::PowerLawSegment> > const&, double):
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 1 time.
terraingen::DiameterRange terraingen::detail::PieceRange<terraingen::SfdPiece>(std::vector<terraingen::SfdPiece, std::allocator<terraingen::SfdPiece> > const&, double):
✓ Branch 0 taken 745 times.
✓ Branch 1 taken 1 time.
|
782 |
DiameterRange PieceRange(const std::vector<Piece>& pieces, double maxDiameter) { |
| 78 |
4/4
terraingen::DiameterRange terraingen::detail::PieceRange<terraingen::PowerLawSegment>(std::vector<terraingen::PowerLawSegment, std::allocator<terraingen::PowerLawSegment> > const&, double):
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 1 time.
terraingen::DiameterRange terraingen::detail::PieceRange<terraingen::SfdPiece>(std::vector<terraingen::SfdPiece, std::allocator<terraingen::SfdPiece> > const&, double):
✓ Branch 0 taken 745 times.
✓ Branch 1 taken 1 time.
|
782 |
return {pieces.empty() ? 0.0 : pieces.front().start, maxDiameter}; |
| 79 |
|
|
} |
| 80 |
|
|
|
| 81 |
|
|
/// The `start` of each of `pieces`. |
| 82 |
2/2
std::vector<double, std::allocator<double> > terraingen::detail::Starts<terraingen::PowerLawSegment>(std::vector<terraingen::PowerLawSegment, std::allocator<terraingen::PowerLawSegment> > const&):
✓ Branch 1 taken 33 times.
std::vector<double, std::allocator<double> > terraingen::detail::Starts<terraingen::SfdPiece>(std::vector<terraingen::SfdPiece, std::allocator<terraingen::SfdPiece> > const&):
✓ Branch 1 taken 742 times.
|
775 |
template <typename Piece> std::vector<double> Starts(const std::vector<Piece>& pieces) { |
| 83 |
2/2
std::vector<double, std::allocator<double> > terraingen::detail::Starts<terraingen::PowerLawSegment>(std::vector<terraingen::PowerLawSegment, std::allocator<terraingen::PowerLawSegment> > const&):
✓ Branch 1 taken 33 times.
std::vector<double, std::allocator<double> > terraingen::detail::Starts<terraingen::SfdPiece>(std::vector<terraingen::SfdPiece, std::allocator<terraingen::SfdPiece> > const&):
✓ Branch 1 taken 742 times.
|
775 |
std::vector<double> starts; |
| 84 |
2/2
std::vector<double, std::allocator<double> > terraingen::detail::Starts<terraingen::PowerLawSegment>(std::vector<terraingen::PowerLawSegment, std::allocator<terraingen::PowerLawSegment> > const&):
✓ Branch 1 taken 33 times.
std::vector<double, std::allocator<double> > terraingen::detail::Starts<terraingen::SfdPiece>(std::vector<terraingen::SfdPiece, std::allocator<terraingen::SfdPiece> > const&):
✓ Branch 1 taken 742 times.
|
775 |
starts.reserve(pieces.size()); |
| 85 |
4/4
std::vector<double, std::allocator<double> > terraingen::detail::Starts<terraingen::PowerLawSegment>(std::vector<terraingen::PowerLawSegment, std::allocator<terraingen::PowerLawSegment> > const&):
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 33 times.
std::vector<double, std::allocator<double> > terraingen::detail::Starts<terraingen::SfdPiece>(std::vector<terraingen::SfdPiece, std::allocator<terraingen::SfdPiece> > const&):
✓ Branch 0 taken 1482 times.
✓ Branch 1 taken 742 times.
|
2329 |
for (const Piece& piece : pieces) { |
| 86 |
2/2
std::vector<double, std::allocator<double> > terraingen::detail::Starts<terraingen::PowerLawSegment>(std::vector<terraingen::PowerLawSegment, std::allocator<terraingen::PowerLawSegment> > const&):
✓ Branch 1 taken 72 times.
std::vector<double, std::allocator<double> > terraingen::detail::Starts<terraingen::SfdPiece>(std::vector<terraingen::SfdPiece, std::allocator<terraingen::SfdPiece> > const&):
✓ Branch 1 taken 1482 times.
|
1554 |
starts.push_back(piece.start); |
| 87 |
|
|
} |
| 88 |
|
775 |
return starts; |
| 89 |
|
|
} |
| 90 |
|
|
|
| 91 |
|
|
/// Checks the join at `start` (meters) of a piece giving N = `above` after one giving `below`. |
| 92 |
|
|
/// @param tolerance The relative mismatch allowed. |
| 93 |
|
|
/// @param allowDiscontinuities Whether a larger downward jump is allowed. |
| 94 |
|
|
/// @throws std::invalid_argument for a rise, or a drop beyond `tolerance` unless allowed. |
| 95 |
|
|
void CheckJoin(double below, double above, double start, double tolerance, |
| 96 |
|
|
bool allowDiscontinuities); |
| 97 |
|
|
|
| 98 |
|
|
/// `CheckJoin` at every join of `pieces`, each evaluated as `cumulative(piece, diameter)`. |
| 99 |
|
|
template <typename Piece, typename Cumulative> |
| 100 |
|
771 |
void CheckJoins(const std::vector<Piece>& pieces, const Cumulative& cumulative, double tolerance, |
| 101 |
|
|
bool allowDiscontinuities) { |
| 102 |
6/6
void terraingen::detail::CheckJoins<terraingen::PowerLawSegment, CheckJoins_ChecksEveryJoinOfThePieces_Test::TestBody()::{lambda(terraingen::PowerLawSegment const&, double)#1}>(std::vector<terraingen::PowerLawSegment, std::allocator<terraingen::PowerLawSegment> > const&, CheckJoins_ChecksEveryJoinOfThePieces_Test::TestBody()::{lambda(terraingen::PowerLawSegment const&, double)#1} const&, double, bool):
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 time.
void terraingen::detail::CheckJoins<terraingen::PowerLawSegment, terraingen::PiecewisePowerLawSfd::PiecewisePowerLawSfd(std::vector<terraingen::PowerLawSegment, std::allocator<terraingen::PowerLawSegment> >, terraingen::SfdKind, double, terraingen::SfdJoins)::{lambda(terraingen::PowerLawSegment const&, double)#1}>(std::vector<terraingen::PowerLawSegment, std::allocator<terraingen::PowerLawSegment> > const&, terraingen::PiecewisePowerLawSfd::PiecewisePowerLawSfd(std::vector<terraingen::PowerLawSegment, std::allocator<terraingen::PowerLawSegment> >, terraingen::SfdKind, double, terraingen::SfdJoins)::{lambda(terraingen::PowerLawSegment const&, double)#1} const&, double, bool):
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 27 times.
void terraingen::detail::CheckJoins<terraingen::SfdPiece, terraingen::SplicedSfd::SplicedSfd(std::vector<terraingen::SfdPiece, std::allocator<terraingen::SfdPiece> >, double, double)::{lambda(terraingen::SfdPiece const&, double)#1}>(std::vector<terraingen::SfdPiece, std::allocator<terraingen::SfdPiece> > const&, terraingen::SplicedSfd::SplicedSfd(std::vector<terraingen::SfdPiece, std::allocator<terraingen::SfdPiece> >, double, double)::{lambda(terraingen::SfdPiece const&, double)#1} const&, double, bool):
✓ Branch 0 taken 737 times.
✓ Branch 1 taken 737 times.
|
1540 |
for (std::size_t i = 1; i < pieces.size(); ++i) { |
| 103 |
|
775 |
const double start = pieces[i].start; |
| 104 |
|
775 |
CheckJoin(cumulative(pieces[i - 1], start), cumulative(pieces[i], start), start, tolerance, |
| 105 |
|
|
allowDiscontinuities); |
| 106 |
|
|
} |
| 107 |
|
765 |
} |
| 108 |
|
|
|
| 109 |
|
|
/// The index of the piece that applies at `diameter` (meters): the last whose `start` is below it, |
| 110 |
|
|
/// so the lower piece applies at a join. |
| 111 |
|
|
/// @param pieces Pieces with increasing `start`. |
| 112 |
|
|
template <typename Piece> |
| 113 |
|
3331970 |
std::size_t PieceIndex(const std::vector<Piece>& pieces, double diameter) { |
| 114 |
|
3331970 |
std::size_t index = 0; |
| 115 |
8/8
unsigned long terraingen::detail::PieceIndex<terraingen::PowerLawSegment>(std::vector<terraingen::PowerLawSegment, std::allocator<terraingen::PowerLawSegment> > const&, double):
✓ Branch 0 taken 523752 times.
✓ Branch 1 taken 120906 times.
✓ Branch 2 taken 283104 times.
✓ Branch 3 taken 240648 times.
unsigned long terraingen::detail::PieceIndex<terraingen::SfdPiece>(std::vector<terraingen::SfdPiece, std::allocator<terraingen::SfdPiece> > const&, double):
✓ Branch 0 taken 2972896 times.
✓ Branch 1 taken 1441345 times.
✓ Branch 2 taken 1443825 times.
✓ Branch 3 taken 1529071 times.
|
5058899 |
while (index + 1 < pieces.size() && pieces[index + 1].start < diameter) { |
| 116 |
|
|
++index; |
| 117 |
|
|
} |
| 118 |
|
3331970 |
return index; |
| 119 |
|
|
} |
| 120 |
|
|
|
| 121 |
|
|
/// The first piece from `index` on that `holds(index, high)` accepts, with `high` the end of the |
| 122 |
|
|
/// piece's interval capped at `maxDiameter` meters; the last piece if none does. |
| 123 |
|
|
template <typename Piece, typename Holds> |
| 124 |
|
140552 |
std::size_t WalkPieces(const std::vector<Piece>& pieces, std::size_t index, double maxDiameter, |
| 125 |
|
|
const Holds& holds) { |
| 126 |
11/12
unsigned long terraingen::detail::WalkPieces<terraingen::PowerLawSegment, WalkPieces_StopsAtTheFirstPieceAcceptedOrTheLast_Test::TestBody()::{lambda(unsigned long, double)#1}>(std::vector<terraingen::PowerLawSegment, std::allocator<terraingen::PowerLawSegment> > const&, unsigned long, double, WalkPieces_StopsAtTheFirstPieceAcceptedOrTheLast_Test::TestBody()::{lambda(unsigned long, double)#1} const&):
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 time.
unsigned long terraingen::detail::WalkPieces<terraingen::PowerLawSegment, WalkPieces_StopsAtTheFirstPieceAcceptedOrTheLast_Test::TestBody()::{lambda(unsigned long, double)#2}>(std::vector<terraingen::PowerLawSegment, std::allocator<terraingen::PowerLawSegment> > const&, unsigned long, double, WalkPieces_StopsAtTheFirstPieceAcceptedOrTheLast_Test::TestBody()::{lambda(unsigned long, double)#2} const&):
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
unsigned long terraingen::detail::WalkPieces<terraingen::PowerLawSegment, terraingen::PiecewisePowerLawSfd::InvertCumulative(double, double, double) const::{lambda(unsigned long, double)#1}>(std::vector<terraingen::PowerLawSegment, std::allocator<terraingen::PowerLawSegment> > const&, unsigned long, double, terraingen::PiecewisePowerLawSfd::InvertCumulative(double, double, double) const::{lambda(unsigned long, double)#1} const&):
✓ Branch 0 taken 83034 times.
✓ Branch 1 taken 2891 times.
✓ Branch 2 taken 5575 times.
✓ Branch 3 taken 77459 times.
unsigned long terraingen::detail::WalkPieces<terraingen::SfdPiece, terraingen::SplicedSfd::InvertCumulative(double, double, double) const::{lambda(unsigned long, double)#1}>(std::vector<terraingen::SfdPiece, std::allocator<terraingen::SfdPiece> > const&, unsigned long, double, terraingen::SplicedSfd::InvertCumulative(double, double, double) const::{lambda(unsigned long, double)#1} const&):
✓ Branch 0 taken 60150 times.
✓ Branch 1 taken 5871 times.
✓ Branch 2 taken 5821 times.
✓ Branch 3 taken 54329 times.
|
283739 |
while (index + 1 < pieces.size() && |
| 127 |
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
|
143188 |
!holds(index, std::fmin(maxDiameter, pieces[index + 1].start))) { |
| 128 |
|
2 |
++index; |
| 129 |
|
|
} |
| 130 |
|
140552 |
return index; |
| 131 |
|
|
} |
| 132 |
|
|
|
| 133 |
|
|
/// The interval in meters of piece `index` within [`minDiameter`, `maxDiameter`]. |
| 134 |
|
|
template <typename Piece> |
| 135 |
|
60202 |
std::pair<double, double> PieceInterval(const std::vector<Piece>& pieces, std::size_t index, |
| 136 |
|
|
double minDiameter, double maxDiameter) { |
| 137 |
|
60202 |
const double high = |
| 138 |
4/4
std::pair<double, double> terraingen::detail::PieceInterval<terraingen::PowerLawSegment>(std::vector<terraingen::PowerLawSegment, std::allocator<terraingen::PowerLawSegment> > const&, unsigned long, double, double):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
std::pair<double, double> terraingen::detail::PieceInterval<terraingen::SfdPiece>(std::vector<terraingen::SfdPiece, std::allocator<terraingen::SfdPiece> > const&, unsigned long, double, double):
✓ Branch 0 taken 54329 times.
✓ Branch 1 taken 5871 times.
|
60202 |
index + 1 < pieces.size() ? std::fmin(maxDiameter, pieces[index + 1].start) : maxDiameter; |
| 139 |
|
60202 |
return {std::fmax(minDiameter, pieces[index].start), high}; |
| 140 |
|
|
} |
| 141 |
|
|
|
| 142 |
|
|
} // namespace terraingen::detail |
| 143 |
|
|
|