Generated by Cython 0.20.1 on Sat May 30 04:30:00 2015

Raw output: hav.c

 1: from libc.math cimport sin, cos, acos
 2: 
 3: cpdef haversine(double lat1, double lng1, double lat2, double lng2):
static PyObject *__pyx_pw_3hav_1haversine(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_3hav_haversine(double __pyx_v_lat1, double __pyx_v_lng1, double __pyx_v_lat2, double __pyx_v_lng2, CYTHON_UNUSED int __pyx_skip_dispatch) {
  double __pyx_v_theta1;
  double __pyx_v_theta2;
  double __pyx_v_c;
  double __pyx_v_arc;
  double __pyx_v_phi1;
  double __pyx_v_phi2;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("haversine", 0);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("hav.haversine", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_3hav_1haversine(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_3hav_haversine[] = "Given two (lat, lng) tuples, returns the distance between them in\n    meters.";
static PyObject *__pyx_pw_3hav_1haversine(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  double __pyx_v_lat1;
  double __pyx_v_lng1;
  double __pyx_v_lat2;
  double __pyx_v_lng2;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("haversine (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_lat1,&__pyx_n_s_lng1,&__pyx_n_s_lat2,&__pyx_n_s_lng2,0};
    PyObject* values[4] = {0,0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_lat1)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_lng1)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("haversine", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_lat2)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("haversine", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_lng2)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("haversine", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "haversine") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 4) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
    }
    __pyx_v_lat1 = __pyx_PyFloat_AsDouble(values[0]); if (unlikely((__pyx_v_lat1 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_lng1 = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_lng1 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_lat2 = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_lat2 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_lng2 = __pyx_PyFloat_AsDouble(values[3]); if (unlikely((__pyx_v_lng2 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("haversine", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("hav.haversine", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_3hav_haversine(__pyx_self, __pyx_v_lat1, __pyx_v_lng1, __pyx_v_lat2, __pyx_v_lng2);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_3hav_haversine(CYTHON_UNUSED PyObject *__pyx_self, double __pyx_v_lat1, double __pyx_v_lng1, double __pyx_v_lat2, double __pyx_v_lng2) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("haversine", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_3hav_haversine(__pyx_v_lat1, __pyx_v_lng1, __pyx_v_lat2, __pyx_v_lng2, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("hav.haversine", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 4:     """Given two (lat, lng) tuples, returns the distance between them in
 5:     meters."""
 6: 
 7:     if lat1 > 90 or lat1 < -90 or lat2 > 90 or lat2 < -90:
  __pyx_t_1 = ((__pyx_v_lat1 > 90.0) != 0);
  if (!__pyx_t_1) {
    __pyx_t_2 = ((__pyx_v_lat1 < -90.0) != 0);
    if (!__pyx_t_2) {
      __pyx_t_3 = ((__pyx_v_lat2 > 90.0) != 0);
      if (!__pyx_t_3) {
        __pyx_t_4 = ((__pyx_v_lat2 < -90.0) != 0);
        __pyx_t_5 = __pyx_t_4;
      } else {
        __pyx_t_5 = __pyx_t_3;
      }
      __pyx_t_3 = __pyx_t_5;
    } else {
      __pyx_t_3 = __pyx_t_2;
    }
    __pyx_t_2 = __pyx_t_3;
  } else {
    __pyx_t_2 = __pyx_t_1;
  }
  if (__pyx_t_2) {
 8:         raise ValueError("Invalid latitude (should be between +/- 90)")
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_Raise(__pyx_t_6, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
/* … */
  __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_Invalid_latitude_should_be_betwe); if (unlikely(!__pyx_tuple_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple_);
  __Pyx_GIVEREF(__pyx_tuple_);
 9:     if lng1 > 180 or lng1 < -180 or lng2 > 180 or lng2 < -180:
  __pyx_t_2 = ((__pyx_v_lng1 > 180.0) != 0);
  if (!__pyx_t_2) {
    __pyx_t_1 = ((__pyx_v_lng1 < -180.0) != 0);
    if (!__pyx_t_1) {
      __pyx_t_3 = ((__pyx_v_lng2 > 180.0) != 0);
      if (!__pyx_t_3) {
        __pyx_t_5 = ((__pyx_v_lng2 < -180.0) != 0);
        __pyx_t_4 = __pyx_t_5;
      } else {
        __pyx_t_4 = __pyx_t_3;
      }
      __pyx_t_3 = __pyx_t_4;
    } else {
      __pyx_t_3 = __pyx_t_1;
    }
    __pyx_t_1 = __pyx_t_3;
  } else {
    __pyx_t_1 = __pyx_t_2;
  }
  if (__pyx_t_1) {
 10:         raise ValueError("Invalid longitude (should be between +/- 180)")
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_Raise(__pyx_t_6, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
 11: 
 12:     cdef double ph1
 13:     cdef double ph2
 14:     cdef double theta1
 15:     cdef double theta2
 16:     cdef double c
 17:     cdef double arc
 18: 
 19:     phi1 = (90.0 - lat1) * 0.0174532925
  __pyx_v_phi1 = ((90.0 - __pyx_v_lat1) * 0.0174532925);
 20:     phi2 = (90.0 - lat2) * 0.0174532925
  __pyx_v_phi2 = ((90.0 - __pyx_v_lat2) * 0.0174532925);
 21:     theta1 = lng1 * 0.0174532925
  __pyx_v_theta1 = (__pyx_v_lng1 * 0.0174532925);
 22:     theta2 = lng2 * 0.0174532925
  __pyx_v_theta2 = (__pyx_v_lng2 * 0.0174532925);
 23: 
 24:     c = (sin(phi1) * sin(phi2) * cos(theta1 - theta2) + cos(phi1) * cos(phi2))
  __pyx_v_c = (((sin(__pyx_v_phi1) * sin(__pyx_v_phi2)) * cos((__pyx_v_theta1 - __pyx_v_theta2))) + (cos(__pyx_v_phi1) * cos(__pyx_v_phi2)));
 25:     arc = acos(c)
  __pyx_v_arc = acos(__pyx_v_c);
 26:     return arc * 6367444.7
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_6 = PyFloat_FromDouble((__pyx_v_arc * 6367444.7)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_r = __pyx_t_6;
  __pyx_t_6 = 0;
  goto __pyx_L0;