[Groonga-commit] groonga/groonga [master] add GRN_ prefix to macros.

アーカイブの一覧に戻る

null+****@clear***** null+****@clear*****
2010年 8月 5日 (木) 09:55:16 JST


Kouhei Sutou	2010-08-05 00:55:16 +0000 (Thu, 05 Aug 2010)

  New Revision: 4b8ae43432edd1fd6f3b55714d399f12658ebd75

  Log:
    add GRN_ prefix to macros.

  Modified files:
    lib/geo.c
    lib/geo.h

  Modified: lib/geo.c (+35 -46)
===================================================================
--- lib/geo.c    2010-08-05 00:55:07 +0000 (7c56c10)
+++ lib/geo.c    2010-08-05 00:55:16 +0000 (2c05970)
@@ -15,23 +15,12 @@
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
-#include <math.h>
 #include <string.h>
 #include <stdlib.h>
 #include "geo.h"
 #include "ii.h"
 #include "db.h"
 
-#define GEO_RESOLUTION   3600000
-#define GEO_RADIOUS      6357303
-#define GEO_BES_C1       6334834
-#define GEO_BES_C2       6377397
-#define GEO_BES_C3       0.006674
-#define GEO_GRS_C1       6335439
-#define GEO_GRS_C2       6378137
-#define GEO_GRS_C3       0.006694
-#define GEO_INT2RAD(x)   ((M_PI / (GEO_RESOLUTION * 180)) * x)
-
 unsigned
 grn_geo_in_circle(grn_ctx *ctx, grn_obj *point, grn_obj *center,
                   grn_obj *radius_or_point)
@@ -46,28 +35,28 @@ grn_geo_in_circle(grn_ctx *ctx, grn_obj *point, grn_obj *center,
       if (grn_obj_cast(ctx, center, &center_, 0)) { goto exit; }
       center = &center_;
     }
-    lng0 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point))->longitude);
-    lat0 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point))->latitude);
-    lng1 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(center))->longitude);
-    lat1 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(center))->latitude);
+    lng0 = GRN_GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point))->longitude);
+    lat0 = GRN_GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point))->latitude);
+    lng1 = GRN_GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(center))->longitude);
+    lat1 = GRN_GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(center))->latitude);
     x = (lng1 - lng0) * cos((lat0 + lat1) * 0.5);
     y = (lat1 - lat0);
     d = (x * x) + (y * y);
     switch (radius_or_point->header.domain) {
     case GRN_DB_INT32 :
-      r = (sqrt(d) * GEO_RADIOUS) <= GRN_INT32_VALUE(radius_or_point);
+      r = (sqrt(d) * GRN_GEO_RADIOUS) <= GRN_INT32_VALUE(radius_or_point);
       break;
     case GRN_DB_UINT32 :
-      r = (sqrt(d) * GEO_RADIOUS) <= GRN_UINT32_VALUE(radius_or_point);
+      r = (sqrt(d) * GRN_GEO_RADIOUS) <= GRN_UINT32_VALUE(radius_or_point);
       break;
     case GRN_DB_INT64 :
-      r = (sqrt(d) * GEO_RADIOUS) <= GRN_INT64_VALUE(radius_or_point);
+      r = (sqrt(d) * GRN_GEO_RADIOUS) <= GRN_INT64_VALUE(radius_or_point);
       break;
     case GRN_DB_UINT64 :
-      r = (sqrt(d) * GEO_RADIOUS) <= GRN_UINT64_VALUE(radius_or_point);
+      r = (sqrt(d) * GRN_GEO_RADIOUS) <= GRN_UINT64_VALUE(radius_or_point);
       break;
     case GRN_DB_FLOAT :
-      r = (sqrt(d) * GEO_RADIOUS) <= GRN_FLOAT_VALUE(radius_or_point);
+      r = (sqrt(d) * GRN_GEO_RADIOUS) <= GRN_FLOAT_VALUE(radius_or_point);
       break;
     case GRN_DB_SHORT_TEXT :
     case GRN_DB_TEXT :
@@ -79,8 +68,8 @@ grn_geo_in_circle(grn_ctx *ctx, grn_obj *point, grn_obj *center,
     case GRN_DB_TOKYO_GEO_POINT :
     case GRN_DB_WGS84_GEO_POINT :
       if (domain != radius_or_point->header.domain) { /* todo */ goto exit; }
-      lng2 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(radius_or_point))->longitude);
-      lat2 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(radius_or_point))->latitude);
+      lng2 = GRN_GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(radius_or_point))->longitude);
+      lat2 = GRN_GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(radius_or_point))->latitude);
       x = (lng2 - lng1) * cos((lat1 + lat2) * 0.5);
       y = (lat2 - lat1);
       r = d <= (x * x) + (y * y);
@@ -139,13 +128,13 @@ grn_geo_distance(grn_ctx *ctx, grn_obj *point1, grn_obj *point2)
       if (grn_obj_cast(ctx, point2, &point2_, 0)) { goto exit; }
       point2 = &point2_;
     }
-    lng1 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point1))->longitude);
-    lat1 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point1))->latitude);
-    lng2 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point2))->longitude);
-    lat2 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point2))->latitude);
+    lng1 = GRN_GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point1))->longitude);
+    lat1 = GRN_GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point1))->latitude);
+    lng2 = GRN_GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point2))->longitude);
+    lat2 = GRN_GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point2))->latitude);
     x = (lng2 - lng1) * cos((lat1 + lat2) * 0.5);
     y = (lat2 - lat1);
