pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/matplotlib/matplotlib/commit/1e936847d41ad71df6b11ef63da65d18d4ff6a04

.css" /> Triangulation.set_mask fix and tests · matplotlib/matplotlib@1e93684 · GitHub
Skip to content

Commit 1e93684

Browse files
committed
Triangulation.set_mask fix and tests
1 parent a4ffb29 commit 1e93684

2 files changed

Lines changed: 36 additions & 6 deletions

File tree

lib/matplotlib/tests/test_triangulation.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,29 @@ def test_triangulation_init():
7272
mtri.Triangulation(x, y, [[0, 1, -1]])
7373

7474

75+
def test_triangulation_set_mask():
76+
x = [-1, 0, 1, 0]
77+
y = [0, -1, 0, 1]
78+
triangles = [[0, 1, 2], [2, 3, 0]]
79+
triang = mtri.Triangulation(x, y, triangles)
80+
81+
# Check neighbors, which forces creation of C++ triangulation
82+
assert_array_equal(triang.neighbors, [[-1, -1, 1], [-1, -1, 0]])
83+
84+
# Set mask
85+
triang.set_mask([False, True])
86+
assert_array_equal(triang.mask, [False, True])
87+
88+
# Reset mask
89+
triang.set_mask(None)
90+
assert triang.mask is None
91+
92+
msg = r"mask array must have same length as triangles array"
93+
for mask in ([False, True, False], [False], [True], False, True):
94+
with pytest.raises(ValueError, match=msg):
95+
triang.set_mask(mask)
96+
97+
7598
def test_delaunay():
7699
# No duplicate points, regular grid.
77100
nx = 5
@@ -1205,11 +1228,18 @@ def test_internal_cpp_api():
12051228
r'triangulation x and y arrays'):
12061229
triang.calculate_plane_coefficients([])
12071230

1208-
with pytest.raises(
1209-
ValueError,
1210-
match=r'mask must be a 1D array with the same length as the '
1211-
r'triangles array'):
1212-
triang.set_mask([0, 1])
1231+
for mask in ([0, 1], None):
1232+
with pytest.raises(
1233+
ValueError,
1234+
match=r'mask must be a 1D array with the same length as the '
1235+
r'triangles array'):
1236+
triang.set_mask(mask)
1237+
1238+
triang.set_mask([True])
1239+
assert_array_equal(triang.get_edges(), np.empty((0, 2)))
1240+
1241+
triang.set_mask(()) # Equivalent to Python Triangulation mask=None
1242+
assert_array_equal(triang.get_edges(), [[1, 0], [2, 0], [2, 1]])
12131243

12141244
# C++ TriContourGenerator.
12151245
with pytest.raises(

lib/matplotlib/tri/_triangulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def set_mask(self, mask):
233233

234234
# Set mask in C++ Triangulation.
235235
if self._cpp_triangulation is not None:
236-
self._cpp_triangulation.set_mask(self.mask)
236+
self._cpp_triangulation.set_mask(self.mask if self.mask is not None else ())
237237

238238
# Clear derived fields so they are recalculated when needed.
239239
self._edges = None

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy