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 fdc4154

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 da2d0c4 commit fdc4154
Copy full SHA for fdc4154

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
@@ -80,8 +80,9 @@ def __init__(self, x, y, triangles=None, mask=None):
8080
neighbors = np.asarray(dt.triangle_neighbors, dtype=np.int32)
8181
self._neighbors = np.roll(neighbors, 1, axis=1)
8282
else:
83-
# Triangulation specified.
84-
self.triangles = np.asarray(triangles, dtype=np.int32)
83+
# Triangulation specified. Copy, since we may correct triangle
84+
# orientation.
85+
self.triangles = np.array(triangles, dtype=np.int32)
8586
if self.triangles.ndim != 2 or self.triangles.shape[1] != 3:
8687
raise ValueError('triangles must be a (?,3) array')
8788
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.