From 01963354f20de41a79c41039482d62533d3a27ab Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Fri, 11 Apr 2014 04:26:23 -0500 Subject: [PATCH] test flyback removal in Polygon --- sympy/geometry/polygon.py | 5 ++++- sympy/geometry/tests/test_geometry.py | 12 ++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/sympy/geometry/polygon.py b/sympy/geometry/polygon.py index c0f16ea9a6f4..ce9fdf8b1b91 100644 --- a/sympy/geometry/polygon.py +++ b/sympy/geometry/polygon.py @@ -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) diff --git a/sympy/geometry/tests/test_geometry.py b/sympy/geometry/tests/test_geometry.py index 06e1257dcf14..c5ddc526592d 100644 --- a/sympy/geometry/tests/test_geometry.py +++ b/sympy/geometry/tests/test_geometry.py @@ -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),