Opened 13 years ago

Closed 12 years ago

# [with patch, positive review] plot3d fails with 'IndexError: list index out of range'

Reported by: Owned by: jhpalmieri was minor sage-3.2 graphics

### Description

```sage: def g(x,y):
...            if y <= 0 or y >= x**2:
...                return 0
...           else:
...               return 1
sage: plot3d(g, (-3, 3), (-3, 3), adaptive=True)
```

fails, returning

```Traceback (most recent call last):
File "<stdin>", line 1, in <module>
7.py", line 6, in <module>
plot3d(g, (-Integer(3), Integer(3)), (-Integer(3), Integer(3)),
File "/usr/local/share/sage/local/lib/python2.5/site-packages/
SQLAlchemy-0.4.6-py2.5.egg/", line 1, in <module>
File "/home/palmieri/Documents/sage-3.1.2/local/lib/python2.5/site-
packages/sage/plot/plot3d/plot3d.py", line 157, in plot3d
P = plot3d_adaptive(f, urange, vrange, **kwds)
File "/home/palmieri/Documents/sage-3.1.2/local/lib/python2.5/site-
G.set_texture(texture[k], opacity=opacity)
IndexError: list index out of range
```

### comment:1 Changed 13 years ago by jhpalmieri

• Summary changed from plot3d fails with 'IndexError: list index out of range' to [with patch, needs review] plot3d fails with 'IndexError: list index out of range'

Here's a patch. I was getting an index error in the last line in this code snippet:

```                span = len(texture) / (max_z - min_z)    # max to avoid dividing by 0
parts = P.partition(lambda x,y,z: int((z-min_z)*span))
all = []
for k, G in parts.iteritems():
G.set_texture(texture[k], opacity=opacity)
```

The function g(x,y) described above is discontinuous at various places, and I think this was making the `k` in the last line of this snippet equal to 128 while `len(texture)` was also 128. Changing the definition of `span` in the first line, as this patch does, I hope should make `k` always strictly less than `len(texture)`.

### comment:2 Changed 12 years ago by anakha

• Summary changed from [with patch, needs review] plot3d fails with 'IndexError: list index out of range' to [with patch, positive review] plot3d fails with 'IndexError: list index out of range'

This does fix the problem and looks ok.

### comment:3 Changed 12 years ago by mabshoff

• Resolution set to fixed
• Status changed from new to closed

Merged in Sage 3.2.alpha1

Note: See TracTickets for help on using tickets.