Package: libgeo-point-perl
Version: 0.94-1
Tags: patch

Geo::Distance integration in Geo::Point seems to be broken.

% perl -MGeo::Point -le 'my $p1 = Geo::Point->latlong(0,0); my $p2 = 
Geo::Point->latlong(1,1); print $p1->distance($p2)'
Use of uninitialized value in multiplication (*) at 
/usr/share/perl5/Geo/Distance.pm line 214.
Use of uninitialized value in multiplication (*) at 
/usr/share/perl5/Geo/Distance.pm line 214.
Can't locate object method "distance_calc" via package "Geo::Distance" at 
/usr/share/perl5/Geo/Point.pm line 233.

Proposed patches (including tests) attached.
-- 
Niko Tyni   nt...@debian.org
>From 7462faadd61d3e24661aa6ee1dab6febb6e575a1 Mon Sep 17 00:00:00 2001
From: Niko Tyni <nt...@debian.org>
Date: Fri, 17 Jan 2014 16:22:19 +0200
Subject: [PATCH 1/2] Fix distance calculations

Geo::Distance, at least version 0.20, doesn't offer a distance_calc()
method at all.
---
 lib/Geo/Point.pm |  2 +-
 t/11point.t      | 11 ++++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/lib/Geo/Point.pm b/lib/Geo/Point.pm
index a8dfd72..71fd666 100644
--- a/lib/Geo/Point.pm
+++ b/lib/Geo/Point.pm
@@ -230,7 +230,7 @@ sub distancePointPoint($$$)
 
     my $here  = $self->in('wgs84');
     my $there = $other->in('wgs84');
-    $geodist->distance_calc($units, $here->latlong, $there->latlong);
+    $geodist->distance($units, $here->latlong, $there->latlong);
 }
 
 
diff --git a/t/11point.t b/t/11point.t
index 2ced52c..18602a8 100644
--- a/t/11point.t
+++ b/t/11point.t
@@ -8,7 +8,7 @@ use warnings;
 
 use lib qw(. lib tests ../MathPolygon/lib ../../MathPolygon/lib);
 
-use Test::More tests => 39;
+use Test::More tests => 40;
 
 use Geo::Point;
 use Geo::Proj;
@@ -91,3 +91,12 @@ is($p->string, 'point[utm-31](5.0000 4.0000)');
 is($p->x, 5);
 is($p->y, 4);
 
+#
+# distance
+#
+
+my $p1 = $gp->latlong(0, 1);
+my $p2 = $gp->latlong(1, 1);
+
+cmp_ok(abs($p1->distance($p2, 'nautical mile') - 60), '<', 0.1);
+
-- 
1.8.5.3

>From 056c53aff0c2a2b44be7df1d6ed67843005b5183 Mon Sep 17 00:00:00 2001
From: Niko Tyni <nt...@debian.org>
Date: Fri, 17 Jan 2014 17:07:43 +0200
Subject: [PATCH 2/2] Fix the 'degree' and 'radian' custom distance units

The error in reg_unit() call was probably a victim of a bug in
Geo::Distance documentation, see http://bugs.debian.org/735682

The geometrical interpretation of these distance units isn't
obvious to me, so just check that results are nonzero.
---
 lib/Geo/Shape.pm | 4 ++--
 t/11point.t      | 5 ++++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/Geo/Shape.pm b/lib/Geo/Shape.pm
index 8558386..00c2b99 100644
--- a/lib/Geo/Shape.pm
+++ b/lib/Geo/Shape.pm
@@ -90,8 +90,8 @@ sub distance($;$)
     unless($geodist)
     {   $geodist = Geo::Distance->new;
         $geodist->formula('hsin');
-        $geodist->reg_unit(radians => 1);
-        $geodist->reg_unit(degrees => deg2rad(1));
+        $geodist->reg_unit(1 => 'radians');
+        $geodist->reg_unit(deg2rad(1) => 'degrees');
         $geodist->reg_unit(km => 1, 'kilometer');
     }
 
diff --git a/t/11point.t b/t/11point.t
index 18602a8..de4527b 100644
--- a/t/11point.t
+++ b/t/11point.t
@@ -8,7 +8,7 @@ use warnings;
 
 use lib qw(. lib tests ../MathPolygon/lib ../../MathPolygon/lib);
 
-use Test::More tests => 40;
+use Test::More tests => 42;
 
 use Geo::Point;
 use Geo::Proj;
@@ -100,3 +100,6 @@ my $p2 = $gp->latlong(1, 1);
 
 cmp_ok(abs($p1->distance($p2, 'nautical mile') - 60), '<', 0.1);
 
+isnt($p1->distance($p2, 'degrees'), 0);
+isnt($p1->distance($p2, 'radians'), 0);
+
-- 
1.8.5.3

Reply via email to