'SVG representation of a GeometryEntity suitable for IPython'

def _repr_svg_(self):

    from sympy.core.evalf import N
    try:
        bounds = self.bounds
    except (NotImplementedError, TypeError):
        return None
    svg_top = '<svg    xmlns="http://www.w3.org/2000/svg"\n                                                xmlns:xlink="http://www.w3.org/1999/xlink"\n                                                width="{1}"    height="{2}"    viewBox="{0}"\n                                                preserveAspectRatio="xMinYMin    meet">\n                                                <defs>\n                                                                <marker    id="markerCircle"    markerWidth="8"    markerHeight="8"\n                                                                                refx="5"    refy="5"    markerUnits="strokeWidth">\n                                                                                <circle    cx="5"    cy="5"    r="1.5"    style="stroke:    none;    fill:#000000;"/>\n                                                                </marker>\n                                                                <marker    id="markerArrow"    markerWidth="13"    markerHeight="13"    refx="2"    refy="4"\n                                                                                            orient="auto"    markerUnits="strokeWidth">\n                                                                                <path    d="M2,2    L2,6    L6,4"    style="fill:    #000000;"    />\n                                                                </marker>\n                                                                <marker    id="markerReverseArrow"    markerWidth="13"    markerHeight="13"    refx="6"    refy="4"\n                                                                                            orient="auto"    markerUnits="strokeWidth">\n                                                                                <path    d="M6,2    L6,6    L2,4"    style="fill:    #000000;"    />\n                                                                </marker>\n                                                </defs>'
    (xmin, ymin, xmax, ymax) = map(N, bounds)
    if ((xmin == xmax) and (ymin == ymax)):
        (xmin, ymin, xmax, ymax) = ((xmin - 0.5), (ymin - 0.5), (xmax + 0.5), (ymax + 0.5))
    else:
        expand = 0.1
        widest_part = max([(xmax - xmin), (ymax - ymin)])
        expand_amount = (widest_part * expand)
        xmin -= expand_amount
        ymin -= expand_amount
        xmax += expand_amount
        ymax += expand_amount
    dx = (xmax - xmin)
    dy = (ymax - ymin)
    width = min([max([100.0, dx]), 300])
    height = min([max([100.0, dy]), 300])
    scale_factor = (1.0 if (max(width, height) == 0) else (max(dx, dy) / max(width, height)))
    try:
        svg = self._svg(scale_factor)
    except (NotImplementedError, TypeError):
        return None
    view_box = '{0}    {1}    {2}    {3}'.format(xmin, ymin, dx, dy)
    transform = 'matrix(1,0,0,-1,0,{0})'.format((ymax + ymin))
    svg_top = svg_top.format(view_box, width, height)
    return (svg_top + '<g    transform="{0}">{1}</g></svg>'.format(transform, svg))
