Skip to content
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

Math.acos may return NaN #19

Open
daisukes opened this issue May 13, 2024 · 0 comments
Open

Math.acos may return NaN #19

daisukes opened this issue May 13, 2024 · 0 comments
Assignees
Labels

Comments

@daisukes
Copy link
Contributor

I found a bug that sometimes RouteSearchBean returns a null route. (0.0000001 difference can change the result)
The root problem is that Math.acos returns NaN when dist is a bit greater than 1.0
So the dist should be truncated within -1.0 to 1.0.

--- a/MapService/src/hulop/hokoukukan/bean/RouteSearchBean.java
+++ b/MapService/src/hulop/hokoukukan/bean/RouteSearchBean.java
@@ -593,7 +593,6 @@ public class RouteSearchBean {
                double theta = deg2rad(point1[0] - point2[0]);
                double lat1 = deg2rad(point1[1]), lat2 = deg2rad(point2[1]);
                double dist = Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(theta);
+               dist = Math.min(1.0, Math.max(-1.0, dist));
                return METERS_PER_DEGREE * Math.acos(dist) * 180.0 / Math.PI;
        }
@daisukes daisukes added the bug label May 13, 2024
@daisukes daisukes self-assigned this May 13, 2024
daisukes added a commit that referenced this issue May 13, 2024
daisukes added a commit that referenced this issue May 13, 2024
kentarou-fukuda added a commit that referenced this issue May 14, 2024
(#19) bugfix: Math.acos may return NaN
kentarou-fukuda added a commit that referenced this issue May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant