/home/andreas/src/svn/mapnik/include/mapnik/envelope.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * 
00003  * This file is part of Mapnik (c++ mapping toolkit)
00004  *
00005  * Copyright (C) 2006 Artem Pavlenko
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020  *
00021  *****************************************************************************/
00022 
00023 //$Id: envelope.hpp 39 2005-04-10 20:39:53Z pavlenko $
00024 
00025 #ifndef ENVELOPE_HPP
00026 #define ENVELOPE_HPP
00027 
00028 // stl
00029 #include <iomanip>
00030 // boost
00031 #include <boost/operators.hpp>
00032 // mapnik
00033 #include <mapnik/config.hpp>
00034 #include <mapnik/coord.hpp>
00035 
00036 namespace mapnik {
00037         template <typename T> class MAPNIK_DECL Envelope 
00038     : boost::addable<Envelope<T>, 
00039       boost::subtractable<Envelope<T>, 
00040       boost::dividable2<Envelope<T>, T,
00041       boost::multipliable2<Envelope<T>, T > > > >
00042     {
00043     public:
00044         typedef Envelope<T> EnvelopeType;
00045     private:
00046         T minx_;
00047         T miny_;
00048         T maxx_;
00049         T maxy_;
00050     public:
00051         Envelope();
00052         Envelope(T minx,T miny,T maxx,T maxy);
00053         Envelope(const coord<T,2>& c0,const coord<T,2>& c1);
00054         Envelope(const EnvelopeType& rhs);
00055         T minx() const;
00056         T miny() const;
00057         T maxx() const;
00058         T maxy() const;
00059         T width() const;
00060         T height() const;
00061         void width(T w);
00062         void height(T h);
00063         coord<T,2> center() const;
00064         void expand_to_include(T x,T y);
00065         void expand_to_include(const coord<T,2>& c);
00066         void expand_to_include(const EnvelopeType& other);
00067         bool contains(const coord<T,2> &c) const;
00068         bool contains(T x,T y) const;
00069         bool contains(const EnvelopeType &other) const;
00070         bool intersects(const coord<T,2> &c) const;
00071         bool intersects(T x,T y) const;
00072         bool intersects(const EnvelopeType &other) const;
00073         EnvelopeType intersect(const EnvelopeType& other) const;
00074         bool operator==(const EnvelopeType &other) const;
00075         void re_center(T cx,T cy);
00076         void init(T x0,T y0,T x1,T y1);
00077         
00078         // define some operators 
00079         EnvelopeType& operator+=(EnvelopeType const& other);
00080         EnvelopeType& operator-=(EnvelopeType const& other);
00081         EnvelopeType& operator*=(T);
00082         EnvelopeType& operator/=(T);    
00083     };
00084     
00085     template <class charT,class traits,class T>
00086     inline std::basic_ostream<charT,traits>&
00087     operator << (std::basic_ostream<charT,traits>& out,
00088                  const Envelope<T>& e)
00089     {
00090         std::basic_ostringstream<charT,traits> s;
00091         s.copyfmt(out);
00092         s.width(0);
00093         s <<"Envelope(" << std::setprecision(16) 
00094           << e.minx() << "," << e.miny() <<"," 
00095           << e.maxx() << "," << e.maxy() <<")";
00096         out << s.str();
00097         return out;
00098     }
00099 }
00100 
00101 #endif // ENVELOPE_HPP

Generated on Thu Jul 19 17:59:25 2007 for Mapnik by  doxygen 1.4.7