null+****@clear*****
null+****@clear*****
2011年 3月 9日 (水) 16:01:35 JST
Kouhei Sutou 2011-03-09 07:01:35 +0000 (Wed, 09 Mar 2011) New Revision: 3e0a81bbb56dde54c2c12cf0cb9c00d59597f74e Log: add a max latitude check. Modified files: lib/geo.c lib/geo.h test/unit/story/test-taiyaki.c Modified: lib/geo.c (+10 -0) =================================================================== --- lib/geo.c 2011-03-09 07:00:46 +0000 (f4a8618) +++ lib/geo.c 2011-03-09 07:01:35 +0000 (c83f2fd) @@ -695,6 +695,16 @@ grn_geo_search_in_rectangle(grn_ctx *ctx, grn_obj *obj, grn_obj **args, int narg goto exit; } + if (geo_point1->latitude >= GRN_GEO_MAX_LATITUDE) { + ERR(GRN_INVALID_ARGUMENT, + "geo_in_rectangle(): geo point1's latitude is too big: <%d>(max:%d): " + "(%d,%d) (%d,%d)", + GRN_GEO_MAX_LATITUDE, geo_point1->latitude, + geo_point1->latitude, geo_point1->longitude, + geo_point2->latitude, geo_point2->longitude); + goto exit; + } + latitude_distance = geo_point1->latitude - geo_point2->latitude; longitude_distance = geo_point2->longitude - geo_point1->longitude; if (latitude_distance > longitude_distance) { Modified: lib/geo.h (+3 -0) =================================================================== --- lib/geo.h 2011-03-09 07:00:46 +0000 (e99d943) +++ lib/geo.h 2011-03-09 07:01:35 +0000 (5eb6df7) @@ -41,6 +41,9 @@ extern "C" { #define GRN_GEO_INT2RAD(x) ((int)((M_PI / (GRN_GEO_RESOLUTION * 180)) * (x))) #define GRN_GEO_RAD2INT(x) ((int)(((GRN_GEO_RESOLUTION * 180) / M_PI) * (x))) +#define GRN_GEO_MAX_LATITUDE 1296000000 /* 360 * 60 * 60 * 1000 */ +#define GRN_GEO_MAX_LONGITUDE 648000000 /* 180 * 60 * 60 * 1000 */ + #define GRN_GEO_POINT_VALUE_RAW(obj) (grn_geo_point *)GRN_BULK_HEAD(obj) #define GRN_GEO_POINT_VALUE_RADIUS(obj,_latitude,_longitude) do {\ grn_geo_point *_val = (grn_geo_point *)GRN_BULK_HEAD(obj);\ Modified: test/unit/story/test-taiyaki.c (+17 -0) =================================================================== --- test/unit/story/test-taiyaki.c 2011-03-09 07:00:46 +0000 (6977313) +++ test/unit/story/test-taiyaki.c 2011-03-09 07:01:35 +0000 (9c81cc6) @@ -25,6 +25,7 @@ void test_in_circle(void); void test_in_rectangle_long_latitude(void); void test_in_rectangle_long_longitude(void); void test_in_rectangle_over_border(void); +void test_in_rectangle_over_latitude1(void); void test_sort(void); void test_filter_by_tag_and_sort_by_distance_from_tokyo_tocho(void); void test_in_circle_and_tag(void); @@ -205,6 +206,22 @@ test_in_rectangle_over_border(void) } void +test_in_rectangle_over_latitude1(void) +{ + grn_test_assert_send_command_error( + context, + GRN_FUNCTION_NOT_IMPLEMENTED, + "geo_in_rectangle(): geo point1's latitude is too big: " + "<1296000000>(max:1296000000): " + "(1296000000,505723679) (130508208,505954080", + "select Shops " + "--sortby '+name' " + "--output_columns 'name, location' " + "--filter " + "'geo_in_rectangle(location, \"360.0x139.7394\", \"35.62614x139.7714\")'"); +} + +void test_sort(void) { gdouble yurakucho_latitude = 35.67487;