Skip to content

Commit

Permalink
Merge pull request #1 from smichr/geom
Browse files Browse the repository at this point in the history
test flyback removal in Polygon"
  • Loading branch information
akshayah3 committed Apr 11, 2014
2 parents d88f9cf + 0196335 commit 270b0aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 4 additions & 1 deletion sympy/geometry/polygon.py
Expand Up @@ -146,9 +146,12 @@ def __new__(cls, *args, **kwargs):
i = -3
while i < len(nodup) - 3 and len(nodup) > 2:
a, b, c = nodup[i], nodup[i + 1], nodup[i + 2]
# if flyback lines are desired then the following should
# only be done if tuple(sorted((a, b, c))) == (a, b, c)
if b not in shared and Point.is_collinear(a, b, c):
nodup[i] = a
nodup.pop(i + 1)
if a == c:
nodup.pop(i)
i += 1

vertices = list(nodup)
Expand Down
12 changes: 8 additions & 4 deletions sympy/geometry/tests/test_geometry.py
Expand Up @@ -677,10 +677,14 @@ def test_ellipse_random_point():


def test_polygon():
t = Triangle(Point(0, 0), Point(2, 0), Point(3, 3))
assert Polygon(Point(0, 0), Point(1, 0), Point(2, 0), Point(3, 3)) == t
assert Polygon(Point(1, 0), Point(2, 0), Point(3, 3), Point(0, 0)) == t
assert Polygon(Point(2, 0), Point(3, 3), Point(0, 0), Point(1, 0)) == t
a, b, c = Point(0, 0), Point(2, 0), Point(3, 3)
t = Triangle(a, b, c)
assert Polygon(a, Point(1, 0), b, c) == t
assert Polygon(Point(1, 0), b, c, a) == t
assert Polygon(b, c, a, Point(1, 0)) == t
# 2 "remove flyback" tests
assert Polygon(a, Point(3, 0), b, c) == t
assert Polygon(a, b, Point(3, -1), b, c) == t

p1 = Polygon(
Point(0, 0), Point(3, -1),
Expand Down

0 comments on commit 270b0aa

Please sign in to comment.