-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilding.cpp
152 lines (124 loc) · 3.1 KB
/
building.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*building.cpp*/
//
// A building in the Open Street Map.
//
// Aibaww
//
#include <iostream>
#include <string>
#include <utility>
#include <curl/curl.h>
#include "curl_util.h"
#include "busstop.h"
#include "busstops.h"
#include "building.h"
#include "footways.h"
#include "nodes.h"
#include "node.h"
using namespace std;
//
// constructor
//
Building::Building(long long id, string name, string streetAddr)
: ID(id), Name(name), StreetAddress(streetAddr)
{
//
// the proper technique is to use member initialization list above,
// in the same order as the data members are declared:
//
// this->ID = id;
// this->Name = name;
// this->StreetAddress = streetAddr;
// vector is default initialized by its constructor
}
//
// adds the given nodeid to the end of the vector.
//
void Building::add(long long nodeid)
{
this->NodeIDs.push_back(nodeid);
}
//
// prints information about this building.
//
void Building::print(Nodes& nodes, BusStops& busstops, CURL* curl)
{
cout << this->Name << endl;
cout << "Address: " << this->StreetAddress << endl;
cout << "Building ID: " << this->ID << endl;
cout << "# perimeter nodes: " << this->NodeIDs.size() << endl;
pair<double,double> location = this->getLocation(nodes);
cout << "Location: (" << location.first << ", " << location.second << ")" << endl;
//
// find closest busstops
//
busstops.getClosestBusStop(location, curl);
return;
//
// print all nodes of this building:
//
// cout << "Nodes: " << this->NodeIDs.size() << endl;
// for (long long nodeid : this->NodeIDs)
// {
// cout << " " << nodeid << ": ";
// double lat = 0.0;
// double lon = 0.0;
// bool entrance = false;
// bool found = nodes.find(nodeid, lat, lon, entrance);
// if (found) {
// cout << "(" << lat << ", " << lon << ")";
// if (entrance)
// cout << ", is entrance";
// cout << endl;
// }
// else {
// cout << "**NOT FOUND**" << endl;
// }
// }
}
//
// searches for a footway that intersects with this building.
//
void Building::findIntersectingFootway(Footways& footways)
{
set<long long> foundids;
for (long long nodeid : this->NodeIDs)
{
footways.searchFootways(nodeid, foundids);
}
cout << "Footways that intersect: " << foundids.size() << endl;
if (foundids.size() == 0)
{
cout << " None" << endl;
}
else
{
for (long long id : foundids)
{
cout << " Footway " << id << endl;
}
}
}
//
// gets the center (lat, lon) of the building based
// on the nodes that form the perimeter
//
pair<double, double> Building::getLocation(const Nodes& nodes)
{
double avglat = 0.0;
double avglon = 0.0;
for (long long nodeid : this->NodeIDs) // for each node of building
{
double lat = 0.0;
double lon = 0.0;
bool entrance = false;
bool found = nodes.find(nodeid, lat, lon, entrance); // search for node in all nodes
if (found) { // if found, add the lat and lon to the total
avglat += lat;
avglon += lon;
}
}
avglat /= this->NodeIDs.size();
avglon /= this->NodeIDs.size();
return make_pair(avglat, avglon);
}