diff --git a/lib/matplotlib/tests/test_patches.py b/lib/matplotlib/tests/test_patches.py index c2fcc7f55944..73f24cd38ebd 100644 --- a/lib/matplotlib/tests/test_patches.py +++ b/lib/matplotlib/tests/test_patches.py @@ -2,8 +2,11 @@ Tests specific to the patches module. """ +import numpy as np from numpy.testing import assert_array_equal +from numpy.testing import assert_almost_equal from matplotlib.patches import Polygon +from matplotlib.patches import Rectangle def test_Polygon_close(): """ @@ -40,3 +43,25 @@ def test_Polygon_close(): p.set_xy(xyclosed) assert_array_equal(p.get_xy(), xyclosed) +def test_rotate_rect(): + loc = np.asarray([1.0, 2.0]) + width = 2 + height = 3 + angle = 30.0 + + # A rotated rectangle + rect1 = Rectangle(loc, width, height, angle=angle) + + # A non-rotated rectangle + rect2 = Rectangle(loc, width, height) + + # Set up an explicit rotation matrix (in radians) + angle_rad = np.pi * angle / 180.0 + rotation_matrix = np.array([[np.cos(angle_rad), -np.sin(angle_rad)], + [np.sin(angle_rad), np.cos(angle_rad)]]) + + # Translate to origin, rotate each vertex, and then translate back + new_verts = np.inner(rotation_matrix, rect2.get_verts() - loc).T + loc + + # They should be the same + assert_almost_equal(rect1.get_verts(), new_verts)