DistanceOp::distance(): make it return +inf instead of 0 if one of the geometry is empty#1345
Merged
rouault merged 2 commits intolibgeos:mainfrom Jan 24, 2026
Merged
Conversation
… geometry is empty Fixes OSGeo/gdal#12978
Contributor
Author
|
Note GEOS current behavior regarding empty geometries and distance reflects JTS one (CC @dr-jts ) |
lbartoletti
reviewed
Dec 17, 2025
| } | ||
| if(geom[0]->isEmpty() || geom[1]->isEmpty()) { | ||
| return 0.0; | ||
| return std::numeric_limits<double>::quiet_NaN(); |
Contributor
There was a problem hiding this comment.
There is (/was?) a PostGIS page that explains this difference between the GEOS and SFCGAL backends. GEOS returned 0 (before this PR), while SFCGAL returned Inf.
When I asked why Inf rather than NaN, I was told that:
- NaN: was for invalid operations or errors.
- Inf: the geometry exists, but it does not contain any points.
So, here, I also tend to lean towards Inf, as you suggested in your comment Calling Distance on an empty geometry returns 0 OSGeo/gdal#12978 (comment)
Contributor
Author
There was a problem hiding this comment.
I'm fine with Inf too
… geometry is empty
Contributor
Author
|
Changed to returning +Inf |
dbaston
approved these changes
Dec 18, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes OSGeo/gdal#12978