Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Handle very close points

When step 2's result is 0 (due to points being very close), later steps
(six and up) depend on at least one value being present in the array.
Default to 0 if nothing is present after breaking into 5-bit chunks.

Closes #1
  • Loading branch information...
commit ee318e11bb9019f57a0d26e201314d3cd9204ee1 1 parent 2fc0f9a
@joshuaclayton authored
View
2  lib/polylines/base.rb
@@ -37,6 +37,8 @@ def step_6
numbers.unshift(current_value & 0x1f)
@current_value >>= 5
end
+
+ numbers << 0 if numbers.empty?
end
end
View
6 spec/polylines/decoder_spec.rb
@@ -14,3 +14,9 @@
Polylines::Decoder.decode_polyline(polyline).should == points
end
end
+
+describe Polylines::Decoder, ".decode_polyline with points that were close together" do
+ it "decodes a polyline correctly" do
+ Polylines::Decoder.decode_polyline("krk{FdxdlO?e@").should == [[41.35222, -86.04563],[41.35222, -86.04544]]
+ end
+end
View
6 spec/polylines/encoder_spec.rb
@@ -14,3 +14,9 @@
Polylines::Encoder.encode_points(points).should == polyline
end
end
+
+describe Polylines::Encoder, ".encode_points that are very close together" do
+ it "encodes points correctly" do
+ Polylines::Encoder.encode_points([[41.3522171071184, -86.0456299662023],[41.3522171071183, -86.0454368471533]]).should == "krk{FdxdlO?e@"
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.