Add Google Map of voters
[selectricity-live] / vendor / plugins / ym4r_gm / lib / gm_plugin / point.rb
diff --git a/vendor/plugins/ym4r_gm/lib/gm_plugin/point.rb b/vendor/plugins/ym4r_gm/lib/gm_plugin/point.rb
new file mode 100644 (file)
index 0000000..bcde4e2
--- /dev/null
@@ -0,0 +1,34 @@
+module Ym4r\r
+  module GmPlugin\r
+    #A point in pixel coordinates\r
+    class GPoint < Struct.new(:x,:y)\r
+      include MappingObject\r
+      def create\r
+        "new GPoint(#{x},#{y})"\r
+      end\r
+    end\r
+    #A rectangular that contains all the pixel points passed as arguments\r
+    class GBounds\r
+      include MappingObject\r
+      attr_accessor :points\r
+      #Accepts both an array of GPoint and an array of 2-element arrays\r
+      def initialize(points)\r
+        if !points.empty? and points[0].is_a?(Array)\r
+          @points = points.collect { |pt| GPoint.new(pt[0],pt[1]) }\r
+        else\r
+          @points = points\r
+        end\r
+      end\r
+      def create\r
+        "new GBounds([#{@points.map { |pt| pt.to_javascript}.join(",")}])"\r
+      end\r
+    end\r
+    #A size object, in pixel space\r
+    class GSize < Struct.new(:width,:height)\r
+      include MappingObject\r
+      def create\r
+        "new GSize(#{width},#{height})"\r
+      end\r
+    end\r
+  end\r
+end\r

Benjamin Mako Hill || Want to submit a patch?