diff --git a/bindings/python/mapnik_envelope.cpp b/bindings/python/mapnik_envelope.cpp index 65ca1a69c..553abea6a 100644 --- a/bindings/python/mapnik_envelope.cpp +++ b/bindings/python/mapnik_envelope.cpp @@ -231,6 +231,7 @@ void export_envelope() .def(self * float()) // __mult__ .def(float() * self) .def(self / float()) // __div__ + .def("__getitem__",&box2d::operator[]) .def_pickle(envelope_pickle_suite()) ; } diff --git a/include/mapnik/box2d.hpp b/include/mapnik/box2d.hpp index 752f1dcd5..dc861a8bc 100644 --- a/include/mapnik/box2d.hpp +++ b/include/mapnik/box2d.hpp @@ -84,7 +84,8 @@ public: box2d_type& operator+=(box2d_type const& other); box2d_type& operator-=(box2d_type const& other); box2d_type& operator*=(T); - box2d_type& operator/=(T); + box2d_type& operator/=(T); + T operator[](int index) const; }; template diff --git a/src/box2d.cpp b/src/box2d.cpp index 221a65e90..88bb29c55 100644 --- a/src/box2d.cpp +++ b/src/box2d.cpp @@ -23,6 +23,9 @@ #include +// stl +#include + namespace mapnik { template @@ -339,6 +342,32 @@ box2d& box2d::operator/=(T t) maxy_ = c.y + sy; return *this; } + +template +T box2d::operator[] (int index) const +{ + switch(index) + { + case 0: + return minx_; + case 1: + return miny_; + case 2: + return maxx_; + case 3: + return maxy_; + case -4: + return minx_; + case -3: + return miny_; + case -2: + return maxx_; + case -1: + return maxy_; + default: + throw std::out_of_range("index out of range, max value is 3, min value is -4 "); + } +} template class box2d; template class box2d; diff --git a/tests/python_tests/object_test.py b/tests/python_tests/object_test.py index 752ac7d64..40a8f303c 100644 --- a/tests/python_tests/object_test.py +++ b/tests/python_tests/object_test.py @@ -482,7 +482,16 @@ def test_envelope_init(): eq_(e.maxx, 200) eq_(e.maxy, 200) - + + eq_(e[0],100) + eq_(e[1],100) + eq_(e[2],200) + eq_(e[3],200) + eq_(e[0],e[-4]) + eq_(e[1],e[-3]) + eq_(e[2],e[-2]) + eq_(e[3],e[-1]) + c = e.center() eq_(c.x, 150)