./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
128 / 135
94.8%
Branches:
85 / 94
90.4%
Functions:
11 / 11
100.0%

src/raster/kernels.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief Interpolation kernel weights and kernel interpolation over a lattice.
5 #pragma once
6
7 #include "terraingen/raster/resample.h"
8
9 #include <array>
10 #include <cmath>
11 #include <cstddef>
12 #include <optional>
13 #include <type_traits>
14
15 namespace terraingen {
16
17 /// The weight of a cubic, Lanczos or B-spline kernel at an offset of `x` cells, before any
18 /// normalization.
19 double KernelWeight(ResampleMethod method, double x);
20
21 /// The weights of the 2 `KernelRadius` cells around a point `fraction` of the way from cell 0 to
22 /// cell 1, for cells -radius + 1 to radius, as the interpolation applies them; nearest is not a
23 /// kernel and gives none.
24 /// @param fraction In [0, 1).
25 std::array<double, 6> KernelWeights(ResampleMethod method, double fraction);
26
27 /// `InterpolateLattice` of a kernel of `radius` from its taps' weights, as `KernelWeights` gives
28 /// them: `wxs` along the row from column `u0` and `wys` down the column from row `v0`, the cell
29 /// at or before the point along each axis. The result has the type `value` gives.
30 template <typename Value, typename Missing,
31 typename Result = std::decay_t<std::invoke_result_t<const Value&, double, double>>>
32 1521594 std::optional<Result> InterpolateLatticeWeights(double u0, double v0,
33 const std::array<double, 6>& wxs,
34 const std::array<double, 6>& wys, int radius,
35 const Value& value, const Missing& missing) {
36 1521594 double sum = 0.0;
37
14/14
std::optional<double> terraingen::InterpolateLatticeWeights<terraingen::(anonymous namespace)::Refinement::Interpolate(terraingen::(anonymous namespace)::NodeFrame const&, terraingen::detail::LatticeWindow<double> const&, int, double, double) const::{lambda(double, double)#1}, terraingen::(anonymous namespace)::Refinement::Interpolate(terraingen::(anonymous namespace)::NodeFrame const&, terraingen::detail::LatticeWindow<double> const&, int, double, double) const::{lambda(double)#1}, double>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::(anonymous namespace)::Refinement::Interpolate(terraingen::(anonymous namespace)::NodeFrame const&, terraingen::detail::LatticeWindow<double> const&, int, double, double) const::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::Refinement::Interpolate(terraingen::(anonymous namespace)::NodeFrame const&, terraingen::detail::LatticeWindow<double> const&, int, double, double) const::{lambda(double)#1} const&):
✓ Branch 0 taken 1100756 times.
✓ Branch 1 taken 275189 times.
std::optional<float> terraingen::InterpolateLatticeWeights<std::function<float (double, double)>, (anonymous namespace)::InterpolateAt(std::function<float (double, double)> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, std::function<float (double, double)> const&, (anonymous namespace)::InterpolateAt(std::function<float (double, double)> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1} const&):
✓ Branch 0 taken 436 times.
✓ Branch 1 taken 109 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(double, double)#1}, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(float)#1} const&):
✓ Branch 0 taken 1192533 times.
✓ Branch 1 taken 471908 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(double, double)#1}, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1} const&):
✓ Branch 0 taken 54280 times.
✓ Branch 1 taken 13408 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(double, double)#1}, terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(float)#1} const&):
✓ Branch 0 taken 2157501 times.
✓ Branch 1 taken 576678 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::detail::SeamField::At(double, double) const::{lambda(double, double)#1}, terraingen::detail::SeamField::At(double, double) const::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::detail::SeamField::At(double, double) const::{lambda(double, double)#1} const&, terraingen::detail::SeamField::At(double, double) const::{lambda(float)#1} const&):
✓ Branch 0 taken 264730 times.
✓ Branch 1 taken 66381 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(double, double)#1}, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(double, double)#1} const&, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(float)#1} const&):
✓ Branch 0 taken 390226 times.
✓ Branch 1 taken 112182 times.
6676317 for (int j = 1 - radius; j <= radius; ++j) {
38 5160462 const double wy = wys[static_cast<std::size_t>(j + radius - 1)];
39
14/14
std::optional<double> terraingen::InterpolateLatticeWeights<terraingen::(anonymous namespace)::Refinement::Interpolate(terraingen::(anonymous namespace)::NodeFrame const&, terraingen::detail::LatticeWindow<double> const&, int, double, double) const::{lambda(double, double)#1}, terraingen::(anonymous namespace)::Refinement::Interpolate(terraingen::(anonymous namespace)::NodeFrame const&, terraingen::detail::LatticeWindow<double> const&, int, double, double) const::{lambda(double)#1}, double>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::(anonymous namespace)::Refinement::Interpolate(terraingen::(anonymous namespace)::NodeFrame const&, terraingen::detail::LatticeWindow<double> const&, int, double, double) const::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::Refinement::Interpolate(terraingen::(anonymous namespace)::NodeFrame const&, terraingen::detail::LatticeWindow<double> const&, int, double, double) const::{lambda(double)#1} const&):
✓ Branch 0 taken 4403024 times.
✓ Branch 1 taken 1100756 times.
std::optional<float> terraingen::InterpolateLatticeWeights<std::function<float (double, double)>, (anonymous namespace)::InterpolateAt(std::function<float (double, double)> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, std::function<float (double, double)> const&, (anonymous namespace)::InterpolateAt(std::function<float (double, double)> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1} const&):
✓ Branch 0 taken 1960 times.
✓ Branch 1 taken 436 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(double, double)#1}, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(float)#1} const&):
✓ Branch 0 taken 4515643 times.
✓ Branch 1 taken 1192431 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(double, double)#1}, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1} const&):
✓ Branch 0 taken 220994 times.
✓ Branch 1 taken 54279 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(double, double)#1}, terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(float)#1} const&):
✓ Branch 0 taken 8900156 times.
✓ Branch 1 taken 2151882 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::detail::SeamField::At(double, double) const::{lambda(double, double)#1}, terraingen::detail::SeamField::At(double, double) const::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::detail::SeamField::At(double, double) const::{lambda(double, double)#1} const&, terraingen::detail::SeamField::At(double, double) const::{lambda(float)#1} const&):
✓ Branch 0 taken 1058138 times.
✓ Branch 1 taken 264730 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(double, double)#1}, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(double, double)#1} const&, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(float)#1} const&):
✓ Branch 0 taken 1443790 times.
✓ Branch 1 taken 390209 times.
25698428 for (int i = 1 - radius; i <= radius; ++i) {
40
14/14
std::optional<double> terraingen::InterpolateLatticeWeights<terraingen::(anonymous namespace)::Refinement::Interpolate(terraingen::(anonymous namespace)::NodeFrame const&, terraingen::detail::LatticeWindow<double> const&, int, double, double) const::{lambda(double, double)#1}, terraingen::(anonymous namespace)::Refinement::Interpolate(terraingen::(anonymous namespace)::NodeFrame const&, terraingen::detail::LatticeWindow<double> const&, int, double, double) const::{lambda(double)#1}, double>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::(anonymous namespace)::Refinement::Interpolate(terraingen::(anonymous namespace)::NodeFrame const&, terraingen::detail::LatticeWindow<double> const&, int, double, double) const::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::Refinement::Interpolate(terraingen::(anonymous namespace)::NodeFrame const&, terraingen::detail::LatticeWindow<double> const&, int, double, double) const::{lambda(double)#1} const&):
✓ Branch 0 taken 1030509 times.
✓ Branch 1 taken 3372515 times.
std::optional<float> terraingen::InterpolateLatticeWeights<std::function<float (double, double)>, (anonymous namespace)::InterpolateAt(std::function<float (double, double)> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, std::function<float (double, double)> const&, (anonymous namespace)::InterpolateAt(std::function<float (double, double)> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1} const&):
✓ Branch 0 taken 795 times.
✓ Branch 1 taken 1165 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(double, double)#1}, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(float)#1} const&):
✓ Branch 0 taken 34256 times.
✓ Branch 1 taken 4481387 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(double, double)#1}, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1} const&):
✓ Branch 0 taken 4640 times.
✓ Branch 1 taken 216354 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(double, double)#1}, terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(float)#1} const&):
✓ Branch 0 taken 574348 times.
✓ Branch 1 taken 8325808 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::detail::SeamField::At(double, double) const::{lambda(double, double)#1}, terraingen::detail::SeamField::At(double, double) const::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::detail::SeamField::At(double, double) const::{lambda(double, double)#1} const&, terraingen::detail::SeamField::At(double, double) const::{lambda(float)#1} const&):
✓ Branch 0 taken 19713 times.
✓ Branch 1 taken 1038425 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(double, double)#1}, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(double, double)#1} const&, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(float)#1} const&):
✓ Branch 0 taken 133430 times.
✓ Branch 1 taken 1310360 times.
20543705 const double wx = wxs[static_cast<std::size_t>(i + radius - 1)];
41
14/14
std::optional<double> terraingen::InterpolateLatticeWeights<terraingen::(anonymous namespace)::Refinement::Interpolate(terraingen::(anonymous namespace)::NodeFrame const&, terraingen::detail::LatticeWindow<double> const&, int, double, double) const::{lambda(double, double)#1}, terraingen::(anonymous namespace)::Refinement::Interpolate(terraingen::(anonymous namespace)::NodeFrame const&, terraingen::detail::LatticeWindow<double> const&, int, double, double) const::{lambda(double)#1}, double>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::(anonymous namespace)::Refinement::Interpolate(terraingen::(anonymous namespace)::NodeFrame const&, terraingen::detail::LatticeWindow<double> const&, int, double, double) const::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::Refinement::Interpolate(terraingen::(anonymous namespace)::NodeFrame const&, terraingen::detail::LatticeWindow<double> const&, int, double, double) const::{lambda(double)#1} const&):
✓ Branch 0 taken 1030509 times.
✓ Branch 1 taken 3372515 times.
std::optional<float> terraingen::InterpolateLatticeWeights<std::function<float (double, double)>, (anonymous namespace)::InterpolateAt(std::function<float (double, double)> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, std::function<float (double, double)> const&, (anonymous namespace)::InterpolateAt(std::function<float (double, double)> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1} const&):
✓ Branch 0 taken 795 times.
✓ Branch 1 taken 1165 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(double, double)#1}, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(float)#1} const&):
✓ Branch 0 taken 34256 times.
✓ Branch 1 taken 4481387 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(double, double)#1}, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1} const&):
✓ Branch 0 taken 4640 times.
✓ Branch 1 taken 216354 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(double, double)#1}, terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(float)#1} const&):
✓ Branch 0 taken 574348 times.
✓ Branch 1 taken 8325808 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::detail::SeamField::At(double, double) const::{lambda(double, double)#1}, terraingen::detail::SeamField::At(double, double) const::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::detail::SeamField::At(double, double) const::{lambda(double, double)#1} const&, terraingen::detail::SeamField::At(double, double) const::{lambda(float)#1} const&):
✓ Branch 0 taken 19713 times.
✓ Branch 1 taken 1038425 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(double, double)#1}, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(double, double)#1} const&, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(float)#1} const&):
✓ Branch 0 taken 133430 times.
✓ Branch 1 taken 1310360 times.
20543705 if (wx * wy == 0.0) {
42 1797691 continue;
43 }
44
9/10
std::optional<float> terraingen::InterpolateLatticeWeights<std::function<float (double, double)>, (anonymous namespace)::InterpolateAt(std::function<float (double, double)> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, std::function<float (double, double)> const&, (anonymous namespace)::InterpolateAt(std::function<float (double, double)> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1} const&):
✗ Branch 1 not taken.
✓ Branch 2 taken 1165 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(double, double)#1}, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(float)#1} const&):
✓ Branch 1 taken 3251266 times.
✓ Branch 2 taken 1230277 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(double, double)#1}, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1} const&):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 216353 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(double, double)#1}, terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(float)#1} const&):
✓ Branch 0 taken 5619 times.
✓ Branch 1 taken 8320189 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(double, double)#1}, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(double, double)#1} const&, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(float)#1} const&):
✓ Branch 1 taken 248 times.
✓ Branch 2 taken 1310112 times.
18746014 const Result cell = value(u0 + i, v0 + j);
45
9/10
std::optional<float> terraingen::InterpolateLatticeWeights<std::function<float (double, double)>, (anonymous namespace)::InterpolateAt(std::function<float (double, double)> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, std::function<float (double, double)> const&, (anonymous namespace)::InterpolateAt(std::function<float (double, double)> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1} const&):
✗ Branch 0 not taken.
✓ Branch 1 taken 1165 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(double, double)#1}, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(float)#1} const&):
✓ Branch 0 taken 258 times.
✓ Branch 1 taken 3251008 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(double, double)#1}, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1} const&):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 216353 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(double, double)#1}, terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::InterpolateBlock(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, terraingen::Span<terraingen::Vec2d const>, terraingen::Span<float>)::{lambda(float)#1} const&):
✓ Branch 0 taken 5619 times.
✓ Branch 1 taken 8320189 times.
std::optional<float> terraingen::InterpolateLatticeWeights<terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(double, double)#1}, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(float)#1}, float>(double, double, std::array<double, 6ul> const&, std::array<double, 6ul> const&, int, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(double, double)#1} const&, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(float)#1} const&):
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 231 times.
11794841 if (missing(cell)) {
46 5895 return std::nullopt;
47 }
48 18740275 sum += wx * wy * static_cast<double>(cell);
49 }
50 }
51 1515855 return static_cast<Result>(sum);
52 }
53
54 /// Values on a lattice interpolated at lattice position (`u`, `v`), measured in cells from the
55 /// center of cell (0, 0), with `method`: cells are read as `value(col, row)` with whole `col`
56 /// and `row` as doubles, and taps of zero weight are skipped. Nothing where a tap with weight
57 /// holds a value that `missing(value)` says has no data.
58 /// @tparam Value Callable as `float(double col, double row)` or `double(double col, double row)`.
59 /// @tparam Missing Callable as `bool(float value)`, or of a double for double values.
60 template <typename Value, typename Missing,
61 typename Result = std::decay_t<std::invoke_result_t<const Value&, double, double>>>
62 675232 std::optional<Result> InterpolateLattice(double u, double v, ResampleMethod method,
63 const Value& value, const Missing& missing) {
64
6/8
std::optional<float> terraingen::InterpolateLattice<terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(double, double)#1}, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(float)#1}, float>(double, double, terraingen::ResampleMethod, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(float)#1} const&):
✓ Branch 0 taken 533 times.
✓ Branch 1 taken 472097 times.
std::optional<float> terraingen::InterpolateLattice<terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(double, double)#1}, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1}, float>(double, double, terraingen::ResampleMethod, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1} const&):
✓ Branch 0 taken 10422 times.
✓ Branch 1 taken 13409 times.
std::optional<float> terraingen::InterpolateLattice<terraingen::detail::SeamField::At(double, double) const::{lambda(double, double)#1}, terraingen::detail::SeamField::At(double, double) const::{lambda(float)#1}, float>(double, double, terraingen::ResampleMethod, terraingen::detail::SeamField::At(double, double) const::{lambda(double, double)#1} const&, terraingen::detail::SeamField::At(double, double) const::{lambda(float)#1} const&):
✗ Branch 0 not taken.
✓ Branch 1 taken 66371 times.
std::optional<float> terraingen::InterpolateLattice<terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(double, double)#1}, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(float)#1}, float>(double, double, terraingen::ResampleMethod, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(double, double)#1} const&, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(float)#1} const&):
✗ Branch 0 not taken.
✓ Branch 1 taken 72246 times.
675232 if (method == ResampleMethod::Nearest) {
65 11047 const Result nearest = value(std::round(u), std::round(v));
66
5/10
std::optional<float> terraingen::InterpolateLattice<terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(double, double)#1}, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(float)#1}, float>(double, double, terraingen::ResampleMethod, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::Interpolate(terraingen::Raster<float> const&, double, double, terraingen::ResampleMethod)::{lambda(float)#1} const&):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 532 times.
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
std::optional<float> terraingen::InterpolateLattice<terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(double, double)#1}, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1}, float>(double, double, terraingen::ResampleMethod, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(double, double)#1} const&, terraingen::(anonymous namespace)::Interpolate(terraingen::detail::LatticeWindow<float> const&, terraingen::ResampleMethod, double, double)::{lambda(float)#1} const&):
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 10398 times.
std::optional<float> terraingen::InterpolateLattice<terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(double, double)#1}, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(float)#1}, float>(double, double, terraingen::ResampleMethod, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(double, double)#1} const&, terraingen::testing::Resample(terraingen::Raster<float> const&, double, terraingen::ResampleMethod)::{lambda(float)#1} const&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11112 if (missing(nearest)) {
67 29 return std::nullopt;
68 }
69 11018 return nearest;
70 }
71 664185 const double u0 = std::floor(u);
72 664185 const double v0 = std::floor(v);
73 1328438 return InterpolateLatticeWeights(u0, v0, KernelWeights(method, u - u0),
74 856237 KernelWeights(method, v - v0), KernelRadius(method), value,
75 missing);
76 }
77
78 } // namespace terraingen
79