minor API change suggestion on pointPolygonTest() (Feature #4095)
Description
I suggest an API change for the function:
cv::pointPolygonTest()
It returns a `double` that can be either -1,0 or +1. This induces bad code practices, as the user will probably do things like:
if( 1.0 == cv::pointPolygonTest() )
Which is obviously a bad idea, as floating-point values should never be compared with the == operator.
I checked the current source:
https://github.com/Itseez/opencv/blob/master/modules/imgproc/src/geometry.cpp
(line 95)
This value can in some situation be computed as a square root (line 235). But if this computed value is always 0 or 1, then why not return an int ?
Or maybe the 'double' is intended for some future extension ?
Or maybe the general policy is not to break the API ? (although I doubt in the present case that it would break anything)
Associated revisions
Merge pull request #4095 from alalek:hal_unresolved_symbols
History
Updated by Sebastien Kramm about 10 years ago
- Status changed from New to Cancelled
Updated by Sebastien Kramm about 10 years ago
CANCELLED, SORRY FOR THE NOISE, DIDNT READ DOC ENOUGH !
Sebastien Kramm wrote:
I suggest an API change for the function:
[...]It returns a `double` that can be either -1,0 or +1. This induces bad code practices, as the user will probably do things like:
[...]
Which is obviously a bad idea, as floating-point values should never be compared with the == operator.I checked the current source:
https://github.com/Itseez/opencv/blob/master/modules/imgproc/src/geometry.cpp(line 95)
This value can in some situation be computed as a square root (line 235). But if this computed value is always 0 or 1, then why not return an int ?Or maybe the 'double' is intended for some future extension ?
Or maybe the general policy is not to break the API ? (although I doubt in the present case that it would break anything)