Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c2af7ad

Browse filesBrowse files
pvianthomas23
authored andcommitted
BUG: tri: prevent Triangulation from modifying specified input
triplot(x, y, simplex) should not modify the simplex array as a side effect.
1 parent 5ec4079 commit c2af7ad
Copy full SHA for c2af7ad

File tree

Expand file treeCollapse file tree

2 files changed

+12
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-2
lines changed

‎lib/matplotlib/tests/test_triangulation.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_triangulation.py
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,12 @@ def test_tripcolor():
122122
plt.subplot(122)
123123
plt.tripcolor(triang, facecolors=Cfaces, edgecolors='k')
124124
plt.title('facecolors')
125+
126+
def test_no_modify():
127+
triangles = np.array([[3, 2, 0], [3, 1, 0]], dtype=np.int32)
128+
points = np.array([(0, 0), (0, 1.1), (1, 0), (1, 1)])
129+
130+
old_triangles = triangles.copy()
131+
tri = mtri.Triangulation(points[:,0], points[:,1], triangles)
132+
edges = tri.edges
133+
assert_array_equal(old_triangles, triangles)

‎lib/matplotlib/tri/triangulation.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tri/triangulation.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ def __init__(self, x, y, triangles=None, mask=None):
5959
neighbors = np.asarray(dt.triangle_neighbors, dtype=np.int32)
6060
self._neighbors = np.roll(neighbors, 1, axis=1)
6161
else:
62-
# Triangulation specified.
63-
self.triangles = np.asarray(triangles, dtype=np.int32)
62+
# Triangulation specified. Copy, since we may correct triangle
63+
# orientation.
64+
self.triangles = np.array(triangles, dtype=np.int32)
6465
if self.triangles.ndim != 2 or self.triangles.shape[1] != 3:
6566
raise ValueError('triangles must be a (?,3) array')
6667
if self.triangles.max() >= len(self.x):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.