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

Back to archive index

null+****@clear***** null+****@clear*****
2010年 8月 12日 (木) 10:15:37 JST


Kouhei Sutou	2010-08-12 01:15:37 +0000 (Thu, 12 Aug 2010)

  New Revision: 0aa339c773c41712c5a1766cc60ea68d1de87e8c

  Log:
    use grn_geo_in_rectangle().

  Modified files:
    lib/proc.c
    test/unit/story/taiyaki/test-geo.c

  Modified: lib/proc.c (+1 -20)
===================================================================
--- lib/proc.c    2010-08-11 09:24:27 +0000 (4814e39)
+++ lib/proc.c    2010-08-12 01:15:37 +0000 (ae81437)
@@ -2069,26 +2069,7 @@ func_geo_in_rectangle(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *us
   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_geo_point *p, *p1, *p2;
-    grn_id domain = pos->header.domain;
-    if (domain == GRN_DB_TOKYO_GEO_POINT || domain == GRN_DB_WGS84_GEO_POINT) {
-      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_;
-      }
-      if (pos2->header.domain != domain) {
-        GRN_OBJ_INIT(&pos2_, GRN_BULK, 0, domain);
-        if (grn_obj_cast(ctx, pos2, &pos2_, 0)) { goto exit; }
-        pos2 = &pos2_;
-      }
-      p = ((grn_geo_point *)GRN_BULK_HEAD(pos));
-      p1 = ((grn_geo_point *)GRN_BULK_HEAD(pos1));
-      p2 = ((grn_geo_point *)GRN_BULK_HEAD(pos2));
-      r = ((p1->longitude <= p->longitude) && (p->longitude <= p2->longitude) &&
-           (p1->latitude <= p->latitude) && (p->latitude <= p2->latitude));
-    }
+    r = grn_geo_in_rectangle(ctx, args[0], args[1], args[2]);
   }
 exit :
   if ((obj = GRN_PROC_ALLOC(GRN_DB_UINT32, 0))) {

  Modified: test/unit/story/taiyaki/test-geo.c (+31 -0)
===================================================================
--- test/unit/story/taiyaki/test-geo.c    2010-08-11 09:24:27 +0000 (f9a6a69)
+++ test/unit/story/taiyaki/test-geo.c    2010-08-12 01:15:37 +0000 (3910718)
@@ -22,6 +22,7 @@
 #include "../../lib/grn-assertions.h"
 
 void test_in_circle(void);
+void test_in_rectangle(void);
 void test_sort(void);
 void test_filter_by_tag_and_sort_by_distance_from_tokyo_tocho(void);
 void test_but_white(void);
@@ -122,6 +123,36 @@ test_in_circle(void)
 }
 
 void
+test_in_rectangle(void)
+{
+  gdouble takada_no_baba_latitude = 35.7121;
+  gdouble takada_no_baba_longitude = 139.7038;
+  gdouble tsukiji_latitude = 35.6684;
+  gdouble tsukiji_longitude = 139.7727;
+  gdouble budoukan_latitude = 35.69328;
+  gdouble budoukan_longitude = 139.74968;
+
+  cut_assert_equal_string(
+    "[[[3],"
+    "[[\"name\",\"ShortText\"],[\"_score\",\"Int32\"]],"
+    "[\"たいやき神田達磨 八重洲店\",3273],"
+    "[\"銀座 かずや\",3713],"
+    "[\"たい焼き鉄次 大丸東京店\",3732]"
+    "]]",
+    send_command(
+      cut_take_printf(
+        "select Shops "
+        "--sortby '+_score, +name' "
+        "--output_columns 'name, _score' "
+        "--filter 'geo_in_rectangle(location, \"%s\", \"%s\") > 0' "
+        "--scorer '_score=geo_distance(location, \"%s\")'",
+        grn_test_location_string(takada_no_baba_latitude,
+                                 takada_no_baba_longitude),
+        grn_test_location_string(tsukiji_latitude, tsukiji_longitude),
+        grn_test_location_string(budoukan_latitude, budoukan_longitude))));
+}
+
+void
 test_sort(void)
 {
   gdouble yurakucho_latitude = 35.67487;




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