]> projects.mako.cc - selectricity-live/blob - vendor/plugins/ym4r_gm/lib/gm_plugin/point.rb
licensed under the AGPL
[selectricity-live] / vendor / plugins / ym4r_gm / lib / gm_plugin / point.rb
1 module Ym4r\r
2   module GmPlugin\r
3     #A point in pixel coordinates\r
4     class GPoint < Struct.new(:x,:y)\r
5       include MappingObject\r
6       def create\r
7         "new GPoint(#{x},#{y})"\r
8       end\r
9     end\r
10     #A rectangular that contains all the pixel points passed as arguments\r
11     class GBounds\r
12       include MappingObject\r
13       attr_accessor :points\r
14       #Accepts both an array of GPoint and an array of 2-element arrays\r
15       def initialize(points)\r
16         if !points.empty? and points[0].is_a?(Array)\r
17           @points = points.collect { |pt| GPoint.new(pt[0],pt[1]) }\r
18         else\r
19           @points = points\r
20         end\r
21       end\r
22       def create\r
23         "new GBounds([#{@points.map { |pt| pt.to_javascript}.join(",")}])"\r
24       end\r
25     end\r
26     #A size object, in pixel space\r
27     class GSize < Struct.new(:width,:height)\r
28       include MappingObject\r
29       def create\r
30         "new GSize(#{width},#{height})"\r
31       end\r
32     end\r
33   end\r
34 end\r

Benjamin Mako Hill || Want to submit a patch?