Revision: 8561
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8561&view=rev
Author:   mdboom
Date:     2010-07-16 18:45:49 +0000 (Fri, 16 Jul 2010)

Log Message:
-----------
Able to produce simple_plot.py!!!

Modified Paths:
--------------
    branches/py3k/examples/pylab_examples/simple_plot.py
    branches/py3k/lib/matplotlib/artist.py
    branches/py3k/lib/matplotlib/axes.py
    branches/py3k/lib/matplotlib/backends/backend_agg.py
    branches/py3k/lib/matplotlib/backends/tkagg.py
    branches/py3k/lib/matplotlib/docstring.py
    branches/py3k/lib/matplotlib/figure.py
    branches/py3k/lib/matplotlib/font_manager.py
    branches/py3k/lib/matplotlib/lines.py
    branches/py3k/lib/matplotlib/mlab.py
    branches/py3k/lib/matplotlib/patches.py
    branches/py3k/lib/matplotlib/text.py
    branches/py3k/setup.py
    branches/py3k/setupext.py
    branches/py3k/src/_backend_agg.cpp
    branches/py3k/src/_png.cpp

Removed Paths:
-------------
    branches/py3k/src/nxutils.c

Modified: branches/py3k/examples/pylab_examples/simple_plot.py
===================================================================
--- branches/py3k/examples/pylab_examples/simple_plot.py        2010-07-16 
13:55:35 UTC (rev 8560)
+++ branches/py3k/examples/pylab_examples/simple_plot.py        2010-07-16 
18:45:49 UTC (rev 8561)
@@ -8,4 +8,5 @@
 ylabel('voltage (mV)')
 title('About as simple as it gets, folks')
 grid(True)
+savefig("test.png")
 show()

Modified: branches/py3k/lib/matplotlib/artist.py
===================================================================
--- branches/py3k/lib/matplotlib/artist.py      2010-07-16 13:55:35 UTC (rev 
8560)
+++ branches/py3k/lib/matplotlib/artist.py      2010-07-16 18:45:49 UTC (rev 
8561)
@@ -481,7 +481,7 @@
         :class:`~matplotlib.transforms.Transform`) |
         :class:`~matplotlib.patches.Patch` | None ]
         """
-        from patches import Patch, Rectangle
+        from matplotlib.patches import Patch, Rectangle
 
         success = False
         if transform is None:

Modified: branches/py3k/lib/matplotlib/axes.py
===================================================================
--- branches/py3k/lib/matplotlib/axes.py        2010-07-16 13:55:35 UTC (rev 
8560)
+++ branches/py3k/lib/matplotlib/axes.py        2010-07-16 18:45:49 UTC (rev 
8561)
@@ -1,5 +1,5 @@
 from __future__ import division, generators
-import math, sys, warnings, datetime, new
+import math, sys, warnings, datetime
 from operator import itemgetter
 import itertools
 
@@ -8400,9 +8400,15 @@
 
     new_class = _subplot_classes.get(axes_class)
     if new_class is None:
-        new_class = new.classobj("%sSubplot" % (axes_class.__name__),
-                                 (SubplotBase, axes_class),
-                                 {'_axes_class': axes_class})
+        if sys.hexversion >= 0x03000000:
+            new_class = type("%sSubplot" % (axes_class.__name__),
+                             (SubplotBase, axes_class),
+                             {'_axes_class': axes_class})
+        else:
+            import new
+            new_class = new.classobj("%sSubplot" % (axes_class.__name__),
+                                     (SubplotBase, axes_class),
+                                     {'_axes_class': axes_class})
         _subplot_classes[axes_class] = new_class
 
     return new_class

Modified: branches/py3k/lib/matplotlib/backends/backend_agg.py
===================================================================
--- branches/py3k/lib/matplotlib/backends/backend_agg.py        2010-07-16 
13:55:35 UTC (rev 8560)
+++ branches/py3k/lib/matplotlib/backends/backend_agg.py        2010-07-16 
18:45:49 UTC (rev 8561)
@@ -35,7 +35,7 @@
 from matplotlib.path import Path
 from matplotlib.transforms import Bbox, BboxBase
 
-from _backend_agg import RendererAgg as _RendererAgg
+from matplotlib.backends._backend_agg import RendererAgg as _RendererAgg
 from matplotlib import _png
 
 backend_version = 'v2.2'
@@ -429,7 +429,7 @@
         original_dpi = renderer.dpi
         renderer.dpi = self.figure.dpi
         if is_string_like(filename_or_obj):
-            filename_or_obj = file(filename_or_obj, 'wb')
+            filename_or_obj = open(filename_or_obj, 'wb')
         renderer._renderer.write_rgba(filename_or_obj)
         renderer.dpi = original_dpi
     print_rgba = print_raw
@@ -440,7 +440,7 @@
         original_dpi = renderer.dpi
         renderer.dpi = self.figure.dpi
         if is_string_like(filename_or_obj):
-            filename_or_obj = file(filename_or_obj, 'wb')
+            filename_or_obj = open(filename_or_obj, 'wb')
         _png.write_png(renderer._renderer.buffer_rgba(0, 0),
                        renderer.width, renderer.height,
                        filename_or_obj, self.figure.dpi)

Modified: branches/py3k/lib/matplotlib/backends/tkagg.py
===================================================================
--- branches/py3k/lib/matplotlib/backends/tkagg.py      2010-07-16 13:55:35 UTC 
(rev 8560)
+++ branches/py3k/lib/matplotlib/backends/tkagg.py      2010-07-16 18:45:49 UTC 
(rev 8561)
@@ -1,4 +1,4 @@
-import _tkagg
+from matplotlib import _tkagg
 import Tkinter as Tk
 
 def blit(photoimage, aggimage, bbox=None, colormode=1):

Modified: branches/py3k/lib/matplotlib/docstring.py
===================================================================
--- branches/py3k/lib/matplotlib/docstring.py   2010-07-16 13:55:35 UTC (rev 
8560)
+++ branches/py3k/lib/matplotlib/docstring.py   2010-07-16 18:45:49 UTC (rev 
8561)
@@ -1,29 +1,31 @@
 from matplotlib import cbook
+import sys
+import types
 
 class Substitution(object):
     """
     A decorator to take a function's docstring and perform string
     substitution on it.
-    
+
     This decorator should be robust even if func.__doc__ is None
     (for example, if -OO was passed to the interpreter)
-    
+
     Usage: construct a docstring.Substitution with a sequence or
     dictionary suitable for performing substitution; then
     decorate a suitable function with the constructed object. e.g.
-    
+
     sub_author_name = Substitution(author='Jason')
-    
+
     @sub_author_name
     def some_function(x):
         "%(author)s wrote this function"
-    
+
     # note that some_function.__doc__ is now "Jason wrote this function"
-    
+
     One can also use positional arguments.
-    
+
     sub_first_last_names = Substitution('Edgar Allen', 'Poe')
-    
+
     @sub_first_last_names
     def some_function(x):
         "%s %s wrote the Raven"
@@ -56,16 +58,16 @@
     """
     A function decorator that will append an addendum to the docstring
     of the target function.
-    
+
     This decorator should be robust even if func.__doc__ is None
     (for example, if -OO was passed to the interpreter).
-    
+
     Usage: construct a docstring.Appender with a string to be joined to
     the original docstring. An optional 'join' parameter may be supplied
     which will be used to join the docstring and addendum. e.g.
-    
+
     add_copyright = Appender("Copyright (c) 2009", join='\n')
-    
+
     @add_copyright
     def my_dog(has='fleas'):
         "This docstring will have a copyright below"
@@ -100,6 +102,8 @@
 def dedent_interpd(func):
     """A special case of the interpd that first performs a dedent on
     the incoming docstring"""
+    if isinstance(func, types.MethodType) and sys.hexversion <= 0x03000000:
+        func = func.im_func
     return interpd(dedent(func))
 
 def copy_dedent(source):

Modified: branches/py3k/lib/matplotlib/figure.py
===================================================================
--- branches/py3k/lib/matplotlib/figure.py      2010-07-16 13:55:35 UTC (rev 
8560)
+++ branches/py3k/lib/matplotlib/figure.py      2010-07-16 18:45:49 UTC (rev 
8561)
@@ -17,7 +17,7 @@
 from artist import Artist, allow_rasterization
 from axes import Axes, SubplotBase, subplot_class_factory
 from cbook import flatten, allequal, Stack, iterable, is_string_like
-import _image
+from matplotlib import _image
 import colorbar as cbar
 from image import FigureImage
 from matplotlib import rcParams

Modified: branches/py3k/lib/matplotlib/font_manager.py
===================================================================
--- branches/py3k/lib/matplotlib/font_manager.py        2010-07-16 13:55:35 UTC 
(rev 8560)
+++ branches/py3k/lib/matplotlib/font_manager.py        2010-07-16 18:45:49 UTC 
(rev 8561)
@@ -235,13 +235,12 @@
     within them.
     """
     fontpaths = []
-    def add(arg,directory,files):
-        fontpaths.append(directory)
 
     for fontdir in OSXFontDirectories:
         try:
             if os.path.isdir(fontdir):
-                os.path.walk(fontdir, add, None)
+                for root, dirs, files in os.walk(fontdir):
+                    fontpaths.append(root)
         except (IOError, OSError, TypeError, ValueError):
             pass
     return fontpaths
@@ -274,13 +273,12 @@
     within them.
     """
     fontpaths = []
-    def add(arg,directory,files):
-        fontpaths.append(directory)
 
     for fontdir in X11FontDirectories:
         try:
             if os.path.isdir(fontdir):
-                os.path.walk(fontdir, add, None)
+                for root, dirs, files in os.walk(fontdir):
+                    fontpaths.append(root)
         except (IOError, OSError, TypeError, ValueError):
             pass
     return fontpaths
@@ -304,6 +302,7 @@
         return fontfiles
 
     if pipe.returncode == 0:
+        output = str(output)
         for line in output.split('\n'):
             fname = line.split(':')[0]
             if (os.path.splitext(fname)[1][1:] in fontext and
@@ -945,7 +944,8 @@
     Equivalent to pickle.dump(data, open(filename, 'w'))
     but closes the file to prevent filehandle leakage.
     """
-    fh = open(filename, 'w')
+    fh = open(filename, 'wb')
+    print data
     try:
         pickle.dump(data, fh)
     finally:
@@ -956,7 +956,7 @@
     Equivalent to pickle.load(open(filename, 'r'))
     but closes the file to prevent filehandle leakage.
     """
-    fh = open(filename, 'r')
+    fh = open(filename, 'rb')
     try:
         data = pickle.load(fh)
     finally:
@@ -975,7 +975,7 @@
     # Increment this version number whenever the font cache data
     # format or behavior has changed and requires a existing font
     # cache files to be rebuilt.
-    __version__ = 7
+    __version__ = 8
 
     def __init__(self, size=None, weight='normal'):
         self._version = self.__version__
@@ -1317,7 +1317,10 @@
         return result
 
 else:
-    _fmcache = os.path.join(get_configdir(), 'fontList.cache')
+    if sys.hexversion >= 0x03000000:
+        _fmcache = os.path.join(get_configdir(), 'fontList.py3k.cache')
+    else:
+        _fmcache = os.path.join(get_configdir(), 'fontList.py3k.cache')
 
     fontManager = None
 

Modified: branches/py3k/lib/matplotlib/lines.py
===================================================================
--- branches/py3k/lib/matplotlib/lines.py       2010-07-16 13:55:35 UTC (rev 
8560)
+++ branches/py3k/lib/matplotlib/lines.py       2010-07-16 18:45:49 UTC (rev 
8561)
@@ -1811,4 +1811,4 @@
 
 # You can not set the docstring of an instancemethod,
 # but you can on the underlying function.  Go figure.
-docstring.dedent_interpd(Line2D.__init__.im_func)
+docstring.dedent_interpd(Line2D.__init__)

Modified: branches/py3k/lib/matplotlib/mlab.py
===================================================================
--- branches/py3k/lib/matplotlib/mlab.py        2010-07-16 13:55:35 UTC (rev 
8560)
+++ branches/py3k/lib/matplotlib/mlab.py        2010-07-16 18:45:49 UTC (rev 
8561)
@@ -148,7 +148,6 @@
 ma = np.ma
 from matplotlib import verbose
 
-import matplotlib.nxutils as nxutils
 import matplotlib.cbook as cbook
 from matplotlib import docstring
 
@@ -2965,6 +2964,7 @@
     Return value is a sequence of indices into points for the points
     that are inside the polygon.
     """
+    # PY3KTODO: Reimplement in terms of _path module
     res, =  np.nonzero(nxutils.points_inside_poly(points, verts))
     return res
 

Modified: branches/py3k/lib/matplotlib/patches.py
===================================================================
--- branches/py3k/lib/matplotlib/patches.py     2010-07-16 13:55:35 UTC (rev 
8560)
+++ branches/py3k/lib/matplotlib/patches.py     2010-07-16 18:45:49 UTC (rev 
8561)
@@ -401,7 +401,7 @@
     docstring.interpd.update({k:patchdoc})
 
 # define Patch.__init__ docstring after the class has been added to interpd
-docstring.dedent_interpd(Patch.__init__.im_func)
+docstring.dedent_interpd(Patch.__init__)
 
 class Shadow(Patch):
     def __str__(self):

Modified: branches/py3k/lib/matplotlib/text.py
===================================================================
--- branches/py3k/lib/matplotlib/text.py        2010-07-16 13:55:35 UTC (rev 
8560)
+++ branches/py3k/lib/matplotlib/text.py        2010-07-16 18:45:49 UTC (rev 
8561)
@@ -22,8 +22,6 @@
 
 from matplotlib.artist import allow_rasterization
 
-import matplotlib.nxutils as nxutils
-
 from matplotlib.path import Path
 import matplotlib.font_manager as font_manager
 from matplotlib.ft2font import FT2Font
@@ -210,12 +208,9 @@
 
         r = l+w
         t = b+h
-        xyverts = (l,b), (l, t), (r, t), (r, b)
         x, y = mouseevent.x, mouseevent.y
-        inside = nxutils.pnpoly(x, y, xyverts)
+        return x >= l and x <= r and y >= t and y <= b
 
-        return inside,{}
-
     def _get_xy_display(self):
         'get the (possibly unit converted) transformed x, y in display coords'
         x, y = self.get_position()
@@ -997,7 +992,7 @@
         self.set_fontproperties(fp)
 
 docstring.interpd.update(Text = artist.kwdoc(Text))
-docstring.dedent_interpd(Text.__init__.im_func)
+docstring.dedent_interpd(Text.__init__)
 
 
 class TextWithDash(Text):

Modified: branches/py3k/setup.py
===================================================================
--- branches/py3k/setup.py      2010-07-16 13:55:35 UTC (rev 8560)
+++ branches/py3k/setup.py      2010-07-16 18:45:49 UTC (rev 8561)
@@ -39,7 +39,7 @@
     from distutils.command.build_py import build_py
 from setupext import build_agg, build_gtkagg, build_tkagg, build_wxagg,\
      build_macosx, build_ft2font, build_image, build_windowing, build_path, \
-     build_contour, build_delaunay, build_nxutils, build_gdk, \
+     build_contour, build_delaunay, build_gdk, \
      build_ttconv, print_line, print_status, print_message, \
      print_raw, check_for_freetype, check_for_libpng, check_for_gtk, \
      check_for_tk, check_for_wx, check_for_macosx, check_for_numpy, \
@@ -136,7 +136,6 @@
 build_ttconv(ext_modules, packages)
 build_contour(ext_modules, packages)
 build_delaunay(ext_modules, packages)
-build_nxutils(ext_modules, packages)
 build_path(ext_modules, packages)
 build_tri(ext_modules, packages)
 

Modified: branches/py3k/setupext.py
===================================================================
--- branches/py3k/setupext.py   2010-07-16 13:55:35 UTC (rev 8560)
+++ branches/py3k/setupext.py   2010-07-16 18:45:49 UTC (rev 8561)
@@ -106,7 +106,6 @@
 BUILT_WINDOWING = False
 BUILT_CONTOUR   = False
 BUILT_DELAUNAY  = False
-BUILT_NXUTILS   = False
 BUILT_CONTOUR   = False
 BUILT_GDK       = False
 BUILT_PATH      = False
@@ -1394,22 +1393,6 @@
     BUILT_CONTOUR = True
 
 
-def build_nxutils(ext_modules, packages):
-    global BUILT_NXUTILS
-    if BUILT_NXUTILS: return # only build it if you you haven't already
-    module = Extension(
-        'matplotlib.nxutils',
-        [ 'src/nxutils.c'],
-        include_dirs=numpy_inc_dirs,
-        define_macros=defines
-        )
-    add_numpy_flags(module)
-    add_base_flags(module)
-    ext_modules.append(module)
-
-    BUILT_NXUTILS = True
-
-
 def build_gdk(ext_modules, packages):
     global BUILT_GDK
     if BUILT_GDK: return # only build it if you you haven't already

Modified: branches/py3k/src/_backend_agg.cpp
===================================================================
--- branches/py3k/src/_backend_agg.cpp  2010-07-16 13:55:35 UTC (rev 8560)
+++ branches/py3k/src/_backend_agg.cpp  2010-07-16 18:45:49 UTC (rev 8561)
@@ -1743,16 +1743,16 @@
 
     //segments, trans, clipbox, colors, linewidths, antialiaseds
     GCAgg gc(args[0], dpi);
-    agg::trans_affine       master_transform = 
py_to_agg_transformation_matrix(args[1].ptr());
-    size_t                  mesh_width       = Py::Int(args[2]);
-    size_t                  mesh_height      = Py::Int(args[3]);
-    Py::Object              coordinates      = args[4];
-    Py::Object              offsets_obj      = args[5];
-    agg::trans_affine       offset_trans     = 
py_to_agg_transformation_matrix(args[6].ptr());
-    Py::Object              facecolors_obj   = args[7];
-    bool                    antialiased      = Py::Boolean(args[8]);
-    bool                    showedges        = Py::Boolean(args[9]);
-    bool                    free_edgecolors  = false;
+    agg::trans_affine master_transform = 
py_to_agg_transformation_matrix(args[1].ptr());
+    size_t            mesh_width       = Py::Int(args[2]);
+    size_t            mesh_height      = Py::Int(args[3]);
+    Py::Object        coordinates      = args[4];
+    Py::Object        offsets_obj      = args[5];
+    agg::trans_affine offset_trans     = 
py_to_agg_transformation_matrix(args[6].ptr());
+    Py::Object        facecolors_obj   = args[7];
+    bool              antialiased      = Py::Boolean(args[8]);
+    bool              showedges        = Py::Boolean(args[9]);
+    bool              free_edgecolors  = false;
 
     QuadMeshGenerator path_generator(mesh_width, mesh_height, 
coordinates.ptr());
 

Modified: branches/py3k/src/_png.cpp
===================================================================
--- branches/py3k/src/_png.cpp  2010-07-16 13:55:35 UTC (rev 8560)
+++ branches/py3k/src/_png.cpp  2010-07-16 18:45:49 UTC (rev 8561)
@@ -199,24 +199,30 @@
     }
     catch (...)
     {
+        if (png_ptr && info_ptr)
+        {
+            png_destroy_write_struct(&png_ptr, &info_ptr);
+        }
+        delete [] row_pointers;
         if (fp && close_file)
         {
             fclose(fp);
         }
-        delete [] row_pointers;
         /* Changed calls to png_destroy_write_struct to follow
            http://www.libpng.org/pub/png/libpng-manual.txt.
            This ensures the info_ptr memory is released.
         */
-        if (png_ptr && info_ptr)
-        {
-            png_destroy_write_struct(&png_ptr, &info_ptr);
-        }
         throw;
     }
 
     png_destroy_write_struct(&png_ptr, &info_ptr);
     delete [] row_pointers;
