Skip to content

Instantly share code, notes, and snippets.

@musically-ut
Created December 31, 2011 19:54
Show Gist options
  • Save musically-ut/1545147 to your computer and use it in GitHub Desktop.
Save musically-ut/1545147 to your computer and use it in GitHub Desktop.
Testing line intersections.
def test_intersects():
line_1 = ((0, 0), (1, 1))
line_2 = ((2.5, 2.5), (1.5, 1.5)) # No intersection
assert not intersects(line_1, line_2)
line_1 = ((0, 0), (1, 1))
line_2 = ((0, 0.5), (1, 0.5)) # Intersects
assert intersects(line_1, line_2)
line_1 = ((0, 0), (1, 1))
line_2 = ((0.5, 0.5), (1.5, 1.5)) # Overlaps
assert intersects(line_1, line_2)
line_1 = ((0, 0), (1, 1))
line_2 = ((0.5, 0.5), (1, .5)) # One point on line
assert intersects(line_1, line_2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment