'The intersection of polygon and geometry entity.
The intersection may be empty and can contain individual Points and
complete Line Segments.
Parameters
other: GeometryEntity
Returns
intersection : list
The list of Segments and Points
See Also
sympy.geometry.point.Point, sympy.geometry.line.Segment
Examples
>>> from sympy import Point, Polygon, Line
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly1 = Polygon(p1, p2, p3, p4)
>>> p5, p6, p7 = map(Point, [(3, 2), (1, -1), (0, 2)])
>>> poly2 = Polygon(p5, p6, p7)
>>> poly1.intersection(poly2)
[Point2D(1/3, 1), Point2D(2/3, 0), Point2D(9/5, 1/5), Point2D(7/3, 1)]
>>> poly1.intersection(Line(p1, p2))
[Segment2D(Point2D(0, 0), Point2D(1, 0))]
>>> poly1.intersection(p1)
[Point2D(0, 0)]'

def intersection(self, o):

    intersection_result = []
    k = (o.sides if isinstance(o, Polygon) else [o])
    for side in self.sides:
        for side1 in k:
            intersection_result.extend(side.intersection(side1))
    intersection_result = list(uniq(intersection_result))
    points = [entity for entity in intersection_result if isinstance(entity, Point)]
    segments = [entity for entity in intersection_result if isinstance(entity, Segment)]
    if (points and segments):
        points_in_segments = list(uniq([point for point in points for segment in segments if (point in segment)]))
        if points_in_segments:
            for i in points_in_segments:
                points.remove(i)
        return list(ordered((segments + points)))
    else:
        return list(ordered(intersection_result))
