[Groonga-commit] groonga/groonga [master] use grn_geo_in_circle().

Back to archive index

null+****@clear***** null+****@clear*****
2010年 8月 5日 (木) 10:22:06 JST


Kouhei Sutou	2010-08-05 01:22:06 +0000 (Thu, 05 Aug 2010)

  New Revision: c5e1a63b735ecd8bb225da5b6c203b4896645da0

  Log:
    use grn_geo_in_circle().

  Modified files:
    lib/proc.c

  Modified: lib/proc.c (+2 -53)
===================================================================
--- lib/proc.c    2010-08-05 01:18:41 +0000 (8f1fe40)
+++ lib/proc.c    2010-08-05 01:22:06 +0000 (48bc788)
@@ -27,6 +27,7 @@
 #include "util.h"
 #include "output.h"
 #include "pat.h"
+#include "geo.h"
 
 #ifndef O_NOFOLLOW
 #define O_NOFOLLOW 0
@@ -2065,60 +2066,8 @@ func_geo_in_circle(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_
   grn_obj *obj;
   unsigned char r = GRN_FALSE;
   if (nargs == 3) {
-    grn_obj *pos = args[0], *pos1 = args[1], *pos2 = args[2], pos1_, pos2_;
-    grn_id domain = pos->header.domain;
-    if (domain == GRN_DB_TOKYO_GEO_POINT || domain == GRN_DB_WGS84_GEO_POINT) {
-      double lng0, lat0, lng1, lat1, lng2, lat2, x, y, d;
-      if (pos1->header.domain != domain) {
-        GRN_OBJ_INIT(&pos1_, GRN_BULK, 0, domain);
-        if (grn_obj_cast(ctx, pos1, &pos1_, 0)) { goto exit; }
-        pos1 = &pos1_;
-      }
-      lng0 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(pos))->longitude);
-      lat0 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(pos))->latitude);
-      lng1 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(pos1))->longitude);
-      lat1 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(pos1))->latitude);
-      x = (lng1 - lng0) * cos((lat0 + lat1) * 0.5);
-      y = (lat1 - lat0);
-      d = (x * x) + (y * y);
-      switch (pos2->header.domain) {
-      case GRN_DB_INT32 :
-        r = (sqrt(d) * GEO_RADIOUS) <= GRN_INT32_VALUE(pos2);
-        break;
-      case GRN_DB_UINT32 :
-        r = (sqrt(d) * GEO_RADIOUS) <= GRN_UINT32_VALUE(pos2);
-        break;
-      case GRN_DB_INT64 :
-        r = (sqrt(d) * GEO_RADIOUS) <= GRN_INT64_VALUE(pos2);
-        break;
-      case GRN_DB_UINT64 :
-        r = (sqrt(d) * GEO_RADIOUS) <= GRN_UINT64_VALUE(pos2);
-        break;
-      case GRN_DB_FLOAT :
-        r = (sqrt(d) * GEO_RADIOUS) <= GRN_FLOAT_VALUE(pos2);
-        break;
-      case GRN_DB_SHORT_TEXT :
-      case GRN_DB_TEXT :
-      case GRN_DB_LONG_TEXT :
-        GRN_OBJ_INIT(&pos2_, GRN_BULK, 0, domain);
-        if (grn_obj_cast(ctx, pos2, &pos2_, 0)) { goto exit; }
-        pos2 = &pos2_;
-        /* fallthru */
-      case GRN_DB_TOKYO_GEO_POINT :
-      case GRN_DB_WGS84_GEO_POINT :
-        if (domain != pos2->header.domain) { /* todo */ goto exit; }
-        lng2 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(pos2))->longitude);
-        lat2 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(pos2))->latitude);
-        x = (lng2 - lng1) * cos((lat1 + lat2) * 0.5);
-        y = (lat2 - lat1);
-        r = d <= (x * x) + (y * y);
-        break;
-      default :
-        goto exit;
-      }
-    }
+    r = grn_geo_in_circle(ctx, args[0], args[1], args[2]);
   }
-exit :
   if ((obj = GRN_PROC_ALLOC(GRN_DB_UINT32, 0))) {
     GRN_UINT32_SET(ctx, obj, r);
   }




Groonga-commit メーリングリストの案内
Back to archive index