[Groonga-commit] groonga/groonga [master] test: add a method to check direction

Zurück zum Archiv-Index

null+****@clear***** null+****@clear*****
2012年 5月 18日 (金) 16:28:56 JST


HAYASHI Kentaro	2012-05-18 16:28:56 +0900 (Fri, 18 May 2012)

  New Revision: 97d3a14aa87cee49f0930bdca1d177e181b01de0

  Log:
    test: add a method to check direction

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

  Modified: test/function/tools/geo/generate-grntest-data.rb (+87 -0)
===================================================================
--- test/function/tools/geo/generate-grntest-data.rb    2012-05-18 15:00:19 +0900 (27a79fe)
+++ test/function/tools/geo/generate-grntest-data.rb    2012-05-18 16:28:56 +0900 (3d9fe79)
@@ -237,6 +237,93 @@ class GrnTestData
     start_longitude == end_longitude and start_latitude == end_latitude
   end
 
+  def longitude_equal?
+    @longitude_start_degree == @longitude_end_degree
+  end
+
+  def latitude_equal?
+    @latitude_start_degree == @latitude_end_degree
+  end
+
+  def to_north?(check_longitude=true)
+    if check_longitude
+      longitude_equal? and @latitude_start_degree < @latitude_end_degree
+    else
+      @latitude_start_degree < @latitude_end_degree
+    end
+  end
+
+  def to_east?(check_latitude=true)
+    if check_latitude
+      latitude_equal? and @longitude_start_degree < @longitude_end_degree
+    else
+      @longitude_start_degree < @longitude_end_degree
+    end
+  end
+
+  def to_west?(check_latitude=true)
+    if check_latitude
+      latitude_equal? and @longitude_start_degree > @longitude_end_degree
+    else
+      @longitude_start_degree > @longitude_end_degree
+    end
+  end
+
+  def to_south?(check_longitude=true)
+    if check_longitude
+      longitude_equal? and @latitude_start_degree > @latitude_end_degree
+    else
+      @latitude_start_degree > @latitude_end_degree
+    end
+  end
+
+  def to_north_east?
+    to_north?(false) and to_east?(false)
+  end
+
+  def to_north_west?
+    to_north?(false) and to_west?(false)
+  end
+
+  def to_south_east?
+    to_south?(false) and to_east?(false)
+  end
+
+  def to_south_west?
+    to_south?(false) and to_west?(false)
+  end
+
+  def direction
+    is_point = point?(@longitude_start_degree, @latitude_start_degree,
+                      @longitude_end_degree, @latitude_end_degree)
+    if is_point
+      ""
+    else
+      if within_specified_quadrant?("1st") or
+         within_specified_quadrant?("2nd") or
+         within_specified_quadrant?("3rd") or
+         within_specified_quadrant?("4th")
+        if to_north?
+          "north"
+        elsif to_east?
+          "east"
+        elsif to_west?
+          "west"
+        elsif to_south?
+          "south_west"
+        elsif to_north_east?
+          "north_east"
+        elsif to_north_west?
+          "north_west"
+        elsif to_south_east?
+          "south_east"
+        elsif to_south_west?
+          "south_west"
+        end
+      end
+    end
+  end
+
   def generate_filename
     s = get_point(@longitude_start_degree, @latitude_start_degree)
     e = get_point(@longitude_end_degree, @latitude_end_degree)




Groonga-commit メーリングリストの案内
Zurück zum Archiv-Index