Osmium  0.1
include/osmium/osm/bounds.hpp
Go to the documentation of this file.
00001 #ifndef OSMIUM_OSM_BOUNDS_HPP
00002 #define OSMIUM_OSM_BOUNDS_HPP
00003 
00004 /*
00005 
00006 Copyright 2011 Jochen Topf <jochen@topf.org> and others (see README).
00007 
00008 This file is part of Osmium (https://github.com/joto/osmium).
00009 
00010 Osmium is free software: you can redistribute it and/or modify it under the
00011 terms of the GNU Lesser General Public License or (at your option) the GNU
00012 General Public License as published by the Free Software Foundation, either
00013 version 3 of the Licenses, or (at your option) any later version.
00014 
00015 Osmium is distributed in the hope that it will be useful, but WITHOUT ANY
00016 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
00017 PARTICULAR PURPOSE. See the GNU Lesser General Public License and the GNU
00018 General Public License for more details.
00019 
00020 You should have received a copy of the Licenses along with Osmium. If not, see
00021 <http://www.gnu.org/licenses/>.
00022 
00023 */
00024 
00025 #include <limits>
00026 
00027 #include <osmium/osm/position.hpp>
00028 
00029 namespace Osmium {
00030 
00031     namespace OSM {
00032 
00033         class Bounds {
00034 
00035         public:
00036 
00037             Bounds()
00038                 : m_min_x(std::numeric_limits<int32_t>::max()),
00039                   m_max_x(std::numeric_limits<int32_t>::min()),
00040                   m_min_y(std::numeric_limits<int32_t>::max()),
00041                   m_max_y(std::numeric_limits<int32_t>::min()) {
00042             }
00043 
00044             Bounds& extend(const Position& position) {
00045                 if (position.x() < m_min_x) m_min_x = position.x();
00046                 if (position.x() > m_max_x) m_max_x = position.x();
00047                 if (position.y() < m_min_y) m_min_y = position.y();
00048                 if (position.y() > m_max_y) m_max_y = position.y();
00049                 return *this;
00050             }
00051 
00052             bool defined() const {
00053                 return m_min_x != std::numeric_limits<int32_t>::max();
00054             }
00055 
00059             Position bl() const {
00060                 return Position(m_min_x, m_min_y);
00061             }
00062 
00066             Position tr() const {
00067                 return Position(m_max_x, m_max_y);
00068             }
00069 
00070             friend std::ostream& operator<<(std::ostream& out, const Bounds& bounds) {
00071                 out << '(' << bounds.bl().lon() << ',' << bounds.bl().lat() << ','
00072                     << bounds.tr().lon() << ',' << bounds.tr().lat() << ')';
00073                 return out;
00074             }
00075 
00076         private:
00077 
00078             int32_t m_min_x;
00079             int32_t m_max_x;
00080             int32_t m_min_y;
00081             int32_t m_max_y;
00082 
00083         }; // class Bounds
00084 
00085     } // namespace OSM
00086 
00087 } // namespace Osmium
00088 
00089 #endif // OSMIUM_OSM_BOUNDS_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines