Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f3101f6

Browse files
authored
Merge pull request #8873 from ianthomas23/8682_qhull_large_offset
Improved qhull triangulations with large x,y offset
2 parents cf43f81 + d9ea551 commit f3101f6

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Improved Delaunay triangulations with large offsets
2+
```````````````````````````````````````````````````
3+
4+
Delaunay triangulations now deal with large x,y offsets in a better
5+
way. This can cause minor changes to any triangulations calculated
6+
using Matplotlib, i.e. any use of `matplotlib.tri.Triangulation` that
7+
requests that a Delaunay triangulation is calculated, which includes
8+
`matplotlib.pyplot.tricontour`, `matplotlib.pyplot.tricontourf`,
9+
`matplotlib.pyplot.tripcolor`, `matplotlib.pyplot.triplot`,
10+
`mlab.griddata` and `mpl_toolkits.mplot3d.plot_trisurf`.

lib/matplotlib/tests/test_triangulation.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ def z(x, y):
745745

746746

747747
@image_comparison(baseline_images=['tri_smooth_contouring'],
748-
extensions=['png'], remove_text=True)
748+
extensions=['png'], remove_text=True, tol=0.07)
749749
def test_tri_smooth_contouring():
750750
# Image comparison based on example tricontour_smooth_user.
751751
n_angles = 20
@@ -786,8 +786,7 @@ def z(x, y):
786786

787787

788788
@image_comparison(baseline_images=['tri_smooth_gradient'],
789-
extensions=['png'], remove_text=True,
790-
tol=0.03 if on_win else 0)
789+
extensions=['png'], remove_text=True, tol=0.035)
791790
def test_tri_smooth_gradient():
792791
# Image comparison based on example trigradient_demo.
793792

@@ -1123,3 +1122,14 @@ def test_internal_cpp_api():
11231122
with pytest.raises(ValueError) as excinfo:
11241123
trifinder.find_many([0], [0, 1])
11251124
excinfo.match(r'x and y must be array_like with same shape')
1125+
1126+
1127+
def test_qhull_large_offset():
1128+
# github issue 8682.
1129+
x = np.asarray([0, 1, 0, 1, 0.5])
1130+
y = np.asarray([0, 0, 1, 1, 0.5])
1131+
1132+
offset = 1e10
1133+
triang = mtri.Triangulation(x, y)
1134+
triang_offset = mtri.Triangulation(x + offset, y + offset)
1135+
assert len(triang.triangles) == len(triang_offset.triangles)

src/qhull_wrap.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ delaunay_impl(int npoints, const double* x, const double* y,
108108
PyArrayObject* neighbors = NULL;
109109
int* triangles_ptr;
110110
int* neighbors_ptr;
111+
double x_mean = 0.0;
112+
double y_mean = 0.0;
111113

112114
QHULL_LIB_CHECK
113115

@@ -119,10 +121,18 @@ delaunay_impl(int npoints, const double* x, const double* y,
119121
goto error_before_qhull;
120122
}
121123

124+
/* Determine mean x, y coordinates. */
125+
for (i = 0; i < npoints; ++i) {
126+
x_mean += x[i];
127+
y_mean += y[i];
128+
}
129+
x_mean /= npoints;
130+
y_mean /= npoints;
131+
122132
/* Prepare points array to pass to qhull. */
123133
for (i = 0; i < npoints; ++i) {
124-
points[2*i ] = x[i];
125-
points[2*i+1] = y[i];
134+
points[2*i ] = x[i] - x_mean;
135+
points[2*i+1] = y[i] - y_mean;
126136
}
127137

128138
/* qhull expects a FILE* to write errors to. */

0 commit comments

Comments
 (0)