PGROUTING  2.5
node.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 FILE: node.cpp
4 
5 Copyright (c) 2015 pgRouting developers
6 Mail: project@pgrouting.org
7 
8 ------
9 
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 
24  ********************************************************************PGR-GNU*/
25 
26 #include "vrp/node.h"
27 
28 #include "cpp_common/pgr_assert.h"
29 
30 namespace pgrouting {
31 namespace vrp {
32 
33 std::ostream& operator << (std::ostream &log, const Node &node) {
34  node.print(log);
35  return log;
36 }
37 
38 void
39 Node::print(std::ostream& os) const {
40  os << id()
41 #ifndef NDEBUG
42  << "(" << idx() << ")"
43 #endif
44  << " (x,y) = (" << m_point.x() << ", " << m_point.y() << ")";
45 }
46 
47 double
48 Node::distance(const Node &other) const {
49  auto dx = m_point.x() - other.m_point.x();
50  auto dy = m_point.y() - other.m_point.y();
51  return sqrt(dx * dx + dy * dy);
52 }
53 
57 double
58 Node::distance(const Base_node *n) const {
59  return distance(*dynamic_cast<const Node*>(n));
60 }
61 
68 Node::Node(size_t _idx, int64_t _id, double _x, double _y)
69  : Base_node(_idx, _id),
70  m_point(_x, _y) {
71  }
72 
73 bool
74 Node::operator ==(const Node &rhs) const {
75  if (&rhs == this) return true;
76  return
77  (idx() == rhs.idx())
78  && (id() == rhs.id())
79  && (m_point == rhs.m_point);
80 }
81 
82 } // namespace vrp
83 } // namespace pgrouting
The Node class defines a point in 2D space with an id.
Definition: node.h:50
int64_t id() const
Definition: identifier.cpp:42
bool operator==(const Node &rhs) const
Definition: node.cpp:74
The Base_node class defines the operations that can be performed in a 2D node.
Definition: base_node.h:47
std::ostream & operator<<(std::ostream &log, const Base_node &node)
Definition: base_node.cpp:32
double distance(const Base_node *) const
Calculates distance between two Node.
Definition: node.cpp:58
pgrouting::Point m_point
Definition: node.h:71
Book keeping class for swapping orders between vehicles.
Definition: basic_edge.cpp:28
Assertions Handling.
void print(std::ostream &os) const
Definition: node.cpp:39
size_t idx() const
Definition: identifier.cpp:37