Class: Mapper
- Inherits:
-
Array
- Object
- Array
- Mapper
- Defined in:
- lib/mapper.rb
Instance Attribute Summary collapse
-
#reference_point1 ⇒ Object
readonly
Returns the value of attribute reference_point1.
-
#reference_point2 ⇒ Object
readonly
Returns the value of attribute reference_point2.
-
#x_factor ⇒ Object
readonly
Returns the value of attribute x_factor.
-
#y_factor ⇒ Object
readonly
Returns the value of attribute y_factor.
-
#zero_point ⇒ Object
readonly
Returns the value of attribute zero_point.
Instance Method Summary collapse
- #add_point(point) ⇒ Object
- #get_coords(point = {:lon=>0.0,:lat=>0.0}) ⇒ Object
-
#initialize(reference_point1 = {:lat=>0.0,:lon=>0.0,:x=>0,:y=>0}, reference_point2 = {:lat=>0.0,:lon=>0.0,:x=>0,:y=>0}) ⇒ Mapper
constructor
A new instance of Mapper.
Constructor Details
#initialize(reference_point1 = {:lat=>0.0,:lon=>0.0,:x=>0,:y=>0}, reference_point2 = {:lat=>0.0,:lon=>0.0,:x=>0,:y=>0}) ⇒ Mapper
Returns a new instance of Mapper.
5 6 7 8 9 10 11 |
# File 'lib/mapper.rb', line 5 def initialize(reference_point1={:lat=>0.0,:lon=>0.0,:x=>0,:y=>0}, reference_point2={:lat=>0.0,:lon=>0.0,:x=>0,:y=>0}) @reference_point1 = reference_point1; @reference_point2 = reference_point2 @x_factor = (reference_point1[:x] - reference_point2[:x]) / (reference_point1[:lon] - reference_point2[:lon]).to_f @y_factor = (reference_point1[:y] - reference_point2[:y]) / (reference_point1[:lat] - reference_point2[:lat]).to_f @zero_point = {:lon => reference_point1[:lon] - reference_point1[:x] / @x_factor, :x => 0, :lat => reference_point1[:lat] - reference_point1[:y] / @y_factor, :y => 0} end |
Instance Attribute Details
#reference_point1 ⇒ Object (readonly)
Returns the value of attribute reference_point1.
2 3 4 |
# File 'lib/mapper.rb', line 2 def reference_point1 @reference_point1 end |
#reference_point2 ⇒ Object (readonly)
Returns the value of attribute reference_point2.
2 3 4 |
# File 'lib/mapper.rb', line 2 def reference_point2 @reference_point2 end |
#x_factor ⇒ Object (readonly)
Returns the value of attribute x_factor.
3 4 5 |
# File 'lib/mapper.rb', line 3 def x_factor @x_factor end |
#y_factor ⇒ Object (readonly)
Returns the value of attribute y_factor.
3 4 5 |
# File 'lib/mapper.rb', line 3 def y_factor @y_factor end |
#zero_point ⇒ Object (readonly)
Returns the value of attribute zero_point.
2 3 4 |
# File 'lib/mapper.rb', line 2 def zero_point @zero_point end |
Instance Method Details
#add_point(point) ⇒ Object
21 22 23 |
# File 'lib/mapper.rb', line 21 def add_point(point) self << get_coords(point) end |
#get_coords(point = {:lon=>0.0,:lat=>0.0}) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/mapper.rb', line 13 def get_coords( point={:lon=>0.0,:lat=>0.0} ) point.merge!(:x => (point[:lon] - @zero_point[:lon]) * @x_factor) if point[:lon] && !point[:x] point.merge!(:y => (point[:lat] - @zero_point[:lat]) * @y_factor) if point[:lat] && !point[:y] point.merge!(:lon => (point[:x] / @x_factor) + @zero_point[:lon]) if point[:x] && !point[:lon] point.merge!(:lat => (point[:y] / @y_factor) + @zero_point[:lat]) if point[:y] && !point[:lat] point end |