From 22fc14ef0513db9e5b7000e932bbdb7dd4f26d31 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Thu, 19 Aug 2010 21:35:27 +0000 Subject: [PATCH] + ability to pass coord2d to box2d::re_center in core and python --- bindings/python/mapnik_envelope.cpp | 53 ++++++++++++++++++++--------- include/mapnik/box2d.hpp | 1 + src/box2d.cpp | 10 ++++++ 3 files changed, 47 insertions(+), 17 deletions(-) diff --git a/bindings/python/mapnik_envelope.cpp b/bindings/python/mapnik_envelope.cpp index c6703013d..65ca1a69c 100644 --- a/bindings/python/mapnik_envelope.cpp +++ b/bindings/python/mapnik_envelope.cpp @@ -63,6 +63,10 @@ bool (box2d::*intersects_p3)(box2d const&) const = &box2d (box2d::*intersect)(box2d const&) const = &box2d::intersect; +// re_center +void (box2d::*re_center_p1)(double,double) = &box2d::re_center; +void (box2d::*re_center_p2)(coord const& ) = &box2d::re_center; + void export_envelope() { using namespace boost::python; @@ -72,10 +76,10 @@ void export_envelope() (arg("minx"),arg("miny"),arg("maxx"),arg("maxy")), "Constructs a new envelope from the coordinates\n" "of its lower left and upper right corner points.\n")) - .def(init<>("Equivalent to box2d(0, 0, -1, -1).\n")) + .def(init<>("Equivalent to Box2d(0, 0, -1, -1).\n")) .def(init&, const coord&>( (arg("ll"),arg("ur")), - "Equivalent to box2d(ll.x, ll.y, ur.x, ur.y).\n")) + "Equivalent to Box2d(ll.x, ll.y, ur.x, ur.y).\n")) .add_property("minx", &box2d::minx, "X coordinate for the lower left corner") .add_property("miny", &box2d::miny, @@ -88,35 +92,50 @@ void export_envelope() "Returns the coordinates of the center of the bounding box.\n" "\n" "Example:\n" - ">>> e = box2d(0, 0, 100, 100)\n" + ">>> e = Box2d(0, 0, 100, 100)\n" ">>> e.center()\n" "Coord(50, 50)\n") - .def("center", &box2d::re_center, + .def("center", re_center_p1, (arg("x"), arg("y")), "Moves the envelope so that the given coordinates become its new center.\n" "The width and the height are preserved.\n" "\n " "Example:\n" - ">>> e = box2d(0, 0, 100, 100)\n" + ">>> e = Box2d(0, 0, 100, 100)\n" ">>> e.center(60, 60)\n" ">>> e.center()\n" "Coord(60.0,60.0)\n" ">>> (e.width(), e.height())\n" "(100.0, 100.0)\n" ">>> e\n" - "box2d(10.0, 10.0, 110.0, 110.0)\n" + "Box2d(10.0, 10.0, 110.0, 110.0)\n" + ) + .def("center", re_center_p2, + (arg("Coord")), + "Moves the envelope so that the given coordinates become its new center.\n" + "The width and the height are preserved.\n" + "\n " + "Example:\n" + ">>> e = Box2d(0, 0, 100, 100)\n" + ">>> e.center(Coord60, 60)\n" + ">>> e.center()\n" + "Coord(60.0,60.0)\n" + ">>> (e.width(), e.height())\n" + "(100.0, 100.0)\n" + ">>> e\n" + "Box2d(10.0, 10.0, 110.0, 110.0)\n" ) .def("width", width_p1, (arg("new_width")), "Sets the width to new_width of the envelope preserving its center.\n" "\n " "Example:\n" - ">>> e = box2d(0, 0, 100, 100)\n" + ">>> e = Box2d(0, 0, 100, 100)\n" ">>> e.width(120)\n" ">>> e.center()\n" "Coord(50.0,50.0)\n" ">>> e\n" - "box2d(-10.0, 0.0, 110.0, 100.0)\n" + "Box2d(-10.0, 0.0, 110.0, 100.0)\n" ) .def("width", width_p2, "Returns the width of this envelope.\n" @@ -126,12 +145,12 @@ void export_envelope() "Sets the height to new_height of the envelope preserving its center.\n" "\n " "Example:\n" - ">>> e = box2d(0, 0, 100, 100)\n" + ">>> e = Box2d(0, 0, 100, 100)\n" ">>> e.height(120)\n" ">>> e.center()\n" "Coord(50.0,50.0)\n" ">>> e\n" - "box2d(0.0, -10.0, 100.0, 110.0)\n" + "Box2d(0.0, -10.0, 100.0, 110.0)\n" ) .def("height", height_p2, "Returns the height of this envelope.\n" @@ -141,10 +160,10 @@ void export_envelope() "Expands this envelope to include the point given by x and y.\n" "\n" "Example:\n", - ">>> e = box2d(0, 0, 100, 100)\n" + ">>> e = Box2d(0, 0, 100, 100)\n" ">>> e.expand_to_include(110, 110)\n" ">>> e\n" - "box2d(0.0, 00.0, 110.0, 110.0)\n" + "Box2d(0.0, 00.0, 110.0, 110.0)\n" ) .def("expand_to_include",expand_to_include_p2, (arg("p")), @@ -188,8 +207,8 @@ void export_envelope() "This relationship is symmetric." "\n" "Example:\n" - ">>> e1 = box2d(0, 0, 100, 100)\n" - ">>> e2 = box2d(50, 50, 150, 150)\n" + ">>> e1 = Box2d(0, 0, 100, 100)\n" + ">>> e2 = Box2d(50, 50, 150, 150)\n" ">>> e1.intersects(e2)\n" "True\n" ">>> e1.contains(e2)\n" @@ -201,10 +220,10 @@ void export_envelope() "as a new envelope.\n" "\n" "Example:\n" - ">>> e1 = box2d(0, 0, 100, 100)\n" - ">>> e2 = box2d(50, 50, 150, 150)\n" + ">>> e1 = Box2d(0, 0, 100, 100)\n" + ">>> e2 = Box2d(50, 50, 150, 150)\n" ">>> e1.intersect(e2)\n" - "box2d(50.0, 50.0, 100.0, 100.0)\n" + "Box2d(50.0, 50.0, 100.0, 100.0)\n" ) .def(self == self) // __eq__ .def(self + self) // __add__ diff --git a/include/mapnik/box2d.hpp b/include/mapnik/box2d.hpp index bbe0ebe31..752f1dcd5 100644 --- a/include/mapnik/box2d.hpp +++ b/include/mapnik/box2d.hpp @@ -77,6 +77,7 @@ public: box2d_type intersect(const box2d_type& other) const; bool operator==(const box2d_type &other) const; void re_center(T cx,T cy); + void re_center(const coord& c); void init(T x0,T y0,T x1,T y1); // define some operators diff --git a/src/box2d.cpp b/src/box2d.cpp index ef08321ad..221a65e90 100644 --- a/src/box2d.cpp +++ b/src/box2d.cpp @@ -266,6 +266,16 @@ void box2d::re_center(T cx,T cy) maxy_+=dy; } +template +#if !defined(__SUNPRO_CC) +inline +#endif +void box2d::re_center(const coord &c) +{ + re_center(c.x,c.y); +} + + template #if !defined(__SUNPRO_CC) inline