[Groonga-commit] groonga/groonga [master] test: calculate distance by approximate_type "rectangle"

Back to archive index

null+****@clear***** null+****@clear*****
2012年 5月 21日 (月) 18:44:32 JST


HAYASHI Kentaro	2012-05-21 18:44:32 +0900 (Mon, 21 May 2012)

  New Revision: b79f57d962fcd24c9b97847d97e1b668e3d26284

  Log:
    test: calculate distance by approximate_type "rectangle"

  Modified files:
    test/function/tools/geo/generate-grntest-data.rb

  Modified: test/function/tools/geo/generate-grntest-data.rb (+17 -1)
===================================================================
--- test/function/tools/geo/generate-grntest-data.rb    2012-05-21 18:42:40 +0900 (fa1b4e7)
+++ test/function/tools/geo/generate-grntest-data.rb    2012-05-21 18:44:32 +0900 (1ecc1d6)
@@ -20,6 +20,9 @@ SELECT = "select Geo --output_columns distance "
 SELECT_PRE = "[[0,0.0,0.0],[[[1],[[\"distance\",\"Int32\"]],["
 SELECT_POST = "]]]]"
 
+GRN_GEO_RESOLUTION=3600000
+GRN_GEO_RADIUS=6357303
+
 class GrnTestData
   attr_accessor :csv_file
   attr_accessor :options
@@ -414,8 +417,21 @@ class GrnTestData
             SELECT, scorer, select_postfix)
   end
 
+  def geo_int2rad(value)
+    ((Math::PI / (GRN_GEO_RESOLUTION * 180)) * (value))
+  end
+
   def geo_distance(app_type)
-    0
+    case app_type
+    when "", "rect", "rectangle"
+      lat1 = geo_int2rad(@latitude_start_degree)
+      lng1 = geo_int2rad(@longitude_start_degree)
+      lat2 = geo_int2rad(@latitude_end_degree)
+      lng2 = geo_int2rad(@longitude_end_degree)
+      x = (lng2 - lng1) * Math.cos((lat1 + lat2) * 0.5)
+      y = (lat2 - lat1)
+      return (Math.sqrt((x * x) + (y * y)) * GRN_GEO_RADIUS).floor
+    end
   end
 
   def generate_expected_data(app_type)




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