From 5d64de24b33a292937ddb53486b3f96a0e69d986 Mon Sep 17 00:00:00 2001 From: mchelem Date: Sat, 8 Jun 2019 07:08:45 -0300 Subject: [PATCH] Fix setting a point's y coordinate changes x instead (Python bindings) (#1795) * Add point assignment test * Fix setting points y coordinate changes x instead (issue #1794) --- tools/python/src/vector.cpp | 2 +- tools/python/test/test_point.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/python/src/vector.cpp b/tools/python/src/vector.cpp index ff6f8bc58..4457165ac 100644 --- a/tools/python/src/vector.cpp +++ b/tools/python/src/vector.cpp @@ -432,7 +432,7 @@ void bind_vector(py::module& m) .def(double() * py::self) .def("normalize", &type::normalize, "Returns a unit normalized copy of this vector.") .def_property("x", &point_x, [](point& p, long x){p.x()=x;}, "The x-coordinate of the point.") - .def_property("y", &point_y, [](point& p, long y){p.x()=y;}, "The y-coordinate of the point.") + .def_property("y", &point_y, [](point& p, long y){p.y()=y;}, "The y-coordinate of the point.") .def(py::pickle(&getstate, &setstate)); } { diff --git a/tools/python/test/test_point.py b/tools/python/test/test_point.py index 75b8c191f..feebba28c 100644 --- a/tools/python/test/test_point.py +++ b/tools/python/test/test_point.py @@ -16,6 +16,14 @@ def test_point(): assert deser.x == p.x assert deser.y == p.y +def test_point_assignment(): + p = point(27, 42) + p.x = 16 + assert p.x == 16 + assert p.y == 42 + p.y = 31 + assert p.x == 16 + assert p.y == 31 def test_point_init_kwargs(): p = point(y=27, x=42)