Stride Reference Manual  - generated for commit 9643b11
KdTree2DPoint.h
Go to the documentation of this file.
1 /*
2  * This is free software: you can redistribute it and/or modify it
3  * under the terms of the GNU General Public License as published by
4  * the Free Software Foundation, either version 3 of the License, or
5  * any later version.
6  * The software is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  * You should have received a copy of the GNU General Public License
11  * along with the software. If not, see <http://www.gnu.org/licenses/>.
12  *
13  * Copyright 2018, 2019, Jan Broeckhove and Bistromatics group.
14  */
15 
16 #pragma once
17 
18 #include "AABBox.h"
19 #include "geopop/Coordinate.h"
20 
21 #include <boost/geometry/core/access.hpp>
22 #include <memory>
23 
24 namespace geopop {
25 
26 class Location;
27 
28 namespace geogrid_detail {
29 
32 {
33 public:
35  constexpr static std::size_t dim = 2;
36 
38  template <std::size_t D>
40  {
41  using type = double;
42  };
43 
44 public:
46  KdTree2DPoint() : m_pt(), m_location(nullptr){};
47 
49  explicit KdTree2DPoint(const Location* loc);
50 
52  KdTree2DPoint(double longt, double lat) : m_pt(longt, lat), m_location(nullptr) {}
53 
55  bool operator==(const KdTree2DPoint& other) const;
56 
58  double Distance(const KdTree2DPoint& other) const;
59 
61  template <std::size_t D>
62  double Get() const
63  {
64  static_assert(0 <= D && D <= 1, "Dimension should be in range");
65  return boost::geometry::get<D>(m_pt);
66  }
67 
69  const Location* GetLocation() const { return m_location; }
70 
72  Coordinate GetPoint() const { return m_pt; }
73 
75  bool InBox(const AABBox<KdTree2DPoint>& box) const;
76 
78  bool InRadius(const KdTree2DPoint& start, double radius) const;
79 
80 private:
83 };
84 
85 } // namespace geogrid_detail
86 } // namespace geopop
AxisAlignedBoundingBox (hyperrectangle defined by lower and upper bound for every dimension)...
Definition: AABBox.h:24
bool InRadius(const KdTree2DPoint &start, double radius) const
Does the point lie within radius km from start?
const Location * GetLocation() const
Retrieve the location.
Definition: KdTree2DPoint.h:69
Coordinate GetPoint() const
Get the coordinate for this Location.
Definition: KdTree2DPoint.h:72
KdTree2DPoint()
Default constructor.
Definition: KdTree2DPoint.h:46
bool InBox(const AABBox< KdTree2DPoint > &box) const
Namespace for the geographic and demograhic classes.
Definition: Coordinate.h:21
static constexpr std::size_t dim
Definition: KdTree2DPoint.h:35
KdTree for some more information on methods.
Definition: KdTree2DPoint.h:31
boost::geometry::model::point< double, 2, boost::geometry::cs::geographic< boost::geometry::degree >> Coordinate
Definition: Coordinate.h:23
double Distance(const KdTree2DPoint &other) const
Distance in kilometers, following great circle distance on a speroid earth.
bool operator==(const KdTree2DPoint &other) const
Equal if within one meter of one another.
const Location * m_location
The underlying location.
Definition: KdTree2DPoint.h:82
Coordinate m_pt
Shortcut for access without dereferencing.
Definition: KdTree2DPoint.h:81
Location for use within the GeoGrid, contains Coordinate and index to ContactPools.
Definition: Location.h:41
KdTree2DPoint(double longt, double lat)
Constructor with longitude and latitude.
Definition: KdTree2DPoint.h:52