@@ -134,79 +134,83 @@ def test_no_modify():
134
134
135
135
def test_trifinder ():
136
136
# Test points within triangles of masked triangulation.
137
- x ,y = np .meshgrid (np .arange (4 ), np .arange (4 ))
137
+ x , y = np .meshgrid (np .arange (4 ), np .arange (4 ))
138
138
x = x .ravel ()
139
139
y = y .ravel ()
140
- triangles = [[0 ,1 ,4 ], [1 ,5 ,4 ], [1 ,2 ,5 ], [2 ,6 ,5 ], [2 ,3 ,6 ], [3 ,7 ,6 ], [4 ,5 ,8 ],
141
- [5 ,9 ,8 ], [5 ,6 ,9 ], [6 ,10 ,9 ], [6 ,7 ,10 ], [7 ,11 ,10 ], [8 ,9 ,12 ],
142
- [9 ,13 ,12 ], [9 ,10 ,13 ], [10 ,14 ,13 ], [10 ,11 ,14 ], [11 ,15 ,14 ]]
140
+ triangles = [[0 , 1 , 4 ], [1 , 5 , 4 ], [1 , 2 , 5 ], [2 , 6 , 5 ], [2 , 3 , 6 ],
141
+ [3 , 7 , 6 ], [4 , 5 , 8 ], [5 , 9 , 8 ], [5 , 6 , 9 ], [6 , 10 , 9 ],
142
+ [6 , 7 , 10 ], [7 , 11 , 10 ], [8 , 9 , 12 ], [9 , 13 , 12 ], [9 , 10 , 13 ],
143
+ [10 , 14 , 13 ], [10 , 11 , 14 ], [11 , 15 , 14 ]]
143
144
mask = np .zeros (len (triangles ))
144
145
mask [8 :10 ] = 1
145
146
triang = mtri .Triangulation (x , y , triangles , mask )
146
147
trifinder = triang .get_trifinder ()
147
148
148
149
xs = [0.25 , 1.25 , 2.25 , 3.25 ]
149
150
ys = [0.25 , 1.25 , 2.25 , 3.25 ]
150
- xs ,ys = np .meshgrid (xs ,ys )
151
+ xs , ys = np .meshgrid (xs , ys )
151
152
xs = xs .ravel ()
152
153
ys = ys .ravel ()
153
154
tris = trifinder (xs , ys )
154
- assert_array_equal (tris , [0 ,2 ,4 ,- 1 ,6 ,- 1 ,10 ,- 1 ,12 ,14 ,16 ,- 1 ,- 1 ,- 1 ,- 1 ,- 1 ])
155
+ assert_array_equal (tris , [0 , 2 , 4 , - 1 , 6 , - 1 , 10 , - 1 ,
156
+ 12 , 14 , 16 , - 1 , - 1 , - 1 , - 1 , - 1 ])
155
157
tris = trifinder (xs - 0.5 , ys - 0.5 )
156
- assert_array_equal (tris , [- 1 ,- 1 ,- 1 ,- 1 ,- 1 ,1 ,3 ,5 ,- 1 ,7 ,- 1 ,11 ,- 1 ,13 ,15 ,17 ])
158
+ assert_array_equal (tris , [- 1 , - 1 , - 1 , - 1 , - 1 , 1 , 3 , 5 ,
159
+ - 1 , 7 , - 1 , 11 , - 1 , 13 , 15 , 17 ])
157
160
158
161
# Test points exactly on boundary edges of masked triangulation.
159
- xs = [0.5 , 1.5 , 2.5 , 0.5 , 1.5 , 2.5 , 1.5 , 1.5 , 0.0 , 1.0 , 2.0 , 3.0 ]
160
- ys = [0.0 , 0.0 , 0.0 , 3.0 , 3.0 , 3.0 , 1.0 , 2.0 , 1.5 , 1.5 , 1.5 , 1.5 ]
162
+ xs = [0.5 , 1.5 , 2.5 , 0.5 , 1.5 , 2.5 , 1.5 , 1.5 , 0.0 , 1.0 , 2.0 , 3.0 ]
163
+ ys = [0.0 , 0.0 , 0.0 , 3.0 , 3.0 , 3.0 , 1.0 , 2.0 , 1.5 , 1.5 , 1.5 , 1.5 ]
161
164
tris = trifinder (xs , ys )
162
- assert_array_equal (tris , [0 ,2 , 4 , 13 ,15 ,17 ,3 , 14 ,6 , 7 , 10 ,11 ])
165
+ assert_array_equal (tris , [0 , 2 , 4 , 13 , 15 , 17 , 3 , 14 , 6 , 7 , 10 , 11 ])
163
166
164
167
# Test points exactly on boundary corners of masked triangulation.
165
168
xs = [0.0 , 3.0 ]
166
169
ys = [0.0 , 3.0 ]
167
170
tris = trifinder (xs , ys )
168
- assert_array_equal (tris , [0 ,17 ])
171
+ assert_array_equal (tris , [0 , 17 ])
169
172
170
173
# Test triangles with horizontal colinear points. These are not valid
171
174
# triangulations, but we try to deal with the simplest violations.
172
175
delta = 0.0 # If +ve, triangulation is OK, if -ve triangulation invalid,
173
176
# if zero have colinear points but should pass tests anyway.
174
177
x = [1.5 , 0 , 1 , 2 , 3 , 1.5 , 1.5 ]
175
178
y = [- 1 , 0 , 0 , 0 , 0 , delta , 1 ]
176
- triangles = [[0 ,2 , 1 ], [0 ,3 , 2 ], [0 ,4 , 3 ], [1 ,2 , 5 ], [2 ,3 , 5 ], [ 3 , 4 , 5 ], [ 1 , 5 , 6 ],
177
- [4 , 6 , 5 ]]
179
+ triangles = [[0 , 2 , 1 ], [0 , 3 , 2 ], [0 , 4 , 3 ], [1 , 2 , 5 ], [2 , 3 , 5 ],
180
+ [3 , 4 , 5 ], [ 1 , 5 , 6 ], [ 4 , 6 , 5 ]]
178
181
triang = mtri .Triangulation (x , y , triangles )
179
182
trifinder = triang .get_trifinder ()
180
183
181
184
xs = [- 0.1 , 0.4 , 0.9 , 1.4 , 1.9 , 2.4 , 2.9 ]
182
- ys = [- 0.1 ,0.1 ]
183
- xs ,ys = np .meshgrid (xs , ys )
185
+ ys = [- 0.1 , 0.1 ]
186
+ xs , ys = np .meshgrid (xs , ys )
184
187
tris = trifinder (xs , ys )
185
- assert_array_equal (tris , [[- 1 ,0 ,0 ,1 ,1 ,2 ,- 1 ],[- 1 ,6 ,6 ,6 ,7 ,7 ,- 1 ]])
188
+ assert_array_equal (tris , [[- 1 , 0 , 0 , 1 , 1 , 2 , - 1 ],
189
+ [- 1 , 6 , 6 , 6 , 7 , 7 , - 1 ]])
186
190
187
191
# Test triangles with vertical colinear points. These are not valid
188
192
# triangulations, but we try to deal with the simplest violations.
189
193
delta = 0.0 # If +ve, triangulation is OK, if -ve triangulation invalid,
190
194
# if zero have colinear points but should pass tests anyway.
191
195
x = [- 1 , - delta , 0 , 0 , 0 , 0 , 1 ]
192
196
y = [1.5 , 1.5 , 0 , 1 , 2 , 3 , 1.5 ]
193
- triangles = [[0 ,1 , 2 ], [0 ,1 , 5 ], [1 ,2 , 3 ], [1 ,3 , 4 ], [1 ,4 , 5 ], [ 2 , 6 , 3 ], [ 3 , 6 , 4 ],
194
- [4 , 6 , 5 ]]
197
+ triangles = [[0 , 1 , 2 ], [0 , 1 , 5 ], [1 , 2 , 3 ], [1 , 3 , 4 ], [1 , 4 , 5 ],
198
+ [2 , 6 , 3 ], [ 3 , 6 , 4 ], [ 4 , 6 , 5 ]]
195
199
triang = mtri .Triangulation (x , y , triangles )
196
200
trifinder = triang .get_trifinder ()
197
201
198
- xs = [- 0.1 ,0.1 ]
202
+ xs = [- 0.1 , 0.1 ]
199
203
ys = [- 0.1 , 0.4 , 0.9 , 1.4 , 1.9 , 2.4 , 2.9 ]
200
- xs ,ys = np .meshgrid (xs , ys )
204
+ xs , ys = np .meshgrid (xs , ys )
201
205
tris = trifinder (xs , ys )
202
- assert_array_equal (tris , [[- 1 ,- 1 ], [0 ,5 ], [0 ,5 ], [0 ,6 ], [1 ,6 ], [1 ,7 ],
203
- [- 1 ,- 1 ]])
206
+ assert_array_equal (tris , [[- 1 , - 1 ], [0 , 5 ], [0 , 5 ], [0 , 6 ], [1 , 6 ], [1 , 7 ],
207
+ [- 1 , - 1 ]])
204
208
205
209
# Test that changing triangulation by setting a mask causes the trifinder
206
210
# to be reinitialised.
207
211
x = [0 , 1 , 0 , 1 ]
208
212
y = [0 , 0 , 1 , 1 ]
209
- triangles = [[0 ,1 , 2 ], [1 ,3 , 2 ]]
213
+ triangles = [[0 , 1 , 2 ], [1 , 3 , 2 ]]
210
214
triang = mtri .Triangulation (x , y , triangles )
211
215
trifinder = triang .get_trifinder ()
212
216
@@ -222,21 +226,22 @@ def test_trifinder():
222
226
223
227
def test_triinterp ():
224
228
# Test points within triangles of masked triangulation.
225
- x ,y = np .meshgrid (np .arange (4 ), np .arange (4 ))
229
+ x , y = np .meshgrid (np .arange (4 ), np .arange (4 ))
226
230
x = x .ravel ()
227
231
y = y .ravel ()
228
232
z = 1.23 * x - 4.79 * y
229
- triangles = [[0 ,1 ,4 ], [1 ,5 ,4 ], [1 ,2 ,5 ], [2 ,6 ,5 ], [2 ,3 ,6 ], [3 ,7 ,6 ], [4 ,5 ,8 ],
230
- [5 ,9 ,8 ], [5 ,6 ,9 ], [6 ,10 ,9 ], [6 ,7 ,10 ], [7 ,11 ,10 ], [8 ,9 ,12 ],
231
- [9 ,13 ,12 ], [9 ,10 ,13 ], [10 ,14 ,13 ], [10 ,11 ,14 ], [11 ,15 ,14 ]]
233
+ triangles = [[0 , 1 , 4 ], [1 , 5 , 4 ], [1 , 2 , 5 ], [2 , 6 , 5 ], [2 , 3 , 6 ],
234
+ [3 , 7 , 6 ], [4 , 5 , 8 ], [5 , 9 , 8 ], [5 , 6 , 9 ], [6 , 10 , 9 ],
235
+ [6 , 7 , 10 ], [7 , 11 , 10 ], [8 , 9 , 12 ], [9 , 13 , 12 ], [9 , 10 , 13 ],
236
+ [10 , 14 , 13 ], [10 , 11 , 14 ], [11 , 15 , 14 ]]
232
237
mask = np .zeros (len (triangles ))
233
238
mask [8 :10 ] = 1
234
239
triang = mtri .Triangulation (x , y , triangles , mask )
235
240
linear_interp = mtri .LinearTriInterpolator (triang , z )
236
241
237
242
xs = np .linspace (0.25 , 2.75 , 6 )
238
243
ys = [0.25 , 0.75 , 2.25 , 2.75 ]
239
- xs ,ys = np .meshgrid (xs ,ys )
244
+ xs , ys = np .meshgrid (xs , ys )
240
245
xs = xs .ravel ()
241
246
ys = ys .ravel ()
242
247
zs = linear_interp (xs , ys )
@@ -245,7 +250,7 @@ def test_triinterp():
245
250
# Test points outside triangulation.
246
251
xs = [- 0.25 , 1.25 , 1.75 , 3.25 ]
247
252
ys = xs
248
- xs , ys = np .meshgrid (xs ,ys )
253
+ xs , ys = np .meshgrid (xs , ys )
249
254
xs = xs .ravel ()
250
255
ys = ys .ravel ()
251
256
zs = linear_interp (xs , ys )
0 commit comments