From 6eea1ac720ec1d881be19698ec152f7ae5b128f5 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Tue, 17 Mar 2015 16:31:47 -0700 Subject: [PATCH] abstract out LatLngBounds::extend --- include/mbgl/util/geo.hpp | 7 +++++++ src/mbgl/map/annotation.cpp | 7 +------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/mbgl/util/geo.hpp b/include/mbgl/util/geo.hpp index b6eb602f1d7..b99a6e6614f 100644 --- a/include/mbgl/util/geo.hpp +++ b/include/mbgl/util/geo.hpp @@ -25,6 +25,13 @@ struct LatLngBounds { inline LatLngBounds(LatLng sw_ = {90, 180}, LatLng ne_ = {-90, -180}) : sw(sw_), ne(ne_) {} + + inline void extend(const LatLng& point) { + if (point.latitude < sw.latitude) sw.latitude = point.latitude; + if (point.latitude > ne.latitude) ne.latitude = point.latitude; + if (point.longitude < sw.longitude) sw.longitude = point.longitude; + if (point.longitude > ne.longitude) ne.longitude = point.longitude; + } }; } diff --git a/src/mbgl/map/annotation.cpp b/src/mbgl/map/annotation.cpp index 14db241c147..6235dab0035 100644 --- a/src/mbgl/map/annotation.cpp +++ b/src/mbgl/map/annotation.cpp @@ -12,16 +12,11 @@ Annotation::Annotation(AnnotationType type_, std::vector geom if (type == AnnotationType::Point) { bounds = LatLngBounds(getPoint(), getPoint()); } else { - LatLng sw, ne; for (auto segment : geometry) { for (auto point : segment) { - if (point.latitude < sw.latitude) sw.latitude = point.latitude; - if (point.latitude > ne.latitude) ne.latitude = point.latitude; - if (point.longitude < sw.longitude) sw.longitude = point.longitude; - if (point.longitude > ne.longitude) ne.longitude = point.longitude; + bounds.extend(point); } } - bounds = LatLngBounds(sw, ne); } }