@@ -72,6 +72,29 @@ def test_triangulation_init():
72
72
mtri .Triangulation (x , y , [[0 , 1 , - 1 ]])
73
73
74
74
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
+
75
98
def test_delaunay ():
76
99
# No duplicate points, regular grid.
77
100
nx = 5
@@ -1205,11 +1228,18 @@ def test_internal_cpp_api():
1205
1228
r'triangulation x and y arrays' ):
1206
1229
triang .calculate_plane_coefficients ([])
1207
1230
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 ]])
1213
1243
1214
1244
# C++ TriContourGenerator.
1215
1245
with pytest .raises (
0 commit comments