edge.cpp
Go to the documentation of this file.
1 #include "lib/spanning_tree.h"
2 
3 edge::edge (int f, int t, int c, bool v) : from(f), to(t), cost(c), vertical(v)
4 {
5 }
6 
7 bool edge::operator== (const edge &e) const
8 {
9  return from == e.from && to == e.to && cost == e.cost;
10 }
11 
12 bool compare_edge::operator() (const edge& a, const edge& b) const
13 {
14  if (a.cost == b.cost) {
15  // third, edges on the top/right
16  if (abs(a.to - a.from) == abs(b.to - b.from))
17  return a.from < b.from;
18 
19  // second, horizontal/vertical edges
20  else {
21  if (a.vertical)
22  return abs(a.to - a.from) <= abs(b.to - b.from);
23  else
24  return abs(a.to - a.from) > abs(b.to - b.from);
25  }
26  }
27 
28  // first, edges with lowest cost
29  else
30  return a.cost < b.cost;
31 }
32 
33 size_t hash_edge::operator() (const edge& e) const
34 {
35  return hash<string>()(to_string(e.cost) + to_string(e.from) + to_string(e.to));
36 }
bool operator==(const edge &e) const
Compare this edge to another one.
Definition: edge.cpp:7
size_t operator()(const edge &e) const
Generate the hash of an edge.
Definition: edge.cpp:33
edge(int f, int t, int c, bool v=false)
Constructor that initializes the private member variables.
Definition: edge.cpp:3
int cost
The cost of the edge, i.e., length.
Definition: edge.h:41
int to
The ending vertex of the edge.
Definition: edge.h:36
A class for representing edges.
Definition: edge.h:9
bool vertical
Whether the sweeping pattern is vertical or horizontal.
Definition: coverage_path.h:95
int from
The starting vertex of the edge.
Definition: edge.h:31
bool vertical
Whether the sweeping pattern is vertical or horizontal.
Definition: edge.h:46
bool operator()(const edge &a, const edge &b) const
Compare two edge objects. Edges are compared in terms of cost, orientation, and the position...
Definition: edge.cpp:12


coverage_path
Author(s): Micha Sende
autogenerated on Tue Jan 19 2021 03:30:03