Quetzal-CoaTL
The Coalescence Template Library
Loading...
Searching...
No Matches
neighbors.hpp
1// Copyright 2021 Arnaud Becheler <abechele@umich.edu>
2
3/*********************************************************************** * This program is free software; you can
4 *redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free
5 *Software Foundation; either version 2 of the License, or * (at your option) any later version. *
6 * *
7 ***************************************************************************/
8
9#ifndef __NEIGHBORS_H_INCLUDED__
10#define __NEIGHBORS_H_INCLUDED__
11
12#include "../geography/GeographicCoordinates.hpp"
13
14namespace quetzal
15{
16namespace utils
17{
18
19// used in dispersal kernel definition
20template <typename T> auto make_neighboring_cells_functor(T const &landscape)
21{
22
23 using coord_type = quetzal::geography::GeographicCoordinates;
24 return [landscape](coord_type const &x0) {
25 auto res = landscape.get().resolution();
26
27 std::vector<coord_type> v;
28
29 coord_type x1(x0);
30 x1.lon() += res.lon();
31 if (landscape.get().is_in_spatial_extent(x1))
32 {
33 v.push_back(landscape.get().reproject_to_centroid(x1));
34 }
35
36 coord_type x2(x0);
37 x2.lat() += res.lat();
38 if (landscape.get().is_in_spatial_extent(x2))
39 {
40 v.push_back(landscape.get().reproject_to_centroid(x2));
41 }
42
43 coord_type x3(x0);
44 x3.lon() -= res.lon();
45 if (landscape.get().is_in_spatial_extent(x3))
46 {
47 v.push_back(landscape.get().reproject_to_centroid(x3));
48 }
49
50 coord_type x4(x0);
51 x4.lat() -= res.lat();
52 if (landscape.get().is_in_spatial_extent(x4))
53 {
54 v.push_back(landscape.get().reproject_to_centroid(x4));
55 }
56 return v;
57 };
58};
59} // namespace utils
60} // namespace quetzal
61#endif
Simulation of coalescence-based models of molecular evolution.
Definition coalescence.hpp:21