()
| 323 | |
| 324 | |
| 325 | def test_trifinder(): |
| 326 | # Test points within triangles of masked triangulation. |
| 327 | x, y = np.meshgrid(np.arange(4), np.arange(4)) |
| 328 | x = x.ravel() |
| 329 | y = y.ravel() |
| 330 | triangles = [[0, 1, 4], [1, 5, 4], [1, 2, 5], [2, 6, 5], [2, 3, 6], |
| 331 | [3, 7, 6], [4, 5, 8], [5, 9, 8], [5, 6, 9], [6, 10, 9], |
| 332 | [6, 7, 10], [7, 11, 10], [8, 9, 12], [9, 13, 12], [9, 10, 13], |
| 333 | [10, 14, 13], [10, 11, 14], [11, 15, 14]] |
| 334 | mask = np.zeros(len(triangles)) |
| 335 | mask[8:10] = 1 |
| 336 | triang = mtri.Triangulation(x, y, triangles, mask) |
| 337 | trifinder = triang.get_trifinder() |
| 338 | |
| 339 | xs = [0.25, 1.25, 2.25, 3.25] |
| 340 | ys = [0.25, 1.25, 2.25, 3.25] |
| 341 | xs, ys = np.meshgrid(xs, ys) |
| 342 | xs = xs.ravel() |
| 343 | ys = ys.ravel() |
| 344 | tris = trifinder(xs, ys) |
| 345 | assert_array_equal(tris, [0, 2, 4, -1, 6, -1, 10, -1, |
| 346 | 12, 14, 16, -1, -1, -1, -1, -1]) |
| 347 | tris = trifinder(xs-0.5, ys-0.5) |
| 348 | assert_array_equal(tris, [-1, -1, -1, -1, -1, 1, 3, 5, |
| 349 | -1, 7, -1, 11, -1, 13, 15, 17]) |
| 350 | |
| 351 | # Test points exactly on boundary edges of masked triangulation. |
| 352 | 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] |
| 353 | 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] |
| 354 | tris = trifinder(xs, ys) |
| 355 | assert_array_equal(tris, [0, 2, 4, 13, 15, 17, 3, 14, 6, 7, 10, 11]) |
| 356 | |
| 357 | # Test points exactly on boundary corners of masked triangulation. |
| 358 | xs = [0.0, 3.0] |
| 359 | ys = [0.0, 3.0] |
| 360 | tris = trifinder(xs, ys) |
| 361 | assert_array_equal(tris, [0, 17]) |
| 362 | |
| 363 | # |
| 364 | # Test triangles with horizontal colinear points. These are not valid |
| 365 | # triangulations, but we try to deal with the simplest violations. |
| 366 | # |
| 367 | |
| 368 | # If +ve, triangulation is OK, if -ve triangulation invalid, |
| 369 | # if zero have colinear points but should pass tests anyway. |
| 370 | delta = 0.0 |
| 371 | |
| 372 | x = [1.5, 0, 1, 2, 3, 1.5, 1.5] |
| 373 | y = [-1, 0, 0, 0, 0, delta, 1] |
| 374 | triangles = [[0, 2, 1], [0, 3, 2], [0, 4, 3], [1, 2, 5], [2, 3, 5], |
| 375 | [3, 4, 5], [1, 5, 6], [4, 6, 5]] |
| 376 | triang = mtri.Triangulation(x, y, triangles) |
| 377 | trifinder = triang.get_trifinder() |
| 378 | |
| 379 | xs = [-0.1, 0.4, 0.9, 1.4, 1.9, 2.4, 2.9] |
| 380 | ys = [-0.1, 0.1] |
| 381 | xs, ys = np.meshgrid(xs, ys) |
| 382 | tris = trifinder(xs, ys) |
nothing calls this directly
no test coverage detected
searching dependent graphs…