00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef ENVELOPE_HPP
00026 #define ENVELOPE_HPP
00027
00028
00029 #include <mapnik/config.hpp>
00030 #include <mapnik/coord.hpp>
00031
00032 #include <boost/operators.hpp>
00033
00034 #include <iomanip>
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
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