--- Geo-LatLon2Place/LatLon2Place.pm 2022/03/14 16:04:07 1.4 +++ Geo-LatLon2Place/LatLon2Place.pm 2022/03/15 07:33:40 1.5 @@ -79,7 +79,7 @@ require XSLoader; XSLoader::load (__PACKAGE__, $VERSION); - eval 'sub TORAD() { ' . ((atan2 1,0) / 180) . ' }'; + eval 'sub TORAD() { ' . ((atan2 1,0) / 90) . ' }'; } =item $lookup = Geo::LatLon2Place->new ($path) @@ -108,8 +108,8 @@ $magic eq "SRGL" or Carp::croak "$path: not a Geo::LatLon2Place file"; - $version == 1 - or Carp::croak "$path: version mismatch (got $version, expected 1)"; + $version == 2 + or Carp::croak "$path: version mismatch (got $version, expected 2)"; $self } @@ -139,13 +139,19 @@ =cut +sub lookup_xs { + my ($self, $lat, $lon, $radius) = @_; + + lookup_ext_ $self->[1], $self->[2], $self->[3], $lat, $lon, 0, $radius, 0 +} + sub lookup { my ($self, $lat, $lon, $radius) = @_; $radius ||= $self->[2]; $radius = int +($radius + $self->[2] - 1) / $self->[2]; - my $coslat = cos abs $lat * TORAD; + my $coslat = cos $lat * TORAD; my $blat = int $self->[3] * $coslat; my $cx = int (($lon + 180) * $blat / 360); @@ -155,6 +161,8 @@ for my $y ($cy - $radius .. $cy + $radius) { for my $x ($cx - $radius .. $cx + $radius) { + warn unpack "H*", pack "s< s<", $x, $y; + warn $blat; for (unpack "(C/a*)*", cdb_get $self->[1], pack "s< s<", $x, $y) { my ($plat, $plon, $w, $data) = unpack "s< s< C a*"; $plat = $plat * ( 90 / 32767);