+#if PY_MAJOR_VERSION >= 3
+    if (fp)
+    {
+        fflush(fp);
+    }
+#endif
     if (fp && close_file)
     {
         fclose(fp);

Deleted: branches/py3k/src/nxutils.c
===================================================================
--- branches/py3k/src/nxutils.c 2010-07-16 13:55:35 UTC (rev 8560)
+++ branches/py3k/src/nxutils.c 2010-07-16 18:45:49 UTC (rev 8561)
@@ -1,252 +0,0 @@
-#include <Python.h>
-#include "structmember.h"
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "numpy/arrayobject.h"
-
-
-/*
-  pnpoly license
-  Copyright (c) 1970-2003, Wm. Randolph Franklin
-
-  Permission is hereby granted, free of charge, to any person obtaining a copy 
of this software and associated documentation files (the "Software"), to deal 
in the Software without restriction, including without limitation the rights to 
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 
of the Software, and to permit persons to whom the Software is furnished to do 
so, subject to the following conditions:
-
-  1. Redistributions of source code must retain the above copyright notice, 
this list of conditions and the following disclaimers.
-  2. Redistributions in binary form must reproduce the above copyright notice 
in the documentation and/or other materials provided with the distribution.
-  3. The name of W. Randolph Franklin may not be used to endorse or promote 
products derived from this Software without specific prior written permission.
-
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
SOFTWARE.
-*/
-
-int pnpoly_api(int npol, double *xp, double *yp, double x, double y)
-{
-  int i, j, c = 0;
-  for (i = 0, j = npol-1; i < npol; j = i++) {
-    if ((((yp[i]<=y) && (y<yp[j])) ||
-         ((yp[j]<=y) && (y<yp[i]))) &&
-        (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i]))
-
-      c = !c;
-  }
-  return c;
-}
-
-
-static PyObject *
-pnpoly(PyObject *self, PyObject *args)
-{
-  int npol, i;
-  double x, y;
-  double *xv, *yv;
-  int b;
-  PyObject *vertsarg;
-  PyArrayObject *verts;
-  if (! PyArg_ParseTuple(args, "ddO", &x, &y, &vertsarg))
-    return NULL;
-
-  verts = (PyArrayObject *) PyArray_FromObject(vertsarg,NPY_DOUBLE, 2, 2);
-
-  if (verts == NULL)
-    {
-      PyErr_SetString(PyExc_ValueError,
-                      "Arguments verts must be a Nx2 array.");
-      Py_XDECREF(verts);
-      return NULL;
-
-    }
-
-  npol = verts->dimensions[0];
-  //printf ("found %d verts\n", npol);
-  if (verts->dimensions[1]!=2)
-    {
-      PyErr_SetString(PyExc_ValueError,
-                      "Arguments verts must be a Nx2 array.");
-      Py_XDECREF(verts);
-      return NULL;
-
-    }
-
-
-  xv = (double *) PyMem_Malloc(sizeof(double) * npol);
-  if (xv == NULL)
-    {
-      Py_XDECREF(verts);
-      return NULL;
-    }
-
-  yv = (double *) PyMem_Malloc(sizeof(double) * npol);
-  if (yv == NULL)
-    {
-      Py_XDECREF(verts);
-      PyMem_Free(xv);
-      return NULL;
-    }
-
-  for (i=0; i<npol; ++i) {
-    xv[i] = *(double *)(verts->data + i*verts->strides[0]);
-    yv[i] = *(double *)(verts->data +  i*verts->strides[0] + 
verts->strides[1]);
-    //printf("adding vert: %1.3f, %1.3f\n", xv[i], yv[i]);
-  }
-
-  b = pnpoly_api(npol, xv, yv, x, y);
-  //printf("in poly %d\n", b);
-
-  Py_XDECREF(verts);
-  PyMem_Free(xv);
-  PyMem_Free(yv);
-  return Py_BuildValue("i", b);
-
-}
-
-static PyObject *
-points_inside_poly(PyObject *self, PyObject *args)
-{
-  int npol, npoints, i;
-  double *xv, *yv, x, y;
-  int b;
-  PyObject *xypointsarg, *vertsarg, *ret;
-  PyArrayObject *xypoints, *verts;
-  PyArrayObject *mask;
-  npy_intp dimensions[1];
-
-  if (! PyArg_ParseTuple(args, "OO", &xypointsarg, &vertsarg))
-    return NULL;
-
-  verts = (PyArrayObject *) PyArray_FromObject(vertsarg, NPY_DOUBLE, 2, 2);
-
-  if (verts == NULL)
-    {
-      PyErr_SetString(PyExc_ValueError,
-                      "Argument verts must be a Nx2 array.");
-      Py_XDECREF(verts);
-      return NULL;
-
-    }
-
-  npol = verts->dimensions[0];
-  //printf ("found %d verts\n", npol);
-  if (verts->dimensions[1]!=2)
-    {
-      PyErr_SetString(PyExc_ValueError,
-                      "Arguments verts must be a Nx2 array.");
-      Py_XDECREF(verts);
-      return NULL;
-
-    }
-
-
-  xv = (double *) PyMem_Malloc(sizeof(double) * npol);
-  if (xv == NULL)
-    {
-      Py_XDECREF(verts);
-      return NULL;
-    }
-
-  yv = (double *) PyMem_Malloc(sizeof(double) * npol);
-  if (yv == NULL)
-    {
-      Py_XDECREF(verts);
-      PyMem_Free(xv);
-      return NULL;
-    }
-
-  // fill the verts arrays
-  for (i=0; i<npol; ++i) {
-    xv[i] = *(double *)(verts->data + i*verts->strides[0]);
-    yv[i] = *(double *)(verts->data +  i*verts->strides[0] + 
verts->strides[1]);
-    //printf("adding vert: %1.3f, %1.3f\n", xv[i], yv[i]);
-  }
-
-  xypoints = (PyArrayObject *) PyArray_FromObject(xypointsarg, NPY_DOUBLE, 2, 
2);
-
-  if (xypoints == NULL)
-    {
-      PyErr_SetString(PyExc_ValueError,
-                      "Arguments xypoints must an Nx2 array.");
-      Py_XDECREF(verts);
-      Py_XDECREF(xypoints);
-      PyMem_Free(xv);
-      PyMem_Free(yv);
-      return NULL;
-
-    }
-
-  if (xypoints->dimensions[1]!=2)
-    {
-      PyErr_SetString(PyExc_ValueError,
-                      "Arguments xypoints must be a Nx2 array.");
-
-      Py_XDECREF(verts);
-      Py_XDECREF(xypoints);
-      PyMem_Free(xv);
-      PyMem_Free(yv);
-      return NULL;
-    }
-
-  npoints = xypoints->dimensions[0];
-  dimensions[0] = npoints;
-
-  mask = (PyArrayObject *)PyArray_SimpleNew(1,dimensions, NPY_BOOL);
-  if (mask==NULL) {
-    Py_XDECREF(verts);
-    Py_XDECREF(xypoints);
-    PyMem_Free(xv);
-    PyMem_Free(yv);
-    return NULL;  }
-
-  for (i=0; i<npoints; ++i) {
-    x = *(double *)(xypoints->data + i*xypoints->strides[0]);
-    y = *(double *)(xypoints->data +  i*xypoints->strides[0] + 
xypoints->strides[1]);
-    b = pnpoly_api(npol, xv, yv, x, y);
-    //printf("checking %d, %d, %1.3f, %1.3f, %d\n", npol, npoints, x, y, b);
-    *(char *)(mask->data + i*mask->strides[0]) = b;
-
-  }
-
-
-  Py_XDECREF(verts);
-  Py_XDECREF(xypoints);
-
-  PyMem_Free(xv);
-  PyMem_Free(yv);
-  ret =  Py_BuildValue("O", mask);
-  Py_XDECREF(mask);
-  return ret;
-
-
-}
-
-static PyMethodDef module_methods[] = {
-  {"pnpoly",  pnpoly, METH_VARARGS,
-        "inside = pnpoly(x, y, xyverts)\n\n"
-        "Return 1 if x,y is inside the polygon, 0 otherwise.\n\n"
-        "*xyverts*\n    a sequence of x,y vertices.\n\n"
-        "A point on the boundary may be treated as inside or outside.\n"
-        "See `pnpoly 
<http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html>`_"},
-  {"points_inside_poly",  points_inside_poly, METH_VARARGS,
-        "mask = points_inside_poly(xypoints, xyverts)\n\n"
-        "Return a boolean ndarray, True for points inside the polygon.\n\n"
-        "*xypoints*\n    a sequence of N x,y pairs.\n"
-        "*xyverts*\n    sequence of x,y vertices of the polygon.\n"
-        "*mask*    an ndarray of length N.\n\n"
-        "A point on the boundary may be treated as inside or outside.\n"
-        "See `pnpoly 
<http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html>`_\n"},
-  {NULL}  /* Sentinel */
-};
-
-PyMODINIT_FUNC
-initnxutils(void)
-{
-  PyObject* m;
-
-  m = Py_InitModule3("nxutils", module_methods,
-                     "general purpose numerical utilities, eg for 
computational geometry, that are not available in `numpy 
<http://numpy.scipy.org>`_");
-
-  if (m == NULL)
-    return;
-
-  import_array();
-}
-
-


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 Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to