Permalink
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...
joshuaclayton committed May 30, 2012
1 parent 2fc0f9a commit ee318e11bb9019f57a0d26e201314d3cd9204ee1
Showing with 14 additions and 0 deletions.
  1. +2 −0 lib/polylines/base.rb
  2. +6 −0 spec/polylines/decoder_spec.rb
  3. +6 −0 spec/polylines/encoder_spec.rb
View
@@ -37,6 +37,8 @@ def step_6
numbers.unshift(current_value & 0x1f)
@current_value >>= 5
end
+
+ numbers << 0 if numbers.empty?
end
end
@@ -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
@@ -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

0 comments on commit ee318e1

Please sign in to comment.