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

Skip to content

Improved qhull triangulations with large x,y offset #8873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions doc/api/api_changes/2017-07-14-IT_qhull_large_offset.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Improved Delaunay triangulations with large offsets
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a mention of the Matplotlib methods that are affected by this change? Users might not be aware of what a Delaunay triangulation is or what Matplotlib is doing under the hood, but will be able to identify with a specific Matplotlib method that they use.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping @ianthomas23.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dstansby @QuLogic My apologies, I thought I'd responded to this ages ago but evidently I didn't. I have amended the API change text now.

```````````````````````````````````````````````````

Delaunay triangulations now deal with large x,y offsets in a better
way. This can cause minor changes to any triangulations calculated
using Matplotlib, i.e. any use of `matplotlib.tri.Triangulation` that
requests that a Delaunay triangulation is calculated, which includes
`matplotlib.pyplot.tricontour`, `matplotlib.pyplot.tricontourf`,
`matplotlib.pyplot.tripcolor`, `matplotlib.pyplot.triplot`,
`mlab.griddata` and `mpl_toolkits.mplot3d.plot_trisurf`.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 13 additions & 3 deletions lib/matplotlib/tests/test_triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ def z(x, y):


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


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

Expand Down Expand Up @@ -1123,3 +1122,14 @@ def test_internal_cpp_api():
with pytest.raises(ValueError) as excinfo:
trifinder.find_many([0], [0, 1])
excinfo.match(r'x and y must be array_like with same shape')


def test_qhull_large_offset():
# github issue 8682.
x = np.asarray([0, 1, 0, 1, 0.5])
y = np.asarray([0, 0, 1, 1, 0.5])

offset = 1e10
triang = mtri.Triangulation(x, y)
triang_offset = mtri.Triangulation(x + offset, y + offset)
assert len(triang.triangles) == len(triang_offset.triangles)
14 changes: 12 additions & 2 deletions src/qhull_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ delaunay_impl(int npoints, const double* x, const double* y,
PyArrayObject* neighbors = NULL;
int* triangles_ptr;
int* neighbors_ptr;
double x_mean = 0.0;
double y_mean = 0.0;

QHULL_LIB_CHECK

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

/* Determine mean x, y coordinates. */
for (i = 0; i < npoints; ++i) {
x_mean += x[i];
y_mean += y[i];
}
x_mean /= npoints;
y_mean /= npoints;

/* Prepare points array to pass to qhull. */
for (i = 0; i < npoints; ++i) {
points[2*i ] = x[i];
points[2*i+1] = y[i];
points[2*i ] = x[i] - x_mean;
points[2*i+1] = y[i] - y_mean;
}

/* qhull expects a FILE* to write errors to. */
Expand Down