Skip to content

Commit

Permalink
upped Test::Approx dep
Browse files Browse the repository at this point in the history
started testing small_gpx decoded values against originals, had lots of errors.
reverted to rounding to 5 decimal places, reduced number of errors.  still 26...
  • Loading branch information
spurkis committed Apr 2, 2010
1 parent 23dda38 commit 95d5721
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ my $build = Module::Build->new
'IO::File' => '0.01',
},
build_reccomends => {
'Test::Approx' => '0.01',
'Test::Approx' => '0.03',
'Geo::Gpx' => '0.21',
},

Expand Down
6 changes: 3 additions & 3 deletions lib/Geo/Google/PolylineEncoder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,9 @@ sub encode_signed_number {
# We don't use floor() to avoid a dependency on POSIX

# do this in a series of steps so we can see what's going on in the debugger:
#my $num3_5 = sprintf('%3.5f', $orig_num)+0;
#my $num_1e5 = $num3_5 * 1e5;
my $num_1e5 = $orig_num * 1e5;
my $num3_5 = sprintf('%.5f', $orig_num)+0;
my $num_1e5 = $num3_5 * 1e5;
#my $num_1e5 = $orig_num * 1e5;
#my $num = floor($num_1e5);
my $num = sprintf('%.0f', $num_1e5)+0; # equivalent to round()

Expand Down
45 changes: 32 additions & 13 deletions t/small_gpx_file.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ use Test::More;
BEGIN {
eval "use Geo::Gpx";
plan skip_all => 'Geo::Gpx not available' if $@;

eval "use Test::Approx";
plan skip_all => 'Test::Approx not available' if $@;

plan 'no_plan';
}

Expand All @@ -18,19 +22,20 @@ use_ok( 'Geo::Google::PolylineEncoder' );

# Test 3
# A basic encoded polyline with ~100 points
{
my $filename = 't/data/20061228.gpx';
my $fh = IO::File->new( $filename );
my $gpx = Geo::Gpx->new( input => $fh );

my @track_points;
my $iter = $gpx->iterate_trackpoints;
while (my $pt = $iter->()) {
push @track_points, {lat => $pt->{lat}, lon => $pt->{lon}};
}

my $filename = 't/data/20061228.gpx';
my $fh = IO::File->new( $filename );
my $gpx = Geo::Gpx->new( input => $fh );

my @points;
my $iter = $gpx->iterate_trackpoints;
while (my $pt = $iter->()) {
push @points, {lat => $pt->{lat}, lon => $pt->{lon}};
}

{
my $encoder = Geo::Google::PolylineEncoder->new(zoom_factor => 2, num_levels => 18);
my $eline = $encoder->encode( \@track_points );
my $eline = $encoder->encode( \@points );
is( $eline->{num_levels}, 18, 'ex3 num_levels' );
is( $eline->{zoom_factor}, 2, 'ex3 zoom_factor' );
is( $eline->{points}, '{w}yHtP~MbEDzAECDf@HPh@N^ZTrAB`GA|DlF]pJ_BhBa@RI|AOvDyAhFkCPG`D_@hFU`@Ub@Kh@HVfCj@fE\zCI@PbAL`@f@|@d@^ZLj@HnDoAhGQRv@?LLrBpAvHbAjAdBlCrBfFTdFvA|SlA|J@^AST~@l@IxEcB`@WCAFST[b@Y`@EJj@SP_@LSv@?j@FnA@_@Hd@HV', 'ex3 points' );
Expand All @@ -39,7 +44,21 @@ use_ok( 'Geo::Google::PolylineEncoder' );
my $d_points = $encoder->decode_points( $eline->{points} );
my $d_levels = $encoder->decode_levels( $eline->{levels} );
is( scalar @$d_points, scalar @$d_levels, 'decode: num levels == num points' );
is_deeply( $d_points, \@track_points, 'decode_points' );
#is_deeply( $d_levels, [ 17, 16, 17 ], 'decode_levels' );
}

{
my $encoder = Geo::Google::PolylineEncoder->new(zoom_factor => 2, num_levels => 18, visible_threshold => 0.00000001 );
my $eline = $encoder->encode( \@points );
my $d_points = $encoder->decode_points( $eline->{points} );
my $d_levels = $encoder->decode_levels( $eline->{levels} );
is( scalar @$d_points, scalar @$d_levels, 'decode all: num levels == num points' );
is( scalar @$d_points, scalar @points, 'decode all: num points == orig num' );

# compare the decoded & original points, should be only rounding diffs
for my $i (0 .. $#points) {
my ($Pa, $Pb) = ($points[$i], $d_points->[$i]);
is_approx_num( $Pa->{lon}, $Pb->{lon}, "d.lon[$i] =~ o.lon[$i]", 1e-5 );
is_approx_num( $Pa->{lat}, $Pb->{lat}, "d.lat[$i] =~ o.lat[$i]", 1e-5 );
}
}

0 comments on commit 95d5721

Please sign in to comment.