2019-09-08 16:42:10 +00:00
|
|
|
#include "cache.h"
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
const static int Earth_radius = 6378;
|
|
|
|
|
|
|
|
Position Cache::home;
|
|
|
|
|
|
|
|
static float degtorad(float x) {
|
|
|
|
return x * M_PI / 180;
|
|
|
|
}
|
2019-09-10 12:03:01 +00:00
|
|
|
|
2019-09-08 16:42:10 +00:00
|
|
|
void Cache::show() const {
|
2019-09-11 17:48:03 +00:00
|
|
|
std::cout << "Cache:\t" << code << ' ' << name << " (type: " << type << ", owned by " << owner << ")\n";
|
2019-09-08 16:42:10 +00:00
|
|
|
std::cout << '\t' << pos.lat << " " << pos.lon << "\t\t D/T: " << diff << '/' << terr << '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
float Cache::distance() const {
|
|
|
|
return 2 * Earth_radius * asin(sqrt(pow(sin(degtorad((pos.lat - home.lat) / 2)), 2) + cos(degtorad(pos.lat)) * cos(degtorad(home.lat)) * pow(sin(degtorad((pos.lon - home.lon) / 2)), 2)));
|
2019-09-10 12:03:01 +00:00
|
|
|
}
|
2019-09-08 16:42:10 +00:00
|
|
|
|
|
|
|
bool CacheCmpNS(const Cache& lhs, const Cache& rhs) {
|
|
|
|
return lhs.pos.lat < rhs.pos.lat;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CacheCmpEW(const Cache& lhs, const Cache& rhs) {
|
|
|
|
return lhs.pos.lon < rhs.pos.lon;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CacheCmpDist(const Cache& lhs, const Cache& rhs) {
|
|
|
|
return lhs.distance() < rhs.distance();
|
|
|
|
}
|