GEOS  3.10.2
TemplateSTRNodePair.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2020-2021 Daniel Baston
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU Lesser General Public Licence as published
10  * by the Free Software Foundation.
11  * See the COPYING file for more information.
12  *
13  **********************************************************************/
14 
15 #pragma once
16 
17 #include <geos/index/strtree/TemplateSTRNode.h>
18 
19 namespace geos {
20 namespace index {
21 namespace strtree {
22 
23 template<typename ItemType, typename BoundsTraits, typename ItemDistance>
24 class TemplateSTRNodePair {
25 public:
26  using Node = TemplateSTRNode<ItemType, BoundsTraits>;
27 
28  TemplateSTRNodePair(const Node &node1, const Node &node2, ItemDistance& id)
29  : m_node1(&node1), m_node2(&node2), m_distance(distance(id)) {}
30 
31  bool isLeaves() const {
32  return getFirst().isLeaf() && getSecond().isLeaf();
33  }
34 
35  double getDistance() const {
36  return m_distance;
37  }
38 
39  std::pair<ItemType, ItemType> getItems() const {
40  assert(isLeaves());
41  return std::make_pair(getFirst().getItem(), getSecond().getItem());
42  }
43 
44  const Node &getFirst() const {
45  return *m_node1;
46  }
47 
48  const Node &getSecond() const {
49  return *m_node2;
50  }
51 
52  double distance(ItemDistance& id) {
53  if (isLeaves()) {
54  return id(getFirst().getItem(), getSecond().getItem());
55  } else {
56  return BoundsTraits::distance(getFirst().getBounds(), getSecond().getBounds());
57  }
58  }
59 
60 private:
61  const Node* m_node1;
62  const Node* m_node2;
63  double m_distance;
64 };
65 
66 }
67 }
68 }
69 
Basic namespace for all GEOS functionalities.
Definition: Angle.h:26