Merge pull request #42 from SebKuzminsky/line-line-intersect

Fix Line.intersect(Line) (bug #41)
pull/48/head
Andy Port 2018-02-27 22:38:33 -08:00 committed by GitHub
commit 29a49197a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 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 np.isclose(denom, 0):
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]) -

View File

@ -991,6 +991,19 @@ class Test_intersect(unittest.TestCase):
self.assertTrue(len(yix), 1) self.assertTrue(len(yix), 1)
################################################################### ###################################################################
def test_line_line_0(self):
l0 = Line(start=(25.389999999999997+99.989999999999995j), end=(25.389999999999997+90.484999999999999j))
l1 = Line(start=(25.390000000000001+84.114999999999995j), end=(25.389999999999997+74.604202137430320j))
i = l0.intersect(l1)
assert(len(i)) == 0
def test_line_line_1(self):
l0 = Line(start=(-124.705378549+327.696674827j), end=(12.4926214511+121.261674827j))
l1 = Line(start=(-12.4926214511+121.261674827j), end=(124.705378549+327.696674827j))
i = l0.intersect(l1)
assert(len(i)) == 1
assert(abs(l0.point(i[0][0])-l1.point(i[0][1])) < 1e-9)
class TestPathTools(unittest.TestCase): class TestPathTools(unittest.TestCase):
# moved from test_pathtools.py # moved from test_pathtools.py