| 155 | |
| 156 | |
| 157 | def test_rotate_rect(): |
| 158 | loc = np.asarray([1.0, 2.0]) |
| 159 | width = 2 |
| 160 | height = 3 |
| 161 | angle = 30.0 |
| 162 | |
| 163 | # A rotated rectangle |
| 164 | rect1 = Rectangle(loc, width, height, angle=angle) |
| 165 | |
| 166 | # A non-rotated rectangle |
| 167 | rect2 = Rectangle(loc, width, height) |
| 168 | |
| 169 | # Set up an explicit rotation matrix (in radians) |
| 170 | angle_rad = np.pi * angle / 180.0 |
| 171 | rotation_matrix = np.array([[np.cos(angle_rad), -np.sin(angle_rad)], |
| 172 | [np.sin(angle_rad), np.cos(angle_rad)]]) |
| 173 | |
| 174 | # Translate to origin, rotate each vertex, and then translate back |
| 175 | new_verts = np.inner(rotation_matrix, rect2.get_verts() - loc).T + loc |
| 176 | |
| 177 | # They should be the same |
| 178 | assert_almost_equal(rect1.get_verts(), new_verts) |
| 179 | |
| 180 | |
| 181 | @check_figures_equal() |