[core] Added MetersBounds

This commit is contained in:
Bruno de Oliveira Abinader
2015-11-11 16:48:58 +02:00
parent cd0266f25c
commit aa8857643d
4 changed files with 24 additions and 22 deletions

View File

@@ -135,8 +135,8 @@ public:
uint16_t getHeight() const;
// Projection
void getWorldBoundsMeters(ProjectedMeters& sw, ProjectedMeters& ne) const;
void getWorldBoundsLatLng(LatLng& sw, LatLng& ne) const;
MetersBounds getWorldBoundsMeters() const;
LatLngBounds getWorldBoundsLatLng() const;
double getMetersPerPixelAtLatitude(double lat, double zoom) const;
ProjectedMeters projectedMetersForLatLng(const LatLng&) const;

View File

@@ -54,7 +54,7 @@ struct LatLngBounds {
LatLng sw = {90, 180};
LatLng ne = {-90, -180};
inline LatLngBounds(LatLng sw_ = {90, 180}, LatLng ne_ = {-90, -180})
inline LatLngBounds(const LatLng& sw_ = {90, 180}, const LatLng& ne_ = {-90, -180})
: sw(sw_), ne(ne_) {}
inline bool isValid() const {
@@ -91,6 +91,18 @@ struct LatLngBounds {
}
};
struct MetersBounds {
ProjectedMeters sw;
ProjectedMeters ne;
inline MetersBounds(const ProjectedMeters& sw_, const ProjectedMeters& ne_)
: sw(sw_), ne(ne_) {}
inline bool isValid() const {
return sw.isValid() && ne.isValid();
}
};
}
#endif

View File

@@ -11,24 +11,14 @@ namespace mbgl {
class Projection {
public:
static inline void getWorldBoundsMeters(ProjectedMeters &sw, ProjectedMeters &ne) {
static inline MetersBounds getWorldBoundsMeters() {
const double d = util::EARTH_RADIUS_M * M_PI;
sw.easting = -d;
sw.northing = -d;
ne.easting = d;
ne.northing = d;
return { { -d, -d }, { d, d } };
}
static inline void getWorldBoundsLatLng(LatLng &sw, LatLng &ne) {
ProjectedMeters projectedMetersSW = ProjectedMeters();
ProjectedMeters projectedMetersNE = ProjectedMeters();
getWorldBoundsMeters(projectedMetersSW, projectedMetersNE);
sw = latLngForProjectedMeters(projectedMetersSW);
ne = latLngForProjectedMeters(projectedMetersNE);
static inline LatLngBounds getWorldBoundsLatLng() {
MetersBounds bounds = getWorldBoundsMeters();
return { latLngForProjectedMeters(bounds.sw), latLngForProjectedMeters(bounds.ne) };
}
static inline double getMetersPerPixelAtLatitude(const double lat, const double zoom) {

View File

@@ -335,12 +335,12 @@ double Map::getPitch() const {
#pragma mark - Projection
void Map::getWorldBoundsMeters(ProjectedMeters& sw, ProjectedMeters& ne) const {
Projection::getWorldBoundsMeters(sw, ne);
MetersBounds Map::getWorldBoundsMeters() const {
return Projection::getWorldBoundsMeters();
}
void Map::getWorldBoundsLatLng(LatLng& sw, LatLng& ne) const {
Projection::getWorldBoundsLatLng(sw, ne);
LatLngBounds Map::getWorldBoundsLatLng() const {
return Projection::getWorldBoundsLatLng();
}
double Map::getMetersPerPixelAtLatitude(double lat, double zoom) const {