-    d = sqrt((x * x) + (y * y)) * GEO_RADIOUS;
+    d = sqrt((x * x) + (y * y)) * GRN_GEO_RADIOUS;
   } else {
     /* todo */
   }
@@ -166,13 +155,13 @@ grn_geo_distance2(grn_ctx *ctx, grn_obj *point1, grn_obj *point2)
       if (grn_obj_cast(ctx, point2, &point2_, 0)) { goto exit; }
       point2 = &point2_;
     }
-    lng1 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point1))->longitude);
-    lat1 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point1))->latitude);
-    lng2 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point2))->longitude);
-    lat2 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point2))->latitude);
+    lng1 = GRN_GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point1))->longitude);
+    lat1 = GRN_GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point1))->latitude);
+    lng2 = GRN_GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point2))->longitude);
+    lat2 = GRN_GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point2))->latitude);
     x = sin(fabs(lng2 - lng1) * 0.5);
     y = sin(fabs(lat2 - lat1) * 0.5);
-    d = asin(sqrt((y * y) + cos(lat1) * cos(lat2) * x * x)) * 2 * GEO_RADIOUS;
+    d = asin(sqrt((y * y) + cos(lat1) * cos(lat2) * x * x)) * 2 * GRN_GEO_RADIOUS;
   } else {
     /* todo */
   }
@@ -195,15 +184,15 @@ grn_geo_distance3(grn_ctx *ctx, grn_obj *point1, grn_obj *point2)
         if (grn_obj_cast(ctx, point2, &point2_, 0)) { goto exit; }
         point2 = &point2_;
       }
-      lng1 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point1))->longitude);
-      lat1 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point1))->latitude);
-      lng2 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point2))->longitude);
-      lat2 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point2))->latitude);
+      lng1 = GRN_GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point1))->longitude);
+      lat1 = GRN_GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point1))->latitude);
+      lng2 = GRN_GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point2))->longitude);
+      lat2 = GRN_GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point2))->latitude);
       p = (lat1 + lat2) * 0.5;
-      q = (1 - GEO_BES_C3 * sin(p) * sin(p));
+      q = (1 - GRN_GEO_BES_C3 * sin(p) * sin(p));
       r = sqrt(q);
-      m = GEO_BES_C1 / (q * r);
-      n = GEO_BES_C2 / r;
+      m = GRN_GEO_BES_C1 / (q * r);
+      n = GRN_GEO_BES_C2 / r;
       x = n * cos(p) * fabs(lng1 - lng2);
       y = m * fabs(lat1 - lat2);
       d = sqrt((x * x) + (y * y));
@@ -217,15 +206,15 @@ grn_geo_distance3(grn_ctx *ctx, grn_obj *point1, grn_obj *point2)
         if (grn_obj_cast(ctx, point2, &point2_, 0)) { goto exit; }
         point2 = &point2_;
       }
-      lng1 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point1))->longitude);
-      lat1 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point1))->latitude);
-      lng2 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point2))->longitude);
-      lat2 = GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point2))->latitude);
+      lng1 = GRN_GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point1))->longitude);
+      lat1 = GRN_GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point1))->latitude);
+      lng2 = GRN_GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point2))->longitude);
+      lat2 = GRN_GEO_INT2RAD(((grn_geo_point *)GRN_BULK_HEAD(point2))->latitude);
       p = (lat1 + lat2) * 0.5;
-      q = (1 - GEO_GRS_C3 * sin(p) * sin(p));
+      q = (1 - GRN_GEO_GRS_C3 * sin(p) * sin(p));
       r = sqrt(q);
-      m = GEO_GRS_C1 / (q * r);
-      n = GEO_GRS_C2 / r;
+      m = GRN_GEO_GRS_C1 / (q * r);
+      n = GRN_GEO_GRS_C2 / r;
       x = n * cos(p) * fabs(lng1 - lng2);
       y = m * fabs(lat1 - lat2);
       d = sqrt((x * x) + (y * y));

  Modified: lib/geo.h (+12 -0)
===================================================================
--- lib/geo.h    2010-08-05 00:55:07 +0000 (e930791)
+++ lib/geo.h    2010-08-05 00:55:16 +0000 (4c82796)
@@ -21,10 +21,22 @@
 #include "groonga_in.h"
 #endif /* GROONGA_IN_H */
 
+#include <math.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+#define GRN_GEO_RESOLUTION   3600000
+#define GRN_GEO_RADIOUS      6357303
+#define GRN_GEO_BES_C1       6334834
+#define GRN_GEO_BES_C2       6377397
+#define GRN_GEO_BES_C3       0.006674
+#define GRN_GEO_GRS_C1       6335439
+#define GRN_GEO_GRS_C2       6378137
+#define GRN_GEO_GRS_C3       0.006694
+#define GRN_GEO_INT2RAD(x)   ((M_PI / (GRN_GEO_RESOLUTION * 180)) * x)
+
 unsigned grn_geo_in_circle(grn_ctx *ctx, grn_obj *point, grn_obj *center,
                            grn_obj *radius_or_point);
 unsigned grn_geo_in_rectangle(grn_ctx *ctx, grn_obj *point,




Groonga-commit メーリングリストの案内
アーカイブの一覧に戻る