./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
55 / 55
100.0%
Branches:
34 / 36
94.4%
Functions:
7 / 7, 1 excl
100.0%

src/layers/lattice.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief Jittered-lattice cell loops (`ForEachLatticeCell`) and their random streams.
5 #pragma once
6
7 #include "terraingen/geometry/cells.h"
8 #include "terraingen/geometry/geometry.h"
9 #include "terraingen/geometry/surface.h"
10 #include "terraingen/random/stream.h"
11
12 #include <cmath>
13 #include <cstdint>
14 #include <memory>
15
16 namespace terraingen {
17
18 /// The cells features are generated in on `surface` (`MakeCells`), made once per thread for the
19 /// surface it last asked for, so layers reading the surface from their context at each point
20 /// keep their cells and the areas they recall.
21 150286 inline std::shared_ptr<const SurfaceCells> ThreadCells(const Surface& surface) {
22
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 150266 times.
150286 thread_local Surface last{};
23
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 150266 times.
150286 thread_local std::shared_ptr<const SurfaceCells> cells = MakeCells(last);
24
2/2
✓ Branch 0 taken 12004 times.
✓ Branch 1 taken 138282 times.
150286 if (!(surface == last)) {
25
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12004 times.
24008 cells = MakeCells(surface);
26 12004 last = surface;
27 }
28
1/2
✓ Branch 0 taken 150286 times.
✗ Branch 1 not taken.
150286 return cells;
29 }
30
31 /// The random stream of lattice cell (`i`, `j`) under `seed` and `stream`, keyed by all 64 bits of
32 /// each index.
33 13708701 inline RandomStream LatticeStream(std::uint32_t seed, std::uint32_t stream, std::int64_t i,
34 std::int64_t j) {
35 13708701 return RandomStream(seed, stream, static_cast<std::uint32_t>(i), static_cast<std::uint32_t>(j),
36
2/2
<unknown function 33>:
✓ Branch 1 taken 79578 times.
terraingen::ThreadCells(terraingen::Surface const&):
✓ Branch 1 taken 1231154 times.
13708701 static_cast<std::uint32_t>((i >> 32) ^ ((j >> 32) << 16)));
37 }
38
39 /// Calls `visit(i, j)` for each cell within `rings` cells of the one holding `p`, on a lattice of
40 /// cells `cell.x` by `cell.y` across, row `j` by row with `i` ascending in each.
41 template <typename Visit>
42 710674 void ForEachLatticeCell(const Vec2d& p, const Vec2d& cell, std::int64_t rings, const Visit& visit) {
43 710674 const auto ci = static_cast<std::int64_t>(std::floor(p.x / cell.x));
44 710674 const auto cj = static_cast<std::int64_t>(std::floor(p.y / cell.y));
45
12/12
void terraingen::ForEachLatticeCell<ForEachLatticeCell_VisitsTheRingsRowByRow_Test::TestBody()::{lambda(long, long)#1}>(terraingen::Vec2d const&, terraingen::Vec2d const&, long, ForEachLatticeCell_VisitsTheRingsRowByRow_Test::TestBody()::{lambda(long, long)#1} const&):
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 time.
void terraingen::ForEachLatticeCell<ForEachLatticeCell_VisitsTheRingsRowByRow_Test::TestBody()::{lambda(long, long)#2}>(terraingen::Vec2d const&, terraingen::Vec2d const&, long, ForEachLatticeCell_VisitsTheRingsRowByRow_Test::TestBody()::{lambda(long, long)#2} const&):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
void terraingen::ForEachLatticeCell<terraingen::(anonymous namespace)::PlateSites(terraingen::Vec2d const&, double, double, double, double, unsigned int)::{lambda(long, long)#1}>(terraingen::Vec2d const&, terraingen::Vec2d const&, long, terraingen::(anonymous namespace)::PlateSites(terraingen::Vec2d const&, double, double, double, double, unsigned int)::{lambda(long, long)#1} const&):
✓ Branch 0 taken 351896 times.
✓ Branch 1 taken 70386 times.
void terraingen::ForEachLatticeCell<terraingen::DuneLayer::Barchans(terraingen::Vec2d const&) const::{lambda(long, long)#1}>(terraingen::Vec2d const&, terraingen::Vec2d const&, long, terraingen::DuneLayer::Barchans(terraingen::Vec2d const&) const::{lambda(long, long)#1} const&):
✓ Branch 0 taken 1616211 times.
✓ Branch 1 taken 538834 times.
void terraingen::ForEachLatticeCell<terraingen::DuneLayer::Forks(terraingen::Vec2d const&, double, double, double&) const::{lambda(long, long)#1}>(terraingen::Vec2d const&, terraingen::Vec2d const&, long, terraingen::DuneLayer::Forks(terraingen::Vec2d const&, double, double, double&) const::{lambda(long, long)#1} const&):
✓ Branch 0 taken 74077 times.
✓ Branch 1 taken 12397 times.
void terraingen::ForEachLatticeCell<terraingen::DuneLayer::Grainflows(terraingen::Vec2d const&, double) const::{lambda(long, long)#1}>(terraingen::Vec2d const&, terraingen::Vec2d const&, long, terraingen::DuneLayer::Grainflows(terraingen::Vec2d const&, double) const::{lambda(long, long)#1} const&):
✓ Branch 0 taken 267264 times.
✓ Branch 1 taken 89088 times.
3020159 for (std::int64_t j = cj - rings; j <= cj + rings; ++j) {
46
12/12
void terraingen::ForEachLatticeCell<ForEachLatticeCell_VisitsTheRingsRowByRow_Test::TestBody()::{lambda(long, long)#1}>(terraingen::Vec2d const&, terraingen::Vec2d const&, long, ForEachLatticeCell_VisitsTheRingsRowByRow_Test::TestBody()::{lambda(long, long)#1} const&):
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
void terraingen::ForEachLatticeCell<ForEachLatticeCell_VisitsTheRingsRowByRow_Test::TestBody()::{lambda(long, long)#2}>(terraingen::Vec2d const&, terraingen::Vec2d const&, long, ForEachLatticeCell_VisitsTheRingsRowByRow_Test::TestBody()::{lambda(long, long)#2} const&):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
void terraingen::ForEachLatticeCell<terraingen::(anonymous namespace)::PlateSites(terraingen::Vec2d const&, double, double, double, double, unsigned int)::{lambda(long, long)#1}>(terraingen::Vec2d const&, terraingen::Vec2d const&, long, terraingen::(anonymous namespace)::PlateSites(terraingen::Vec2d const&, double, double, double, double, unsigned int)::{lambda(long, long)#1} const&):
✓ Branch 0 taken 1758586 times.
✓ Branch 1 taken 351901 times.
void terraingen::ForEachLatticeCell<terraingen::DuneLayer::Barchans(terraingen::Vec2d const&) const::{lambda(long, long)#1}>(terraingen::Vec2d const&, terraingen::Vec2d const&, long, terraingen::DuneLayer::Barchans(terraingen::Vec2d const&) const::{lambda(long, long)#1} const&):
✓ Branch 0 taken 4846476 times.
✓ Branch 1 taken 1616238 times.
void terraingen::ForEachLatticeCell<terraingen::DuneLayer::Forks(terraingen::Vec2d const&, double, double, double&) const::{lambda(long, long)#1}>(terraingen::Vec2d const&, terraingen::Vec2d const&, long, terraingen::DuneLayer::Forks(terraingen::Vec2d const&, double, double, double&) const::{lambda(long, long)#1} const&):
✓ Branch 0 taken 454893 times.
✓ Branch 1 taken 74078 times.
void terraingen::ForEachLatticeCell<terraingen::DuneLayer::Grainflows(terraingen::Vec2d const&, double) const::{lambda(long, long)#1}>(terraingen::Vec2d const&, terraingen::Vec2d const&, long, terraingen::DuneLayer::Grainflows(terraingen::Vec2d const&, double) const::{lambda(long, long)#1} const&):
✓ Branch 0 taken 801792 times.
✓ Branch 1 taken 267264 times.
10171242 for (std::int64_t i = ci - rings; i <= ci + rings; ++i) {
47 7861757 visit(i, j);
48 }
49 }
50 710707 }
51
52 } // namespace terraingen
53