Commit 5d64de24 authored by mchelem's avatar mchelem Committed by Davis E. King

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)
parent 22402e99
...@@ -432,7 +432,7 @@ void bind_vector(py::module& m) ...@@ -432,7 +432,7 @@ void bind_vector(py::module& m)
.def(double() * py::self) .def(double() * py::self)
.def("normalize", &type::normalize, "Returns a unit normalized copy of this vector.") .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("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<type>, &setstate<type>)); .def(py::pickle(&getstate<type>, &setstate<type>));
} }
{ {
......
...@@ -16,6 +16,14 @@ def test_point(): ...@@ -16,6 +16,14 @@ def test_point():
assert deser.x == p.x assert deser.x == p.x
assert deser.y == p.y 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(): def test_point_init_kwargs():
p = point(y=27, x=42) p = point(y=27, x=42)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment