server-side-google-maps 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -55,11 +55,7 @@ module ServerSideGoogleMaps
55
55
  distance_step = 1.0 * total_distance / (n - 1)
56
56
 
57
57
  ret = []
58
- ret << Point.new(
59
- points[0].latitude,
60
- points[0].longitude,
61
- :distance_along_path => points[0].distance_along_path
62
- )
58
+ ret << create_interpolated_point(points[0], points[0], 0.0, :distance_along_path => points[0].distance_along_path)
63
59
 
64
60
  j = 0
65
61
  current_distance = points[0].distance_along_path
@@ -74,24 +70,29 @@ module ServerSideGoogleMaps
74
70
  point_segment_length = point_after.distance_along_path - point_before.distance_along_path
75
71
 
76
72
  fraction_after = (1.0 * current_distance - point_before.distance_along_path) / point_segment_length
77
- fraction_before = 1.0 - fraction_after
78
73
 
79
- ret << Point.new(
80
- fraction_before * point_before.latitude + fraction_after * point_after.latitude,
81
- fraction_before * point_before.longitude + fraction_after * point_after.longitude,
82
- :distance_along_path => current_distance.round
83
- )
74
+ ret << create_interpolated_point(point_before, point_after, fraction_after, :distance_along_path => current_distance.to_i)
84
75
  end
85
76
 
86
- ret << Point.new(
87
- points[-1].latitude,
88
- points[-1].longitude,
89
- :distance_along_path => points[-1].distance_along_path
90
- )
77
+ ret << create_interpolated_point(points[-1], points[-1], 0.0, :distance_along_path => points[-1].distance_along_path)
91
78
  end
92
79
 
93
80
  private
94
81
 
82
+ def create_interpolated_point(point_before, point_after, fraction_after, options = {})
83
+ fraction_before = 1.0 - fraction_after
84
+
85
+ if point_before.elevation && point_after.elevation && options[:elevation].nil?
86
+ options = options.merge(:elevation => fraction_before * point_before.elevation + fraction_after * point_after.elevation)
87
+ end
88
+
89
+ Point.new(
90
+ fraction_before * point_before.latitude + fraction_after * point_after.latitude,
91
+ fraction_before * point_before.longitude + fraction_after * point_after.longitude,
92
+ options
93
+ )
94
+ end
95
+
95
96
  def encoded_path
96
97
  @encoded_path ||= ::GoogleMapsPolyline::Encoder.new(StringIO.new).encode_points(points_1e5).string
97
98
  end
@@ -1,3 +1,3 @@
1
1
  module ServerSideGoogleMaps
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/spec/path_spec.rb CHANGED
@@ -105,6 +105,16 @@ module ServerSideGoogleMaps
105
105
  interpolated[6].distance_along_path.should == 666039
106
106
  interpolated[7].should == p3
107
107
  end
108
+
109
+ it('should interpolate elevations') do
110
+ p1 = Point.new(1.0, 1.0, :elevation => 10)
111
+ p2 = Point.new(2.0, 2.0, :elevation => 50)
112
+ path = Path.new([p1, p2])
113
+ interpolated = path.interpolate(5)
114
+ interpolated[0].elevation.should == 10
115
+ interpolated[1].elevation.should == 20
116
+ interpolated[4].elevation.should == 50
117
+ end
108
118
  end
109
119
  end
110
120
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: server-side-google-maps
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Hooper