deal with float rounding error in Line.intersect(Line)

This commit fixes #41.

In the test case added in the previous commit, two non-intersecting lines
are very nearly collinear, but float rounding errors lead to incorrect
intersections reported.

This commit makes Line.intersect() treat denominators below 1e-9 as 0,
to make it more accepting of float rounding.
pull/42/head
Sebastian Kuzminsky 2018-01-06 23:15:43 -07:00
parent 847b270bc2
commit fc34d2c4cf
1 changed files with 1 additions and 1 deletions

View File

@ -572,7 +572,7 @@ class Line(object):
d = (other_seg.start.imag, other_seg.end.imag) d = (other_seg.start.imag, other_seg.end.imag)
denom = ((a[1] - a[0])*(d[0] - d[1]) - denom = ((a[1] - a[0])*(d[0] - d[1]) -
(b[1] - b[0])*(c[0] - c[1])) (b[1] - b[0])*(c[0] - c[1]))
if denom == 0: if denom < 1e-9:
return [] return []
t1 = (c[0]*(b[0] - d[1]) - t1 = (c[0]*(b[0] - d[1]) -
c[1]*(b[0] - d[0]) - c[1]*(b[0] - d[0]) -