PGROUTING  2.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 "./node.h"
27 
28 namespace pgrouting {
29 namespace vrp {
30 
31 bool Node::isSamePos(const Node &other) const {
32  return comparable_distance(other) == 0;
33 }
34 
35 #if 0
36 double Node::travel_time_to(const Node &other) const {
37  return distance(other);
38 }
39 #endif
40 
41 std::ostream& operator << (std::ostream &log, const Node &node) {
42  log << node.m_original_id
43  << "(" << node.m_id << ")"
44  << "(" << node.m_point.x() << ", " << node.m_point.y() << ")";
45  return log;
46 }
47 
48 double
49 Node::distance(const Node &other) const {
50  auto dx = m_point.x() - other.m_point.x();
51  auto dy = m_point.y() - other.m_point.y();
52  return sqrt(dx * dx + dy * dy);
53 }
54 
55 double
56 Node::comparable_distance(const Node &other) const {
57  auto dx = m_point.x() - other.m_point.x();
58  auto dy = m_point.y() - other.m_point.y();
59  return dx * dx + dy * dy;
60 }
61 
62 
63 Node::Node(size_t id, int64_t original_id, double _x, double _y)
64  : m_point(_x, _y),
65  m_id(id),
66  m_original_id(original_id) {
67  }
68 
69 bool
70 Node::operator ==(const Node &rhs) const {
71  if (&rhs == this) return true;
72  return
73  (id() == rhs.id())
74  && (original_id() == rhs.original_id())
75  && (m_point == rhs.m_point);
76 }
77 
78 } // namespace vrp
79 } // namespace pgrouting
80 
81 
Node(size_t id, int64_t original_id, double _x, double _y)
Definition: node.cpp:63
double comparable_distance(const Node &other) const
Definition: node.cpp:56
size_t m_id
internal node number
Definition: node.h:75
The Node class defines a point in 2D space with an id.
Definition: node.h:46
bool operator==(const Node &rhs) const
Definition: node.cpp:70
int64_t original_id() const
Definition: node.h:52
double distance(const Node &other) const
Definition: node.cpp:49
int64_t m_original_id
Definition: node.h:76
PGDLLEXPORT Datum vrp(PG_FUNCTION_ARGS)
Definition: VRP.c:732
pgrouting::Point m_point
Definition: node.h:74
bool isSamePos(const Node &other) const
@ {
Definition: node.cpp:31
size_t id() const
@ {
Definition: node.h:51
std::ostream & operator<<(std::ostream &log, const Node &node)
Definition: node.cpp:41