Revision: 3914
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3914&view=rev
Author:   mdboom
Date:     2007-10-04 11:57:27 -0700 (Thu, 04 Oct 2007)

Log Message:
-----------
Progress on agg_buffer_to_array example.

Modified Paths:
--------------
    branches/transforms/examples/agg_buffer_to_array.py
    branches/transforms/examples/polar_demo.py
    branches/transforms/lib/matplotlib/artist.py
    branches/transforms/lib/matplotlib/image.py
    branches/transforms/lib/matplotlib/projections/polar.py
    branches/transforms/lib/matplotlib/transforms.py
    branches/transforms/src/_backend_agg.cpp
    branches/transforms/src/_backend_agg.h

Modified: branches/transforms/examples/agg_buffer_to_array.py
===================================================================
--- branches/transforms/examples/agg_buffer_to_array.py 2007-10-04 17:22:01 UTC 
(rev 3913)
+++ branches/transforms/examples/agg_buffer_to_array.py 2007-10-04 18:57:27 UTC 
(rev 3914)
@@ -12,7 +12,7 @@
 
 # grab rhe pixel buffer and dumpy it into a numpy array
 buf = fig.canvas.buffer_rgba(0,0)
-l, b, w, h = fig.bbox.get_bounds()
+l, b, w, h = fig.bbox.bounds
 X = npy.fromstring(buf, npy.uint8)
 X.shape = h,w,4
 

Modified: branches/transforms/examples/polar_demo.py
===================================================================
--- branches/transforms/examples/polar_demo.py  2007-10-04 17:22:01 UTC (rev 
3913)
+++ branches/transforms/examples/polar_demo.py  2007-10-04 18:57:27 UTC (rev 
3914)
@@ -40,7 +40,7 @@
 # information on how to customize the grid locations and labels
 
 import numpy as npy
-from matplotlib.pyplot import figure, show, rc
+from matplotlib.pyplot import figure, show, rc, grid
 
 # radar green, solid grid lines
 rc('grid', color='#316931', linewidth=1, linestyle='-')
@@ -55,6 +55,7 @@
 theta = 2*npy.pi*r
 ax.plot(theta, r, color='#ee8d18', lw=3)
 ax.set_rmax(2.0)
+grid(True)
 
 ax.set_title("And there was much rejoicing!", fontsize=20)
 show()

Modified: branches/transforms/lib/matplotlib/artist.py
===================================================================
--- branches/transforms/lib/matplotlib/artist.py        2007-10-04 17:22:01 UTC 
(rev 3913)
+++ branches/transforms/lib/matplotlib/artist.py        2007-10-04 18:57:27 UTC 
(rev 3914)
@@ -350,7 +350,7 @@
     def _set_gc_clip(self, gc):
         'set the clip properly for the gc'
         if self.clipbox is not None:
-            gc.set_clip_rectangle(self.clipbox.bounds)
+            gc.set_clip_rectangle(self.clipbox)
         gc.set_clip_path(self._clippath)
 
     def draw(self, renderer, *args, **kwargs):

Modified: branches/transforms/lib/matplotlib/image.py
===================================================================
--- branches/transforms/lib/matplotlib/image.py 2007-10-04 17:22:01 UTC (rev 
3913)
+++ branches/transforms/lib/matplotlib/image.py 2007-10-04 18:57:27 UTC (rev 
3914)
@@ -149,17 +149,17 @@
         dyintv = ymax-ymin
 
         # the viewport scale factor
-        sx = dxintv/self.axes.viewLim.width()
-        sy = dyintv/self.axes.viewLim.height()
+        sx = dxintv/self.axes.viewLim.width
+        sy = dyintv/self.axes.viewLim.height
 
         if im.get_interpolation()!=_image.NEAREST:
             im.apply_translation(-1, -1)
 
         # the viewport translation
-        tx = (xmin-self.axes.viewLim.xmin())/dxintv * numcols
-        ty = (ymin-self.axes.viewLim.ymin())/dyintv * numrows
+        tx = (xmin-self.axes.viewLim.xmin)/dxintv * numcols
+        ty = (ymin-self.axes.viewLim.ymin)/dyintv * numrows
 
-        l, b, widthDisplay, heightDisplay = self.axes.bbox.get_bounds()
+        l, b, widthDisplay, heightDisplay = self.axes.bbox.bounds
         widthDisplay *= magnification
         heightDisplay *= magnification
 
