From 2ccda1b8198bdbc6334ade8f1d97ca35452be4c0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20A=2E=20Holm?= Date: Thu, 25 Jul 2013 22:35:33 +0200 Subject: [PATCH] Revert "Merge branch 'use-trunc-rounding' into rounding-fixes" This reverts commit 36e638f89efa36adf6336763b5650a86dd343602, reversing changes made to 6061cb0df2f894bacb4087004186945ebd6af3e5. As mentioned in 08782a5, internal floating values are changed to things like *.*9999, and then the values are corrupted. I wish we had eight fingers instead of ten. Or sixteen. Could lead to some interesting guitar and piano playing. 5d9da52a-f56a-11e2-a82d-001f3b596ec9 --- gpst | 20 +++++++++---------- tests/run-tests.pl | 58 +++++++++++++++++++++++++++--------------------------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/gpst b/gpst index 8c1cf39..b3e4a03 100755 --- a/gpst +++ b/gpst @@ -533,9 +533,15 @@ sub print_gpx { ($Sym = postgresql_copy_safe(xml_to_txt($2))); if (length($Opt{'round'})) { - $Round{'lat'} && ($Lat = int($Lat * (10**$Round{'lat'})) / 10**$Round{'lat'}); - $Round{'lon'} && ($Lon = int($Lon * (10**$Round{'lon'})) / 10**$Round{'lon'}); - $Round{'ele'} && $Ele ne '\N' && ($Ele = int($Ele * (10**$Round{'ele'})) / 10**$Round{'ele'}); + if (defined($Round{'lat'}) && length($Lat)) { + ($Lat = 1.0 * sprintf("%.$Round{'lat'}f", $Lat)); + } + if (defined($Round{'lon'}) && length($Lon)) { + ($Lon = 1.0 * sprintf("%.$Round{'lon'}f", $Lon)); + } + if (defined($Round{'ele'}) && $Ele ne '\N') { + ($Ele = 1.0 * sprintf("%.$Round{'ele'}f", $Ele)); + } } if ($Opt{'output-format'} eq "pgwtab") { @@ -739,7 +745,7 @@ sub print_entry { for my $Tmp (qw{ lat lon ele }) { if (defined($Round{$Tmp}) && length($Dat{$Tmp})) { # D("Tmp = '$Tmp'"); - $Dat{$Tmp} = num_expand(int($Dat{$Tmp} * (10**$Round{$Tmp})) / 10**$Round{$Tmp}); + ($Dat{$Tmp} = num_expand(1.0 * sprintf("%.$Round{$Tmp}f", $Dat{$Tmp}))); } } } @@ -1190,12 +1196,6 @@ Options: -R, --round x=y[,x2=y2[...]] Round trackpoint element x to y decimals. Example: --round lat=4,lon=5,ele=1 - Note that this "rounding" merely truncates the number to not mess up - any substring searches through the GPS logs. I.e.: - -R lat=3,lon=3 - 5.9999,6.4001 = 5.999,6.4 - -R lat=0,lon=2 - 5.7,4.999 = 5,4.99 -s, --short-date Use short date format. -S, --save-to-file x diff --git a/tests/run-tests.pl b/tests/run-tests.pl index cc7e344..5734261 100755 --- a/tests/run-tests.pl +++ b/tests/run-tests.pl @@ -1576,15 +1576,15 @@ testcmd("../gpst -R lat=4,lon=5,ele=1 pause.gpx", # {{{ ACTIVE LOG164705 - 60.4254 5.29953 25.2 - 60.4254 5.29961 24.9 - 60.4253 5.29969 27.9 - 60.4253 5.29974 31 - 60.4253 5.29995 30.9 + 60.4255 5.29953 25.3 + 60.4255 5.29961 24.9 + 60.4253 5.29969 28 + 60.4254 5.29974 31 + 60.4253 5.29996 31 60.4252 5.29964 30.5 - 60.4252 5.29968 30.5 + 60.4252 5.29969 30.5 60.4253 5.29977 31.9 - 60.4254 5.29941 31.7 + 60.4255 5.29942 31.8 END @@ -1596,15 +1596,15 @@ END # }}} testcmd("../gpst -R lat=3,lon=3,ele=1 -o pgtab pause.gpx", # {{{ <. ☺\t2469\tmountain\t2006-05-08T18:27:59Z\tHer er det &, < og >. ☺\tSchwæra greie\thttp://www.example.org/\tWaypoint -(60.397,5.35)\tHalfdan Griegs vei\t\\N\t\\N\t\\N\t04-AUG-02 19:42\t04-AUG-02 19:42\t\\N\t\\N +(51.478,-0.001)\t0-Meridian\t\\N\t\\N\t\\N\t11-FEB-03 15:46\t11-FEB-03 15:46\t\\N\t\\N +(51.532,-0.177)\tAbbey Road\t34.5\t\\N\t\\N\tDet hellige gangfeltet der Beatles valsa over.\t26-FEB-06 17:29:46\t\\N\t\\N +(61.637,8.312)\tGaldhøpiggen med ', &, < og >. ☺\t2469\tmountain\t2006-05-08T18:27:59Z\tHer er det &, < og >. ☺\tSchwæra greie\thttp://www.example.org/\tWaypoint +(60.397,5.351)\tHalfdan Griegs vei\t\\N\t\\N\t\\N\t04-AUG-02 19:42\t04-AUG-02 19:42\t\\N\t\\N (51.51,-0.13)\tLeicester Square\t\\N\t\\N\t\\N\t11-FEB-03 18:00\t11-FEB-03 18:00\t\\N\t\\N -(60.968,9.285)\tLeira camping\t\\N\t\\N\t\\N\t03-OKT-02 21:58\t03-OKT-02 21:58\t\\N\t\\N +(60.969,9.285)\tLeira camping\t\\N\t\\N\t\\N\t03-OKT-02 21:58\t03-OKT-02 21:58\t\\N\t\\N END "", "--round works with lat, lon, ele from gpx, pgwtab output", @@ -1630,28 +1630,28 @@ END testcmd("../gpst -R lat=3,lon=3,ele=1 -o pgwupd multitrack.gpx", # {{{ < coor) < 0.05; - UPDATE logg SET dist = cldist(coor) WHERE (point(51.477,-0.001) <-> coor) < 0.05; + UPDATE logg SET name = clname(coor) WHERE (point(51.478,-0.001) <-> coor) < 0.05; + UPDATE logg SET dist = cldist(coor) WHERE (point(51.478,-0.001) <-> coor) < 0.05; COMMIT; BEGIN; UPDATE logg SET name = clname(coor) WHERE (point(51.532,-0.177) <-> coor) < 0.05; UPDATE logg SET dist = cldist(coor) WHERE (point(51.532,-0.177) <-> coor) < 0.05; COMMIT; BEGIN; - UPDATE logg SET name = clname(coor) WHERE (point(61.636,8.312) <-> coor) < 0.05; - UPDATE logg SET dist = cldist(coor) WHERE (point(61.636,8.312) <-> coor) < 0.05; + UPDATE logg SET name = clname(coor) WHERE (point(61.637,8.312) <-> coor) < 0.05; + UPDATE logg SET dist = cldist(coor) WHERE (point(61.637,8.312) <-> coor) < 0.05; COMMIT; BEGIN; - UPDATE logg SET name = clname(coor) WHERE (point(60.397,5.35) <-> coor) < 0.05; - UPDATE logg SET dist = cldist(coor) WHERE (point(60.397,5.35) <-> coor) < 0.05; + UPDATE logg SET name = clname(coor) WHERE (point(60.397,5.351) <-> coor) < 0.05; + UPDATE logg SET dist = cldist(coor) WHERE (point(60.397,5.351) <-> coor) < 0.05; COMMIT; BEGIN; UPDATE logg SET name = clname(coor) WHERE (point(51.51,-0.13) <-> coor) < 0.05; UPDATE logg SET dist = cldist(coor) WHERE (point(51.51,-0.13) <-> coor) < 0.05; COMMIT; BEGIN; - UPDATE logg SET name = clname(coor) WHERE (point(60.968,9.285) <-> coor) < 0.05; - UPDATE logg SET dist = cldist(coor) WHERE (point(60.968,9.285) <-> coor) < 0.05; + UPDATE logg SET name = clname(coor) WHERE (point(60.969,9.285) <-> coor) < 0.05; + UPDATE logg SET dist = cldist(coor) WHERE (point(60.969,9.285) <-> coor) < 0.05; COMMIT; END "", -- 2.11.4.GIT