DISJOINT = 0
OVERWRAPPING = 1
def intersect_point(x1, y1, x2, y2, x3, y3, x4, y4):
if not geometry.is_intersecting(x1, y1, x2, y2, x3, y3, x4, y4):
return DISJOINT
denom = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)
if denom:
t1, t2 = x1 * y2 - y1 * x2, x3 * y4 - y3 * x4
x = ((x3 - x4) * t1 - (x1 - x2) * t2) / denom
y = ((y3 - y4) * t1 - (y1 - y2) * t2) / denom
return (x, y)
else:
p1, p2, p3, p4 = sorted([(x1, y1), (x2, y2), (x3, y3), (x4, y4)])
return p2 if p2 == p3 else OVERWRAPPING