kopia lustrzana https://gitlab.com/tomaszg/geostat
31 wiersze
849 B
C++
31 wiersze
849 B
C++
#include "cache.h"
|
|
|
|
#include <cmath>
|
|
const static int Earth_radius = 6378;
|
|
|
|
Position Cache::home;
|
|
|
|
static float degtorad(float x) {
|
|
return x * M_PI / 180;
|
|
}
|
|
void Cache::show() const {
|
|
std::cout << "Cache:\t" << code << ' ' << name << '\n';
|
|
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)));
|
|
};
|
|
|
|
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();
|
|
}
|