Skip to content

Commit

Permalink
Merge pull request #10 from jayjlawrence/master
Browse files Browse the repository at this point in the history
Handle case where line has identical start and end points
  • Loading branch information
DanielVartanov committed Jun 2, 2014
2 parents 0874a89 + d82e6b6 commit 5242624
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/segment.rb
Expand Up @@ -71,6 +71,8 @@ def distance_to(point)
p1 = point1.to_vector
p2 = point2.to_vector

return Geometry.distance(q, p1) if p1 == p2

u = p2 - p1
v = q - p1

Expand Down
8 changes: 7 additions & 1 deletion test/segment/distance_to_test.rb
Expand Up @@ -28,4 +28,10 @@ def test_distance_to_segment_end
assert_equal 1, segment.distance_to(point)
end

end
def test_distance_to_point_segment
segment = Segment.new_by_arrays([0, 1], [0, 1])
point = Point.new(1, 1)
assert_equal 1, segment.distance_to(point)
end

end

0 comments on commit 5242624

Please sign in to comment.