Geo-LatLon2Place

 view release on metacpan or  search on metacpan

LatLon2Place.xs  view on Meta::CPAN

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#include <math.h>

#include "perlmulticore.h"

#if EMBED_CDB
 #include "cdb-embedded.c"
#else
 #include <cdb.h>
#endif

#define TORAD(r) ((r) * (M_PI / 180.))

static struct cdb_make make;

struct res
{
  double mind;
  unsigned int respos, reslen;
  double x, y;
};

static inline int
intmin (int a, int b)
{
  return a > b ? b : a;
}

static inline int
intmax (int a, int b)
{
  return a > b ? a : b;
}

static inline int
get_u16 (const U8 *ptr)
{
  return ptr[0] | (ptr[1] << 8);
}

MODULE = Geo::LatLon2Place		PACKAGE = Geo::LatLon2Place

PROTOTYPES: ENABLE

SV *
lookup_ext_ (SV *cdb, int km, int boxes, NV lat, NV lon, int r0, int r1, int flags)
	CODE:
{
        struct cdb *db = (struct cdb *)SvPVX (cdb);

        if (!r1)
          r1 = km;

        r0 =  r0           / km;
        r1 = (r1 + km - 1) / km;
        double coslat = cos (TORAD (lat));
        int cy = (lat + 90.) * boxes * (1. / 180.);
        int x, y;

        if (r1 < r0 || r0 < 0 || r1 < 0 || r0 >= boxes / 2 || r1 >= boxes / 2)
          XSRETURN_EMPTY;

        if (lat < -90. || lat > 90. || lon < -180 || lon > 180.)
          XSRETURN_EMPTY;

        double mind = 1e99;



( run in 1.571 second using v1.01-cache-2.11-cpan-a49fcb8fa48 )