[pypy-svn] r7501 - pypy/trunk/src/pypy/translator/tool/pygame

mgedmin at codespeak.net mgedmin at codespeak.net
Sat Nov 20 12:51:30 CET 2004


Author: mgedmin
Date: Sat Nov 20 12:51:30 2004
New Revision: 7501

Modified:
   pypy/trunk/src/pypy/translator/tool/pygame/drawgraph.py
Log:
I just got an OverflowError while trying to zoom in a big function flow graph.
This checkin adds extra clipping code that should prevent such errors.



Modified: pypy/trunk/src/pypy/translator/tool/pygame/drawgraph.py
==============================================================================
--- pypy/trunk/src/pypy/translator/tool/pygame/drawgraph.py	(original)
+++ pypy/trunk/src/pypy/translator/tool/pygame/drawgraph.py	Sat Nov 20 12:51:30 2004
@@ -276,11 +276,21 @@
 
         self.ofsx = noffsetx
         self.ofsy = noffsety
-    
+
     def getboundingbox(self):
         "Get the rectangle where the graph will be rendered."
         return (-self.ofsx, -self.ofsy, self.width, self.height)
 
+    def visible(self, x1, y1, x2, y2):
+        "Is any part of the box visible (i.e. within the bounding box)?
+
+        We have to perform clipping ourselves because with big graphs the
+        coordinates may sometimes become longs and cause OverflowErrors
+        within pygame.
+        "
+        return (x1 < self.width-self.ofsx and x2 > -self.ofsx and
+                y1 < self.height-self.ofsy and y2 > -self.ofsy)
+
     def map(self, x, y):
         return (int(x*self.scale) - (self.ofsx - self.margin),
                 int((self.bboxh-y)*self.scale) - (self.ofsy - self.margin))
@@ -392,7 +402,7 @@
             if edge.highlight:
                 fgcolor = highlight_color(fgcolor)
             points = [self.map(*xy) for xy in edge.bezierpoints()]
-            
+
             def drawedgebody(points=points, fgcolor=fgcolor):
                 pygame.draw.lines(self.screen, fgcolor, False, points)
             edgebodycmd.append(drawedgebody)
@@ -402,14 +412,15 @@
                 def drawedgehead(points=points, fgcolor=fgcolor):
                     pygame.draw.polygon(self.screen, fgcolor, points, 0)
                 edgeheadcmd.append(drawedgehead)
-            
+
             if edge.label:
                 x, y = self.map(edge.xl, edge.yl)
                 img = TextSnippet(self, edge.label, (0, 0, 0))
                 w, h = img.get_size()
-                def drawedgelabel(img=img, x1=x-w//2, y1=y-h//2):
-                    img.draw(x1, y1)
-                edgeheadcmd.append(drawedgelabel)
+                if self.visible(x-w//2, y-h//2, x+w//2, y+h//2):
+                    def drawedgelabel(img=img, x1=x-w//2, y1=y-h//2):
+                        img.draw(x1, y1)
+                    edgeheadcmd.append(drawedgelabel)
 
         return edgebodycmd + nodebkgndcmd + edgeheadcmd + nodecmd
 



More information about the Pypy-commit mailing list