rounding error interrupts GPXViewer

Bug #832059 reported by Fernando Roxo
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gpxviewer (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

Upon opening a .gpx file I got the message :

$ gpxviewer
Traceback (most recent call last):
  File "/usr/share/gpxviewer/gpxviewer/ui.py", line 300, in onTrackAdded
    self.selectTrace(trace)
  File "/usr/share/gpxviewer/gpxviewer/ui.py", line 347, in selectTrace
    distance = trace.get_distance()
  File "/usr/share/gpxviewer/gpxviewer/gpx.py", line 153, in get_distance
    return self._get_cached_value("distance")
  File "/usr/share/gpxviewer/gpxviewer/gpx.py", line 99, in _get_cached_value
    self._walk_points()
  File "/usr/share/gpxviewer/gpxviewer/gpx.py", line 75, in _walk_points
    d = calculate_distance(point['lat'], pointp['lat'], point['lon'], pointp['lon'])
  File "/usr/share/gpxviewer/gpxviewer/gpx.py", line 36, in calculate_distance
    arc = acos((sin(lat1) * sin(lat2)) + (cos(lat1) * cos(lat2) * cos(lon2 - lon1)))
ValueError: math domain error

I inserted the line :

print "lat1=",lat1, "lat2=",lat2, "lon1=",lon1, "lon2=",lon2

And got :

.....
lat1= -22.951462 lat2= -22.951447 lon1= -43.356941 lon2= -43.356937
lat1= -22.951469 lat2= -22.951462 lon1= -43.356941 lon2= -43.356941
lat1= -22.951469 lat2= -22.951469 lon1= -43.356941 lon2= -43.356941
Traceback (most recent call last):
  File "/usr/share/gpxviewer/gpxviewer/ui.py", line 300, in onTrackAdded
    self.selectTrace(trace)
  File "/usr/share/gpxviewer/gpxviewer/ui.py", line 347, in selectTrace
    distance = trace.get_distance()
  File "/usr/share/gpxviewer/gpxviewer/gpx.py", line 156, in get_distance
    return self._get_cached_value("distance")
  File "/usr/share/gpxviewer/gpxviewer/gpx.py", line 102, in _get_cached_value
    self._walk_points()
  File "/usr/share/gpxviewer/gpxviewer/gpx.py", line 78, in _walk_points
    d = calculate_distance(point['lat'], pointp['lat'], point['lon'], pointp['lon'])
  File "/usr/share/gpxviewer/gpxviewer/gpx.py", line 39, in calculate_distance
    arc = acos((sin(lat1) * sin(lat2)) + (cos(lat1) * cos(lat2) * cos(lon2 - lon1)))
ValueError: math domain error

Interactively computing the value I got :

>>> ((sin(lat1) * sin(lat2)) + (cos(lat1) * cos(lat2) * cos(lon2 - lon1)))
1.0000000000000002

This seems to be a typical perversion of floating point rounding error. Do not seems too complicated to fix.

Something like the patch I am attaching.

Revision history for this message
Fernando Roxo (roxo) wrote :
Fernando Roxo (roxo)
affects: gpxviewer → ubuntu
tags: added: patch
Revision history for this message
Vadim Rutkovsky (roignac) wrote :

Could you please specify which version are you using? Is the bug still reproducible?

affects: ubuntu → gpxviewer (Ubuntu)
Changed in gpxviewer (Ubuntu):
status: New → Incomplete
Revision history for this message
Fernando Roxo (roxo) wrote :

The version is the one that is present in Ubuntu 11.04, version 0.4.1.

Yes, it is reproducible.

 I am attaching a test file that can reproduce the problem and works correctly with the tentative sollution I have sent.

Changed in gpxviewer (Ubuntu):
status: Incomplete → Confirmed
Revision history for this message
Andrew Gee (andrewgee) wrote :

Hi. This bug has been fixed upstream. I will work on packaging this for debian/ubuntu soon.

Thanks for reporting this bug. Your contribution is appreciated! Feel free to report any more bugs in the future.

Revision history for this message
Andrew Gee (andrewgee) wrote :

gpxviewer (0.4.3-1) unstable; urgency=low

   * New upstream release
       * Fixes rounding error. Closes: #664494
   * Fixes double build error. Closes: #671212
 -- Andrew Gee <email address hidden> Sat, 12 May 2012 13:22:22 +0100

Changed in gpxviewer (Ubuntu):
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.