Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cf6e95a

Browse files
author
Johann Krauter
committed
Changed get_vertices and get_co_vertices using get_patch_transform().transform() for coordinate calculations.
1 parent 501436f commit cf6e95a

File tree

1 file changed

+10
-33
lines changed

1 file changed

+10
-33
lines changed

lib/matplotlib/patches.py

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,37 +1657,6 @@ def get_corners(self):
16571657
def _calculate_length_between_points(self, x0, y0, x1, y1):
16581658
return np.sqrt((x1 - x0)**2 + (y1 - y0)**2)
16591659

1660-
def _calculate_vertices_coordinates(self, return_major: bool = True):
1661-
# calculate the vertices of width axis
1662-
w_x0 = self._center[0] - self._width / 2 * np.cos(np.deg2rad(self._angle))
1663-
w_y0 = self._center[1] - self._width / 2 * np.sin(np.deg2rad(self._angle))
1664-
w_x1 = self._center[0] + self._width / 2 * np.cos(np.deg2rad(self._angle))
1665-
w_y1 = self._center[1] + self._width / 2 * np.sin(np.deg2rad(self._angle))
1666-
1667-
# calculate the vertices of height axis
1668-
h_x0 = self._center[0] - self._height / 2 * np.sin(np.deg2rad(self._angle))
1669-
h_y0 = self._center[1] + self._height / 2 * np.cos(np.deg2rad(self._angle))
1670-
h_x1 = self._center[0] + self._height / 2 * np.sin(np.deg2rad(self._angle))
1671-
h_y1 = self._center[1] - self._height / 2 * np.cos(np.deg2rad(self._angle))
1672-
1673-
if self._calculate_length_between_points(
1674-
w_x0, w_y0, w_x1, w_y1
1675-
) >= self._calculate_length_between_points(
1676-
h_x0, h_y0, h_x1, h_y1
1677-
): # width is major
1678-
major = [(w_x0, w_y0), (w_x1, w_y1)]
1679-
minor = [(h_x0, h_y0), (h_x1, h_y1)]
1680-
else: # minor
1681-
major = [(h_x0, h_y0), (h_x1, h_y1)]
1682-
minor = [(w_x0, w_y0), (w_x1, w_y1)]
1683-
1684-
if return_major:
1685-
coordinates = major
1686-
else:
1687-
coordinates = minor
1688-
1689-
return coordinates
1690-
16911660
def get_vertices(self):
16921661
"""
16931662
Return the vertices coordinates of the ellipse.
@@ -1696,7 +1665,11 @@ def get_vertices(self):
16961665
16971666
.. versionadded:: 3.8
16981667
"""
1699-
return self._calculate_vertices_coordinates()
1668+
if self.width < self.height:
1669+
ret = self.get_patch_transform().transform([(0, 1), (0, -1)])
1670+
else:
1671+
ret = self.get_patch_transform().transform([(1, 0), (-1, 0)])
1672+
return [tuple(x) for x in ret]
17001673

17011674
def get_co_vertices(self):
17021675
"""
@@ -1706,7 +1679,11 @@ def get_co_vertices(self):
17061679
17071680
.. versionadded:: 3.8
17081681
"""
1709-
return self._calculate_vertices_coordinates(return_major=False)
1682+
if self.width < self.height:
1683+
ret = self.get_patch_transform().transform([(1, 0), (-1, 0)])
1684+
else:
1685+
ret = self.get_patch_transform().transform([(0, 1), (0, -1)])
1686+
return [tuple(x) for x in ret]
17101687

17111688

17121689
class Annulus(Patch):

0 commit comments

Comments
 (0)