I'm looking at the code and can't see how this can happen unless the
grid is larger than the resolution of the drawing area. MASON uses AWT
graphics, and so cuts things down to integers. If you scale down to the
point that, for example, the width of your sparse grid is less than the
pixels in your drawing area, some of those cut-downs will be to zero width.
But if this is not the case, then I'm stumped. Here's the relevant code
newinfo.draw.x = (int)(info.draw.x + (xScale) * loc.x);
newinfo.draw.y = (int)(info.draw.y + (yScale) * loc.y);
newinfo.draw.width = (int)(info.draw.x + (xScale) * (loc.x+1)) -
newinfo.draw.height = (int)(info.draw.y + (yScale) * (loc.y+1)) -
info.draw.x and y are the <x,y> coordinates of the top-left position of
the drawing area in your window. loc.x and loc.y are the location of
the grid item to draw. They're integers. xScale and yScale are the
width or height of the drawing area divided by the maximum extent of the
grid (field.getWidth() etc.). They're doubles.
If xScale is a value >= 1.0, then I believe width *must* be a number
larger than 1.0, and thus cut down to an integer > 1, except for huge
numbers which your screen resolution can't display anyway. I think the
math is right.
Pelle Evensen wrote:
> Sean Luke wrote:
>> Now that's interesting. Is the problem just that you're seeing 0
>> width and 0 height, or that this triggers something which freaks out?
>> In any case, could you create a stack trace when this occurs?
> If it's any help, the width is at most off by one, so if I have scale 1
> => width = 0.0 or 1.0, scale 16 => width = 15.0 or 16.0. Like I said
> earlier, this is only for *some* calls to draw. The version of MASON is
> the CVS version from Monday some time and the JRE is 6_0_7.
> Naughtiness; DrawInfo2D: DrawInfo2D[ Draw:
> java.awt.geom.Rectangle2D$Double[x=88.0,y=9.0,w=0.0,h=0.0] Clip:
> java.lang.Exception: Stack trace
> at java.lang.Thread.dumpStack(Thread.java:1206)
> at barterBugs.BasicAgentPortrayal.draw(BasicAgentPortrayal.java:99)
> at sim.portrayal.FieldPortrayal2D.draw(FieldPortrayal2D.java:55)
> at sim.display.Display2D$InnerDisplay2D.paint(Display2D.java:395)
> at javax.swing.JComponent.paint(JComponent.java:1027)
> at javax.swing.JComponent.paintToOffscreen(JComponent.java:5122)
> at javax.swing.RepaintManager.paint(RepaintManager.java:1217)
> at javax.swing.JComponent._paintImmediately(JComponent.java:5070)
> at javax.swing.JComponent.paintImmediately(JComponent.java:4880)
> at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:803)
> at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
> at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
> at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
> at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)