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 1 commit
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
Next Next commit
Improved qhull triangulations with large x,y offset
  • Loading branch information
ianthomas23 committed Jul 14, 2017
commit be920ad05cf1a31fc93b07adc5236b8d63cb50c5
6 changes: 6 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,6 @@
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.
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.
11 changes: 11 additions & 0 deletions lib/matplotlib/tests/test_triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1123,3 +1123,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