Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

BUG: tri: prevent Triangulation from modifying specified input

triplot(x, y, simplex) should not modify the simplex array as a side
effect.
  • Loading branch information...
commit 68388341b0a25867ac2c6ff5a59775b59fdba720 1 parent da2d0c4
@pv authored
View
9 lib/matplotlib/tests/test_triangulation.py
@@ -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)
View
5 lib/matplotlib/tri/triangulation.py
@@ -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):
Please sign in to comment.
Something went wrong with that request. Please try again.