Skip to content

Commit

Permalink
Add some Eigen helpers for PolarTransform
Browse files Browse the repository at this point in the history
  • Loading branch information
QuLogic committed Dec 20, 2023
1 parent 9cc23b9 commit 194090f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/matplotlib/projections/polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,8 +1092,7 @@ def set_theta_offset(self, offset):
"""
Set the offset for the location of 0 in radians.
"""
mtx = self._theta_offset.get_matrix()
mtx[0, 2] = offset
self._theta_offset._mtx._set_translatex(offset)
self._theta_offset.invalidate()

def get_theta_offset(self):
Expand Down Expand Up @@ -1138,11 +1137,10 @@ def set_theta_direction(self, direction):
counterclockwise, anticlockwise, 1:
Theta increases in the counterclockwise direction
"""
mtx = self._direction.get_matrix()
if direction in ('clockwise', -1):
mtx[0, 0] = -1
self._direction._mtx._set_scalex(-1)
elif direction in ('counterclockwise', 'anticlockwise', 1):
mtx[0, 0] = 1
self._direction._mtx._set_scalex(1)
else:
_api.check_in_list(
[-1, 1, 'clockwise', 'counterclockwise', 'anticlockwise'],
Expand Down
8 changes: 8 additions & 0 deletions src/_eigen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,13 @@ PYBIND11_MODULE(_eigen, m) {
return result.attr("transpose")();
}
)

// Helpers for PolarTransform.
.def("_set_scalex", [](Eigen::Affine2d& self, double scale) {
self(0, 0) = scale;
})
.def("_set_translatex", [](Eigen::Affine2d& self, double offset) {
self(0, 2) = offset;
})
;
}

0 comments on commit 194090f

Please sign in to comment.