|
6 | 6 | import pytest
|
7 | 7 |
|
8 | 8 | import matplotlib as mpl
|
9 |
| -from matplotlib.patches import (Annulus, Patch, Polygon, Rectangle, |
| 9 | +from matplotlib.patches import (Annulus, Ellipse, Patch, Polygon, Rectangle, |
10 | 10 | FancyArrowPatch)
|
11 | 11 | from matplotlib.testing.decorators import image_comparison, check_figures_equal
|
12 | 12 | from matplotlib.transforms import Bbox
|
@@ -54,6 +54,54 @@ def test_Polygon_close():
|
54 | 54 | assert_array_equal(p.get_xy(), xyclosed)
|
55 | 55 |
|
56 | 56 |
|
| 57 | +def test_corner_center(): |
| 58 | + loc = [10, 20] |
| 59 | + width = 1 |
| 60 | + height = 2 |
| 61 | + |
| 62 | + # Rectangle |
| 63 | + # No rotation |
| 64 | + corners = ((10, 20), (10, 22), (11, 22), (11, 20)) |
| 65 | + rect = Rectangle(loc, width, height) |
| 66 | + assert_array_equal(rect.get_corners(), corners) |
| 67 | + assert_array_equal(rect.get_center(), (10.5, 21)) |
| 68 | + |
| 69 | + # 90 deg rotation |
| 70 | + corners_rot = ((10, 20), (8, 20), (8, 21), (10, 21)) |
| 71 | + rect.set_angle(90) |
| 72 | + assert_array_equal(rect.get_corners(), corners_rot) |
| 73 | + assert_array_equal(rect.get_center(), (9, 20.5)) |
| 74 | + |
| 75 | + # Rotation not a multiple of 90 deg |
| 76 | + theta = 33 |
| 77 | + t = mtransforms.Affine2D().rotate_around(*loc, np.deg2rad(theta)) |
| 78 | + corners_rot = t.transform(corners) |
| 79 | + rect.set_angle(theta) |
| 80 | + assert_almost_equal(rect.get_corners(), corners_rot) |
| 81 | + |
| 82 | + # Ellipse |
| 83 | + loc = [loc[0] + width / 2, |
| 84 | + loc[1] + height / 2] |
| 85 | + ellipse = Ellipse(loc, width, height) |
| 86 | + |
| 87 | + # No rotation |
| 88 | + assert_array_equal(ellipse.get_corners(), corners) |
| 89 | + |
| 90 | + # 90 deg rotation |
| 91 | + corners_rot = ((11.5, 20.5), (9.5, 20.5), (9.5, 21.5), (11.5, 21.5)) |
| 92 | + ellipse.set_angle(90) |
| 93 | + assert_array_equal(ellipse.get_corners(), corners_rot) |
| 94 | + # Rotation shouldn't change ellipse center |
| 95 | + assert_array_equal(ellipse.get_center(), loc) |
| 96 | + |
| 97 | + # Rotation not a multiple of 90 deg |
| 98 | + theta = 33 |
| 99 | + t = mtransforms.Affine2D().rotate_around(*loc, np.deg2rad(theta)) |
| 100 | + corners_rot = t.transform(corners) |
| 101 | + ellipse.set_angle(theta) |
| 102 | + assert_almost_equal(ellipse.get_corners(), corners_rot) |
| 103 | + |
| 104 | + |
57 | 105 | def test_rotate_rect():
|
58 | 106 | loc = np.asarray([1.0, 2.0])
|
59 | 107 | width = 2
|
|
0 commit comments