Class: ServerSideGoogleMaps::Segment

Inherits:
Object
  • Object
show all
Defined in:
lib/server-side-google-maps/segment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(point1, point2) ⇒ Segment

Returns a new instance of Segment.



5
6
7
8
# File 'lib/server-side-google-maps/segment.rb', line 5

def initialize(point1, point2)
  @first = point1
  @last = point2
end

Instance Attribute Details

#firstObject (readonly)

Returns the value of attribute first.



3
4
5
# File 'lib/server-side-google-maps/segment.rb', line 3

def first
  @first
end

#lastObject (readonly)

Returns the value of attribute last.



3
4
5
# File 'lib/server-side-google-maps/segment.rb', line 3

def last
  @last
end

Instance Method Details

#dlatObject



10
11
12
# File 'lib/server-side-google-maps/segment.rb', line 10

def dlat
  @dlat ||= last.latitude - first.latitude
end

#dlonObject



14
15
16
# File 'lib/server-side-google-maps/segment.rb', line 14

def dlon
  @dlon ||= last.longitude - first.longitude
end

#length2Object



18
19
20
# File 'lib/server-side-google-maps/segment.rb', line 18

def length2
  @length2 ||= dlat * dlat + dlon * dlon
end

#to_aObject



22
23
24
# File 'lib/server-side-google-maps/segment.rb', line 22

def to_a
  [first, last]
end