()
| 960 | |
| 961 | |
| 962 | def test_tritools(): |
| 963 | # Tests TriAnalyzer.scale_factors on masked triangulation |
| 964 | # Tests circle_ratios on equilateral and right-angled triangle. |
| 965 | x = np.array([0., 1., 0.5, 0., 2.]) |
| 966 | y = np.array([0., 0., 0.5*np.sqrt(3.), -1., 1.]) |
| 967 | triangles = np.array([[0, 1, 2], [0, 1, 3], [1, 2, 4]], dtype=np.int32) |
| 968 | mask = np.array([False, False, True], dtype=bool) |
| 969 | triang = mtri.Triangulation(x, y, triangles, mask=mask) |
| 970 | analyser = mtri.TriAnalyzer(triang) |
| 971 | assert_array_almost_equal(analyser.scale_factors, [1, 1/(1+3**.5/2)]) |
| 972 | assert_array_almost_equal( |
| 973 | analyser.circle_ratios(rescale=False), |
| 974 | np.ma.masked_array([0.5, 1./(1.+np.sqrt(2.)), np.nan], mask)) |
| 975 | |
| 976 | # Tests circle ratio of a flat triangle |
| 977 | x = np.array([0., 1., 2.]) |
| 978 | y = np.array([1., 1.+3., 1.+6.]) |
| 979 | triangles = np.array([[0, 1, 2]], dtype=np.int32) |
| 980 | triang = mtri.Triangulation(x, y, triangles) |
| 981 | analyser = mtri.TriAnalyzer(triang) |
| 982 | assert_array_almost_equal(analyser.circle_ratios(), np.array([0.])) |
| 983 | |
| 984 | # Tests TriAnalyzer.get_flat_tri_mask |
| 985 | # Creates a triangulation of [-1, 1] x [-1, 1] with contiguous groups of |
| 986 | # 'flat' triangles at the 4 corners and at the center. Checks that only |
| 987 | # those at the borders are eliminated by TriAnalyzer.get_flat_tri_mask |
| 988 | n = 9 |
| 989 | |
| 990 | def power(x, a): |
| 991 | return np.abs(x)**a*np.sign(x) |
| 992 | |
| 993 | x = np.linspace(-1., 1., n+1) |
| 994 | x, y = np.meshgrid(power(x, 2.), power(x, 0.25)) |
| 995 | x = x.ravel() |
| 996 | y = y.ravel() |
| 997 | |
| 998 | triang = mtri.Triangulation(x, y, triangles=meshgrid_triangles(n+1)) |
| 999 | analyser = mtri.TriAnalyzer(triang) |
| 1000 | mask_flat = analyser.get_flat_tri_mask(0.2) |
| 1001 | verif_mask = np.zeros(162, dtype=bool) |
| 1002 | corners_index = [0, 1, 2, 3, 14, 15, 16, 17, 18, 19, 34, 35, 126, 127, |
| 1003 | 142, 143, 144, 145, 146, 147, 158, 159, 160, 161] |
| 1004 | verif_mask[corners_index] = True |
| 1005 | assert_array_equal(mask_flat, verif_mask) |
| 1006 | |
| 1007 | # Now including a hole (masked triangle) at the center. The center also |
| 1008 | # shall be eliminated by get_flat_tri_mask. |
| 1009 | mask = np.zeros(162, dtype=bool) |
| 1010 | mask[80] = True |
| 1011 | triang.set_mask(mask) |
| 1012 | mask_flat = analyser.get_flat_tri_mask(0.2) |
| 1013 | center_index = [44, 45, 62, 63, 78, 79, 80, 81, 82, 83, 98, 99, 116, 117] |
| 1014 | verif_mask[center_index] = True |
| 1015 | assert_array_equal(mask_flat, verif_mask) |
| 1016 | |
| 1017 | |
| 1018 | def test_trirefine(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…