@@ -180,8 +180,9 @@
     def draw(self, renderer, *args, **kwargs):
         if not self.get_visible(): return
         im = self.make_image(renderer.get_image_magnification())
-        l, b, widthDisplay, heightDisplay = self.axes.bbox.get_bounds()
-        renderer.draw_image(l, b, im, self.axes.bbox)
+        l, b, widthDisplay, heightDisplay = self.axes.bbox.bounds
+        print self.axes.bbox.frozen()
+        renderer.draw_image(l, b, im, self.axes.bbox.frozen())
 
     def contains(self, mouseevent):
         """Test whether the mouse event occured within the image.

Modified: branches/transforms/lib/matplotlib/projections/polar.py
===================================================================
--- branches/transforms/lib/matplotlib/projections/polar.py     2007-10-04 
17:22:01 UTC (rev 3913)
+++ branches/transforms/lib/matplotlib/projections/polar.py     2007-10-04 
18:57:27 UTC (rev 3914)
@@ -12,14 +12,29 @@
     IdentityTransform, Transform, TransformWrapper
 
 class PolarAxes(Axes):
+    """
+    A polar graph projection, where the input dimensions are theta, r.
+
+    Theta starts pointing east and goes anti-clockwise.
+    """
     name = 'polar'
     
     class PolarTransform(Transform):
+        """
+        The base polar transform.  This handles projection theta and r into
+        Cartesian coordinate space, but does not perform the ultimate affine
+        transformation into the correct position.
+        """
         input_dims = 2
         output_dims = 2
         is_separable = False
 
         def __init__(self, resolution):
+            """
+            Create a new polar transform.  Resolution is the number of steps
+            to interpolate between each input line segment to approximate its
+            path in curved polar space.
+            """
             Transform.__init__(self)
             self._resolution = resolution
 
@@ -32,19 +47,34 @@
             x += r * npy.cos(t)
             y += r * npy.sin(t)
             return xy
+        transform.__doc__ = Transform.transform.__doc__
+
         transform_non_affine = transform
+        transform_non_affine.__doc__ = Transform.transform_non_affine.__doc__
 
         def transform_path(self, path):
             if len(path.vertices) == 2:
                 path = path.interpolated(self._resolution)
             return Path(self.transform(path.vertices), path.codes)
+        transform_path.__doc__ = Transform.transform_path.__doc__
+        
         transform_path_non_affine = transform_path
+        transform_path_non_affine.__doc__ = 
Transform.transform_path_non_affine.__doc__
         
         def inverted(self):
             return PolarAxes.InvertedPolarTransform()
+        inverted.__doc__ = Transform.inverted.__doc__
 
     class PolarAffine(Affine2DBase):
+        """
+        The affine part of the polar projection.  Scales the output so
+        that maximum radius rests on the edge of the axes circle.
+        """
         def __init__(self, limits):
+            """
+            limits is the view limit of the data.  The only part of
+            its bounds that is used is ymax (for the radius maximum).
+            """
             Affine2DBase.__init__(self)
             self._limits = limits
             self.set_children(limits)
@@ -60,8 +90,13 @@
                 self._inverted = None
                 self._invalid = 0
             return self._mtx
+        get_matrix.__doc__ = Affine2DBase.get_matrix.__doc__
     
     class InvertedPolarTransform(Transform):
+        """
+        The inverse of the polar transform, mapping Cartesian
+        coordinate space back to t and r.
+        """
         input_dims = 2
         output_dims = 2
         is_separable = False
@@ -73,21 +108,34 @@
             theta = npy.arccos(x / r)
             theta = npy.where(y < 0, 2 * npy.pi - theta, theta)
             return npy.concatenate((theta, r), 1)
+        transform.__doc__ = Transform.transform.__doc__
 
         def inverted(self):
             return PolarAxes.PolarTransform()
+        inverted.__doc__ = Transform.inverted.__doc__
 
     class ThetaFormatter(Formatter):
+        """
+        Used to format the theta tick labels.  Converts the native
+        unit of radians into degrees and adds a degree symbol.
+        """
         def __call__(self, x, pos=None):
+            # \u00b0 : degree symbol
             return u"%d\u00b0" % ((x / npy.pi) * 180.0)
 
     class RadialLocator(Locator):
+        """
+        Used to locate radius ticks.
+        
+        Ensures that all ticks are strictly positive.  For all other
+        tasks, it delegates to the base Locator (which may be
+        different depending on the scale of the r-axis.
+        """
         def __init__(self, base):
             self.base = base
 
         def __call__(self):
             ticks = self.base()
-            # MGDTODO: Use numpy
             return [x for x in ticks if x > 0]
 
         def autoscale(self):
@@ -105,6 +153,10 @@
     RESOLUTION = 100
         
     def __init__(self, *args, **kwargs):
+        """
+        Create a new Polar Axes for a polar plot.
+        """
+        
         self._rpad = 0.05
         Axes.__init__(self, *args, **kwargs)
         self.set_aspect('equal', adjustable='box', anchor='C')
@@ -120,7 +172,7 @@
         
self.yaxis.set_major_locator(self.RadialLocator(self.yaxis.get_major_locator()))
 
     def _set_lim_and_transforms(self):
-       self.dataLim = Bbox([[0.0, 0.0], [npy.pi * 2.0, 1.0]])
+       self.dataLim = Bbox.unit()
         self.viewLim = Bbox.unit()
         self.transAxes = BboxTransform(Bbox.unit(), self.bbox)
 
@@ -134,14 +186,20 @@
         # An affine transformation on the data, generally to limit the
         # range of the axes
         self.transProjectionAffine = self.PolarAffine(self.viewLim)
-        
+
+        # The complete data transformation stack -- from data all the
+        # way to display coordinates
         self.transData = self.transScale + self.transProjection + \
             (self.transProjectionAffine + self.transAxes)
 
+        # This is the transform for theta-axis ticks.  It is
+        # equivalent to transData, except it always puts r == 1.0 at
+        # the edge of the axis circle.
         self._xaxis_transform = (
             self.transProjection +
             self.PolarAffine(Bbox.unit()) +
             self.transAxes)
+        # The theta labels are moved from radius == 0.0 to radius == 1.1
         self._theta_label1_position = Affine2D().translate(0.0, 1.1)
         self._xaxis_text1_transform = (
             self._theta_label1_position +
@@ -150,10 +208,14 @@
         self._xaxis_text2_transform = (
             self._theta_label2_position +
             self._xaxis_transform)
-        
+
+        # This is the transform for r-axis ticks.  It scales the theta
+        # axis so the gridlines from 0.0 to 1.0, now go from 0.0 to
+        # 2pi.
         self._yaxis_transform = (
             Affine2D().scale(npy.pi * 2.0, 1.0) +
             self.transData)
+        # The r-axis labels are put at an angle and padded in the r-direction
         self._r_label1_position = Affine2D().translate(22.5, self._rpad)
         self._yaxis_text1_transform = (
             self._r_label1_position +
@@ -166,6 +228,9 @@
             Affine2D().scale(1.0 / 360.0, 1.0) +
             self._yaxis_transform
             )
+
+    def get_xaxis_transform(self):
+        return self._xaxis_transform
         
     def get_xaxis_text1_transform(self, pixelPad):
         return self._xaxis_text1_transform, 'center', 'center'
@@ -173,6 +238,9 @@
     def get_xaxis_text2_transform(self, pixelPad):
         return self._xaxis_text2_transform, 'center', 'center'
 
+    def get_yaxis_transform(self):
+        return self._yaxis_transform
+    
     def get_yaxis_text1_transform(self, pixelPad):
         return self._yaxis_text1_transform, 'center', 'center'
 
@@ -181,63 +249,7 @@
     
     def get_axes_patch(self):
         return Circle((0.5, 0.5), 0.5)
-
-    def start_pan(self, x, y, button):
-        angle = self._r_label1_position.to_values()[4] / 180.0 * npy.pi
-        mode = ''
-        if button == 1:
-            epsilon = npy.pi / 45.0
-            t, r = self.transData.inverted().transform_point((x, y))
-            if t >= angle - epsilon and t <= angle + epsilon:
-                mode = 'drag_r_labels'
-        elif button == 3:
-            mode = 'zoom'
             
-        self._pan_start = cbook.Bunch(
-            rmax          = self.get_rmax(),
-            trans         = self.transData.frozen(),
-            trans_inverse = self.transData.inverted().frozen(),
-            r_label_angle = self._r_label1_position.to_values()[4],
-            x             = x,
-            y             = y,
-            mode          = mode
-            )
-
-    def end_pan(self):
-        del self._pan_start
-                                       
-    def drag_pan(self, button, key, x, y):
-        p = self._pan_start
-        
-        if p.mode == 'drag_r_labels':
-            startt, startr = p.trans_inverse.transform_point((p.x, p.y))
-            t, r = p.trans_inverse.transform_point((x, y))
-            
-            # Deal with theta
-            dt0 = t - startt
-            dt1 = startt - t
-            if abs(dt1) < abs(dt0):
-                dt = abs(dt1) * sign(dt0) * -1.0
-            else:
-                dt = dt0 * -1.0
-            dt = (dt / npy.pi) * 180.0
-
-            rpad = self._r_label1_position.to_values()[5]
-            self._r_label1_position.clear().translate(
-                p.r_label_angle - dt, rpad)
-            self._r_label2_position.clear().translate(
-                p.r_label_angle - dt, -rpad)
-            
-        elif p.mode == 'zoom':
-            startt, startr = p.trans_inverse.transform_point((p.x, p.y))
-            t, r = p.trans_inverse.transform_point((x, y))
-            
-            dr = r - startr
-
-            # Deal with r
-            scale = r / startr
-            self.set_rmax(p.rmax / scale)
-            
     def set_rmax(self, rmax):
         self.viewLim.ymax = rmax
         angle = self._r_label1_position.to_values()[4]
@@ -249,6 +261,11 @@
     def get_rmax(self):
         return self.viewLim.ymax
 
+    def set_yscale(self, *args, **kwargs):
+        Axes.set_yscale(self, *args, **kwargs)
+        self.yaxis.set_major_locator(
+            self.RadialLocator(self.yaxis.get_major_locator()))
+    
     set_rscale = Axes.set_yscale
     set_rticks = Axes.set_yticks
 
@@ -330,24 +347,19 @@
         
     set_rgrids.__doc__ = cbook.dedent(set_rgrids.__doc__) % kwdocd
     
-    def set_rscale(self, *args, **kwargs):
-        return self.set_yscale(*args, **kwargs)
-
     def set_xscale(self, *args, **kwargs):
         raise NotImplementedError("You can not set the xscale on a polar 
plot.")
 
-    def set_yscale(self, *args, **kwargs):
-        Axes.set_yscale(self, *args, **kwargs)
-        self.yaxis.set_major_locator(
-            self.RadialLocator(self.yaxis.get_major_locator()))
-    
     def set_xlim(self, *args, **kargs):
-        # The xlim's a fixed, no matter what you do
+        # The xlim is fixed, no matter what you do
         self.viewLim.intervalx = (0.0, npy.pi * 2.0)
     
     def format_coord(self, theta, r):
         'return a format string formatting the coordinate'
         theta /= math.pi
+        # \u03b8: lower-case theta
+        # \u03c0: lower-case pi
+        # \u00b0: degree symbol
         return u'\u03b8=%0.3f\u03c0 (%0.3f\u00b0), r=%0.3f' % (theta, theta * 
180.0, r)
 
     def get_data_ratio(self):
@@ -356,7 +368,65 @@
         this should always be 1.0
         '''
         return 1.0
+
+    ### Interactive panning
     
+    def start_pan(self, x, y, button):
+        angle = self._r_label1_position.to_values()[4] / 180.0 * npy.pi
+        mode = ''
+        if button == 1:
+            epsilon = npy.pi / 45.0
+            t, r = self.transData.inverted().transform_point((x, y))
+            if t >= angle - epsilon and t <= angle + epsilon:
+                mode = 'drag_r_labels'
+        elif button == 3:
+            mode = 'zoom'
+            
+        self._pan_start = cbook.Bunch(
+            rmax          = self.get_rmax(),
+            trans         = self.transData.frozen(),
+            trans_inverse = self.transData.inverted().frozen(),
+            r_label_angle = self._r_label1_position.to_values()[4],
+            x             = x,
+            y             = y,
+            mode          = mode
+            )
+
+    def end_pan(self):
+        del self._pan_start
+                                       
+    def drag_pan(self, button, key, x, y):
+        p = self._pan_start
+        
+        if p.mode == 'drag_r_labels':
+            startt, startr = p.trans_inverse.transform_point((p.x, p.y))
+            t, r = p.trans_inverse.transform_point((x, y))
+            
+            # Deal with theta
+            dt0 = t - startt
+            dt1 = startt - t
+            if abs(dt1) < abs(dt0):
+                dt = abs(dt1) * sign(dt0) * -1.0
+            else:
+                dt = dt0 * -1.0
+            dt = (dt / npy.pi) * 180.0
+
+            rpad = self._r_label1_position.to_values()[5]
+            self._r_label1_position.clear().translate(
+                p.r_label_angle - dt, rpad)
+            self._r_label2_position.clear().translate(
+                p.r_label_angle - dt, -rpad)
+            
+        elif p.mode == 'zoom':
+            startt, startr = p.trans_inverse.transform_point((p.x, p.y))
+            t, r = p.trans_inverse.transform_point((x, y))
+            
+            dr = r - startr
+
+            # Deal with r
+            scale = r / startr
+            self.set_rmax(p.rmax / scale)
+    
 # These are a couple of aborted attempts to project a polar plot using
 # cubic bezier curves.
         

Modified: branches/transforms/lib/matplotlib/transforms.py
===================================================================
--- branches/transforms/lib/matplotlib/transforms.py    2007-10-04 17:22:01 UTC 
(rev 3913)
+++ branches/transforms/lib/matplotlib/transforms.py    2007-10-04 18:57:27 UTC 
(rev 3914)
@@ -191,7 +191,7 @@
         return Bbox(self.get_points().copy())
     frozen.__doc__ = TransformNode.__doc__
     
-    def __array__(self):
+    def __array__(self, *args, **kwargs):
         return self.get_points()
 
     def _get_xmin(self):

Modified: branches/transforms/src/_backend_agg.cpp
===================================================================
--- branches/transforms/src/_backend_agg.cpp    2007-10-04 17:22:01 UTC (rev 
3913)
+++ branches/transforms/src/_backend_agg.cpp    2007-10-04 18:57:27 UTC (rev 
3914)
@@ -187,7 +187,6 @@
 
 GCAgg::GCAgg(const Py::Object &gc, double dpi, bool snapto) :
   dpi(dpi), snapto(snapto), isaa(true), linewidth(1.0), alpha(1.0),
-  cliprect(NULL), 
   Ndash(0), dashOffset(0.0), dasha(NULL)
 {
   _VERBOSE("GCAgg::GCAgg");
@@ -295,34 +294,14 @@
   }
 }
 
-// MGDTODO: Convert directly from Bbox object (numpy)
 void
 GCAgg::_set_clip_rectangle( const Py::Object& gc) {
   //set the clip rectangle from the gc
   
   _VERBOSE("GCAgg::_set_clip_rectangle");
-  
-  delete [] cliprect;
-  cliprect = NULL;
-  
+
   Py::Object o ( gc.getAttr( "_cliprect" ) );
-  if (o.ptr() == Py_None) {
-    return;
-  }
-  
-  Py::SeqBase<Py::Object> rect( o );
-  
-  double l = Py::Float(rect[0]) ;
-  double b = Py::Float(rect[1]) ;
-  double w = Py::Float(rect[2]) ;
-  double h = Py::Float(rect[3]) ;
-  
-  cliprect = new double[4];
-  //todo check for memory alloc failure
-  cliprect[0] = l;
-  cliprect[1] = b;
-  cliprect[2] = w;
-  cliprect[3] = h;
+  cliprect = o;
 }
 
 void
@@ -387,25 +366,29 @@
   
 };
 
-
 template<class R>
 void
-RendererAgg::set_clipbox(double *cliprect, R rasterizer) {
+RendererAgg::set_clipbox(Py::Object& cliprect, R rasterizer) {
   //set the clip rectangle from the gc
   
   _VERBOSE("RendererAgg::set_clipbox");
 
-  if (cliprect!=NULL) {
+  if (cliprect.ptr() != Py_None) {
+    PyArrayObject* bbox = (PyArrayObject*) PyArray_FromObject(cliprect.ptr(), 
PyArray_DOUBLE, 2, 2);   
+
+    if (!bbox || bbox->nd != 2 || bbox->dimensions[0] != 2 || 
bbox->dimensions[1] != 2)
+      throw Py::TypeError
+       ("Expected a Bbox object.");
     
-    double l = cliprect[0] ;
-    double b = cliprect[1] ;
-    double w = cliprect[2] ;
-    double h = cliprect[3] ;
-    
-    rasterizer->clip_box((int)l, (int)(height-(b+h)), (int)(l+w), 
(int)(height-b));
+    double l = *(double*)PyArray_GETPTR2(bbox, 0, 0);
+    double b = *(double*)PyArray_GETPTR2(bbox, 0, 1);
+    double r = *(double*)PyArray_GETPTR2(bbox, 1, 0);
+    double t = *(double*)PyArray_GETPTR2(bbox, 1, 1);
+
+    rasterizer->clip_box((int)l, (int)(height-t), (int)r, (int)(height-b));
   }
+
   _VERBOSE("RendererAgg::set_clipbox done");
-  
 }
 
 std::pair<bool, agg::rgba>
@@ -485,17 +468,24 @@
 RendererAgg::copy_from_bbox(const Py::Tuple& args) {
   //copy region in bbox to buffer and return swig/agg buffer object
   args.verify_length(1);
+
+  Py::Object box_obj = args[0];
+
+  PyArrayObject* bbox = (PyArrayObject*) PyArray_FromObject(box_obj.ptr(), 
PyArray_DOUBLE, 2, 2);   
   
+  if (!bbox || bbox->nd != 2 || bbox->dimensions[0] != 2 || 
bbox->dimensions[1] != 2)
+    throw Py::TypeError
+      ("Expected a Bbox object.");
+    
+  double l = *(double*)PyArray_GETPTR2(bbox, 0, 0);
+  double b = *(double*)PyArray_GETPTR2(bbox, 0, 1);
+  double r = *(double*)PyArray_GETPTR2(bbox, 1, 0);
+  double t = *(double*)PyArray_GETPTR2(bbox, 1, 1);
   
-  agg::rect r = bbox_to_rect<int>(args[0]);
-  /*
-    r.x1 -=5;
-    r.y1 -=5;
-    r.x2 +=5;
-    r.y2 +=5;
-  */
-  int boxwidth = r.x2-r.x1;
-  int boxheight = r.y2-r.y1;
+  agg::rect rect((int)l, (int)(height-t), (int)r, (int)(height-b));
+
+  int boxwidth = rect.x2-rect.x1;
+  int boxheight = rect.y2-rect.y1;
   int boxstride = boxwidth*4;
   agg::buffer buf(boxwidth, boxheight, boxstride, false);
   if (buf.data ==NULL) {
@@ -508,8 +498,8 @@
   pixfmt pf(rbuf);
   renderer_base rb(pf);
   //rb.clear(agg::rgba(1, 0, 0)); //todo remove me
-  rb.copy_from(*renderingBuffer, &r, -r.x1, -r.y1);
-  BufferRegion* reg = new BufferRegion(buf, r, true);
+  rb.copy_from(*renderingBuffer, &rect, -rect.x1, -rect.y1);
+  BufferRegion* reg = new BufferRegion(buf, rect, true);
   return Py::asObject(reg);
 }
 
@@ -535,64 +525,6 @@
   return Py::Object();
 }
 
-/**
- * Helper function to convert a Python Bbox object to an agg rectangle
- */
-template<class T>
-agg::rect_base<T>
-RendererAgg::bbox_to_rect(const Py::Object& o) {
-  //return the agg::rect for bbox, flipping y
-  PyArrayObject *bbox = (PyArrayObject *) 
PyArray_ContiguousFromObject(o.ptr(), PyArray_DOUBLE, 2, 2);
-
-  if (!bbox || bbox->nd != 2 || bbox->dimensions[0] != 2 || 
bbox->dimensions[1] != 2)
-    throw Py::TypeError
-      ("Expected a Bbox object.");
-
-  double l = bbox->data[0];
-  double b = bbox->data[1];
-  double r = bbox->data[2];
-  double t = bbox->data[3];
-  T height = (T)(b - t);
-  
-  agg::rect_base<T> rect((T)l, height-(T)t, (T)r, height-(T)b ) ;
-  if (!rect.is_valid())
-    throw Py::ValueError("Invalid rectangle in bbox_to_rect");
-  return rect;
-}
-
-void
-RendererAgg::set_clip_from_bbox(const Py::Object& o) {
-  
-  // do not puut this in the else below.  We want to unconditionally
-  // clear the clip
-  theRasterizer->reset_clipping();
-  rendererBase->reset_clipping(true);
-  
-  if (o.ptr() != Py_None) {  //using clip
-    // Bbox::check(args[0]) failing; something about cross module?
-    // set the clip rectangle
-    // flipy
-    agg::rect_base<double> r = bbox_to_rect<double>(o);
-    theRasterizer->clip_box(r.x1, r.y1, r.x2, r.y2);
-    rendererBase->clip_box((int)r.x1, (int)r.y1, (int)r.x2, (int)r.y2);
-  }
-  
-}
-
-/****************************/
-
-int RendererAgg::intersectCheck(double yCoord, double x1, double y1, double 
x2, double y2, int* intersectPoint)
-{
-  /* Returns 0 if no intersection or 1 if yes */
-  /* If yes, changes intersectPoint to the x coordinate of the point of 
intersection */
-  if ((y1>=yCoord) != (y2>=yCoord)) {
-    /* Don't need to check for y1==y2 because the above condition rejects it 
automatically */
-    *intersectPoint = (int)( ( x1 * (y2 - yCoord) + x2 * (yCoord - y1) ) / (y2 
- y1) + 0.5);
-    return 1;
-  }
-  return 0;
-}
-
 bool RendererAgg::render_clippath(const GCAgg& gc) {
   typedef agg::conv_transform<PathIterator> transformed_path_t;
   typedef agg::conv_curve<transformed_path_t> curve_t;
@@ -633,6 +565,7 @@
   typedef agg::renderer_scanline_aa_solid<amask_ren_type> 
amask_aa_renderer_type;
   typedef agg::renderer_scanline_bin_solid<amask_ren_type> 
amask_bin_renderer_type;
 
+  rendererBase->reset_clipping(true);
   theRasterizer->reset_clipping();
   
   args.verify_length(5, 6);
@@ -802,6 +735,7 @@
 
 };
 
+// MGDTODO: Support clip paths
 Py::Object
 RendererAgg::draw_text_image(const Py::Tuple& args) {
   _VERBOSE("RendererAgg::draw_text");
@@ -877,6 +811,7 @@
 }
 
 
+// MGDTODO: Support clip paths
 Py::Object
 RendererAgg::draw_image(const Py::Tuple& args) {
   _VERBOSE("RendererAgg::draw_image");
@@ -885,8 +820,11 @@
   float x = Py::Float(args[0]);
   float y = Py::Float(args[1]);
   Image *image = static_cast<Image*>(args[2].ptr());
+  Py::Object box_obj = args[3];
   
-  set_clip_from_bbox(args[3]);
+  theRasterizer->reset_clipping();
+  rendererBase->reset_clipping(true);
+  set_clipbox(box_obj, rendererBase);
   
   pixfmt pixf(*(image->rbufOut));
   

Modified: branches/transforms/src/_backend_agg.h
===================================================================
--- branches/transforms/src/_backend_agg.h      2007-10-04 17:22:01 UTC (rev 
3913)
+++ branches/transforms/src/_backend_agg.h      2007-10-04 18:57:27 UTC (rev 
3914)
@@ -111,7 +111,6 @@
 
   ~GCAgg() {
     delete [] dasha;
-    delete [] cliprect;
   }
 
   double dpi;
@@ -126,7 +125,7 @@
   double alpha;
   agg::rgba color;
 
-  double *cliprect;
+  Py::Object cliprect;
   Py::Object clippath;
   agg::trans_affine clippath_trans;
 
@@ -214,16 +213,12 @@
   const int debug;
 
 protected:
-  template<class T>
-  agg::rect_base<T> bbox_to_rect( const Py::Object& o);
   double points_to_pixels( const Py::Object& points);
   double points_to_pixels_snapto( const Py::Object& points);
-  int intersectCheck(double, double, double, double, double, int*);
-  void set_clip_from_bbox(const Py::Object& o);
   agg::rgba rgb_to_color(const Py::SeqBase<Py::Object>& rgb, double alpha);
   facepair_t _get_rgba_face(const Py::Object& rgbFace, double alpha);
   template<class R>
-  void set_clipbox(double *cliprect, R rasterizer);
+  void set_clipbox(Py::Object& cliprect, R rasterizer);
   bool render_clippath(const GCAgg& gc);
 
 private:


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to