()
| 188 | |
| 189 | |
| 190 | def test_delaunay_robust(): |
| 191 | # Fails when mtri.Triangulation uses matplotlib.delaunay, works when using |
| 192 | # qhull. |
| 193 | tri_points = np.array([ |
| 194 | [0.8660254037844384, -0.5000000000000004], |
| 195 | [0.7577722283113836, -0.5000000000000004], |
| 196 | [0.6495190528383288, -0.5000000000000003], |
| 197 | [0.5412658773652739, -0.5000000000000003], |
| 198 | [0.811898816047911, -0.40625000000000044], |
| 199 | [0.7036456405748561, -0.4062500000000004], |
| 200 | [0.5953924651018013, -0.40625000000000033]]) |
| 201 | test_points = np.asarray([ |
| 202 | [0.58, -0.46], |
| 203 | [0.65, -0.46], |
| 204 | [0.65, -0.42], |
| 205 | [0.7, -0.48], |
| 206 | [0.7, -0.44], |
| 207 | [0.75, -0.44], |
| 208 | [0.8, -0.48]]) |
| 209 | |
| 210 | # Utility function that indicates if a triangle defined by 3 points |
| 211 | # (xtri, ytri) contains the test point xy. Avoid calling with a point that |
| 212 | # lies on or very near to an edge of the triangle. |
| 213 | def tri_contains_point(xtri, ytri, xy): |
| 214 | tri_points = np.vstack((xtri, ytri)).T |
| 215 | return Path(tri_points).contains_point(xy) |
| 216 | |
| 217 | # Utility function that returns how many triangles of the specified |
| 218 | # triangulation contain the test point xy. Avoid calling with a point that |
| 219 | # lies on or very near to an edge of any triangle in the triangulation. |
| 220 | def tris_contain_point(triang, xy): |
| 221 | return sum(tri_contains_point(triang.x[tri], triang.y[tri], xy) |
| 222 | for tri in triang.triangles) |
| 223 | |
| 224 | # Using matplotlib.delaunay, an invalid triangulation is created with |
| 225 | # overlapping triangles; qhull is OK. |
| 226 | triang = mtri.Triangulation(tri_points[:, 0], tri_points[:, 1]) |
| 227 | for test_point in test_points: |
| 228 | assert tris_contain_point(triang, test_point) == 1 |
| 229 | |
| 230 | # If ignore the first point of tri_points, matplotlib.delaunay throws a |
| 231 | # KeyError when calculating the convex hull; qhull is OK. |
| 232 | triang = mtri.Triangulation(tri_points[1:, 0], tri_points[1:, 1]) |
| 233 | |
| 234 | |
| 235 | @image_comparison(['tripcolor1.png'], style='mpl20') |
nothing calls this directly
no test coverage detected
searching dependent graphs…