Ticket #10948: trac_10948_point3d-sl.patch

File trac_10948_point3d-sl.patch, 2.1 KB (added by slabbe, 8 years ago)
  • sage/plot/plot3d/shapes2.py

    # HG changeset patch
    # User Sebastien Labbe <slabqc at gmail.com>
    # Date 1300308736 14400
    # Node ID 2ee27b88384e32839c9a921e62d09315928aeb74
    # Parent  7692a0902797e202f3226a02bdd8d4d00b5e3169
    #10948: Calling point on an iterator of 3d points raises an AttributeError
    
    diff --git a/sage/plot/plot3d/shapes2.py b/sage/plot/plot3d/shapes2.py
    a b def point3d(v, size=5, **kwds): 
    10141014    We check to make sure the options work::
    10151015
    10161016        sage: point3d((4,3,2),size=20,color='red',opacity=.5)
    1017        
     1017
     1018    TESTS::
     1019
     1020        sage: point3d([])
     1021        sage: point3d(iter([]))
     1022        sage: point3d((i,i,i) for i in range(10))
     1023
    10181024    """
    10191025    if (isinstance(v,(list,tuple)) or is_Vector(v)) and len(v) == 3 and not (isinstance(v[0],(list,tuple)) or is_Vector(v[0])):
    10201026        return Point(v, size, **kwds)
    10211027    else:
    1022         A = sum([Point(z, size, **kwds) for z in v])
     1028        from sage.plot.plot3d.base import Graphics3d
     1029        A = sum([Point(z, size, **kwds) for z in v], Graphics3d())
    10231030        A._set_extra_kwds(kwds)
    10241031        return A
    10251032   
  • sage/plot/point.py

    diff --git a/sage/plot/point.py b/sage/plot/point.py
    a b TESTS:: 
    2626#                  http://www.gnu.org/licenses/
    2727#*****************************************************************************
    2828from sage.misc.decorators import options, rename_keyword
     29from sage.misc.misc import is_iterator
    2930from sage.plot.colors import to_mpl_color
    3031from sage.plot.primitive import GraphicPrimitive_xydata
    3132
    def point(points, **kwds): 
    304305
    305306        sage: point([(cos(theta), sin(theta)) for theta in srange(0, 2*pi, pi/8)], frame=True)
    306307        sage: point([(cos(theta), sin(theta)) for theta in srange(0, 2*pi, pi/8)]).show(frame=True) # These are equivalent
     308
     309    Also works for iterator input (trac: #10948)::
     310
     311        sage: point((i,i,i) for i in range(10))
     312
     313    TESTS::
     314
     315        sage: point(iter([]))
    307316    """
     317    if is_iterator(points):
     318        points = list(points)
    308319    try:
    309320        return point2d(points, **kwds)
    310321    except (ValueError, TypeError):