karamsa / android-radar

The simple way to make radar in your Android app
19 stars 5 forks source link

getTouchedCircle error #5

Closed hlvas closed 7 years ago

hlvas commented 7 years ago

The function getTouchedCircle(final int xTouch, final int yTouch) in Radar.java has a small error: if (...<rPoint.radius * rPoint.radius * (rPoint.radius/2)) should be if (...<rPoint.radius * rPoint.radius )

karamsa commented 7 years ago

Thank you for using this module. Can you describe me the error and when it happens ?

hlvas commented 7 years ago

Thank you for creating the module and more imporantly to share this. To the issue at hand: To test if a point is within a circle, you want to determine if the distance between the given point and the center of the circle is smaller than the radius of the circle. Therefore the correct check is : distancesquared = (x - cx) * (x - cx) + (y - cy) * (y - cy); distancesquared <= radius * radius; In the code you have an additional (rPoint.radius/2) parameter. If you run the getTouchedCircle you will find that because of that parameter, it always returns true in the first pin, which is wrong.

karamsa commented 7 years ago

Yes you are right i fixed it.
https://github.com/karamsa/android-radar/commit/d0b75c262c4d30bf9e57e38df2e74e6522a3dd3f Thank you for your collaboration ;)