Skip to content

Commit

Permalink
BUG: tri: prevent Triangulation from modifying specified input
Browse files Browse the repository at this point in the history
triplot(x, y, simplex) should not modify the simplex array as a side
effect.
  • Loading branch information
pv authored and ianthomas23 committed Dec 17, 2012
1 parent da2d0c4 commit fdc4154
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_triangulation.py
Expand Up @@ -122,3 +122,12 @@ def test_tripcolor():
plt.subplot(122)
plt.tripcolor(triang, facecolors=Cfaces, edgecolors='k')
plt.title('facecolors')

def test_no_modify():
triangles = np.array([[3, 2, 0], [3, 1, 0]], dtype=np.int32)
points = np.array([(0, 0), (0, 1.1), (1, 0), (1, 1)])

old_triangles = triangles.copy()
tri = mtri.Triangulation(points[:,0], points[:,1], triangles)
edges = tri.edges
assert_array_equal(old_triangles, triangles)
5 changes: 3 additions & 2 deletions lib/matplotlib/tri/triangulation.py
Expand Up @@ -80,8 +80,9 @@ def __init__(self, x, y, triangles=None, mask=None):
neighbors = np.asarray(dt.triangle_neighbors, dtype=np.int32)
self._neighbors = np.roll(neighbors, 1, axis=1)
else:
# Triangulation specified.
self.triangles = np.asarray(triangles, dtype=np.int32)
# Triangulation specified. Copy, since we may correct triangle
# orientation.
self.triangles = np.array(triangles, dtype=np.int32)
if self.triangles.ndim != 2 or self.triangles.shape[1] != 3:
raise ValueError('triangles must be a (?,3) array')
if self.triangles.max() >= len(self.x):
Expand Down

0 comments on commit fdc4154

Please sign in to comment.