GEOS  3.13.0dev
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 #include <utility>
19 
20 namespace geos {
21 namespace index {
22 namespace strtree {
23 
24 template<typename ItemType, typename BoundsTraits, typename ItemDistance>
25 class TemplateSTRNodePair {
26 public:
27  using Node = TemplateSTRNode<ItemType, BoundsTraits>;
28 
29  TemplateSTRNodePair(const Node &node1, const Node &node2, ItemDistance& id)
30  : m_node1(&node1), m_node2(&node2), m_distance(distance(id)) {}
31 
32  bool isLeaves() const {
33  return getFirst().isLeaf() && getSecond().isLeaf();
34  }
35 
36  double getDistance() const {
37  return m_distance;
38  }
39 
40  std::pair<ItemType, ItemType> getItems() const {
41  assert(isLeaves());
42  return std::make_pair(getFirst().getItem(), getSecond().getItem());
43  }
44 
45  const Node &getFirst() const {
46  return *m_node1;
47  }
48 
49  const Node &getSecond() const {
50  return *m_node2;
51  }
52 
53  double distance(ItemDistance& id) {
54  if (isLeaves()) {
55  return id(getFirst().getItem(), getSecond().getItem());
56  } else {
57  return BoundsTraits::distance(getFirst().getBounds(), getSecond().getBounds());
58  }
59  }
60 
61  double maximumDistance() {
62  return BoundsTraits::maxDistance(getFirst().getBounds(), getSecond().getBounds());
63  }
64 
65 private:
66  const Node* m_node1;
67  const Node* m_node2;
68  double m_distance;
69 };
70 
71 }
72 }
73 }
74 
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25