Stride Reference Manual  - generated for commit 9643b11
KdTree2DPoint.cpp
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 #include "KdTree2DPoint.h"
17 
18 #include "geopop/Location.h"
19 
20 #include <boost/geometry/algorithms/distance.hpp>
21 #include <boost/geometry/algorithms/within.hpp>
22 #include <boost/geometry/core/access.hpp>
23 #include <boost/geometry/geometries/box.hpp>
24 #include <boost/geometry/strategies/geographic/distance.hpp>
25 
26 namespace geopop {
27 
28 namespace geogrid_detail {
29 
30 KdTree2DPoint::KdTree2DPoint(const Location* loc) : m_pt(loc->GetCoordinate()), m_location(loc) {}
31 
32 bool KdTree2DPoint::operator==(const KdTree2DPoint& other) const { return Distance(other) < 0.001; }
33 
35 {
36  return boost::geometry::within(m_pt, boost::geometry::model::box<Coordinate>{box.lower.m_pt, box.upper.m_pt});
37 }
38 
39 bool KdTree2DPoint::InRadius(const KdTree2DPoint& start, double radius) const { return Distance(start) <= radius; }
40 
41 double KdTree2DPoint::Distance(const KdTree2DPoint& other) const
42 {
43  return boost::geometry::distance(m_pt, other.m_pt, boost::geometry::strategy::distance::geographic<>{}) /
44  1000.0;
45 }
46 
47 } // namespace geogrid_detail
48 } // 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?
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
P lower
The lower bound for every dimension.
Definition: AABBox.h:27
P upper
The upper bound for every dimension.
Definition: AABBox.h:29
KdTree for some more information on methods.
Definition: KdTree2DPoint.h:31
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.
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