null+****@clear*****
null+****@clear*****
2012年 6月 5日 (火) 19:07:51 JST
HAYASHI Kentaro 2012-06-05 19:07:51 +0900 (Tue, 05 Jun 2012)
New Revision: 5fcab3fbb5d7f2df19ba27b7356213f3b67b18c4
Log:
geo: change not to execute redundant longitude check
refs #1386
This fix improves the performance penalty introduced at revision 397bbc80
Modified files:
lib/geo.c
Modified: lib/geo.c (+16 -16)
===================================================================
--- lib/geo.c 2012-06-05 13:42:55 +0900 (727ac4f)
+++ lib/geo.c 2012-06-05 19:07:51 +0900 (c67eab5)
@@ -1934,18 +1934,18 @@ grn_geo_distance_rectangle_raw(grn_ctx *ctx,
lng1 = GRN_GEO_INT2RAD(point1->longitude);
lat2 = GRN_GEO_INT2RAD(point2->latitude);
lng2 = GRN_GEO_INT2RAD(point2->longitude);
- dist_type = geo_longitude_distance_type(point1->longitude,
- point2->longitude);
- if (dist_type == LONGITUDE_SHORT) {
- quad_type = geo_quadrant_type(point1, point2);
- if (quad_type == QUADRANT_1ST ||
- quad_type == QUADRANT_2ND ||
- quad_type == QUADRANT_3RD ||
- quad_type == QUADRANT_4TH) {
- x = (lng2 - lng1) * cos((lat1 + lat2) * 0.5);
- y = (lat2 - lat1);
- distance = sqrt((x * x) + (y * y)) * GRN_GEO_RADIUS;
- } else {
+ quad_type = geo_quadrant_type(point1, point2);
+ if (quad_type == QUADRANT_1ST ||
+ quad_type == QUADRANT_2ND ||
+ quad_type == QUADRANT_3RD ||
+ quad_type == QUADRANT_4TH) {
+ x = (lng2 - lng1) * cos((lat1 + lat2) * 0.5);
+ y = (lat2 - lat1);
+ distance = sqrt((x * x) + (y * y)) * GRN_GEO_RADIUS;
+ } else {
+ dist_type = geo_longitude_distance_type(point1->longitude,
+ point2->longitude);
+ if (dist_type == LONGITUDE_SHORT) {
longitude_delta = lng2 - lng1;
latitude_delta = lat2 - lat1;
slope = latitude_delta / longitude_delta;
@@ -1959,11 +1959,11 @@ grn_geo_distance_rectangle_raw(grn_ctx *ctx,
lng2,
lat2);
distance = east_distance + west_distance;
+ } else {
+ x = (lng2 - lng1) * cos((lat1 + lat2) * 0.5);
+ y = (lat2 - lat1);
+ distance = sqrt((x * x) + (y * y)) * GRN_GEO_RADIUS;
}
- } else {
- x = (lng2 - lng1) * cos((lat1 + lat2) * 0.5);
- y = (lat2 - lat1);
- distance = sqrt((x * x) + (y * y)) * GRN_GEO_RADIUS;
}
return distance;
}