Refactor pnpoly function in Cython and add to shared package

This commit is contained in:
Johannes Schönberger
2012-08-21 15:43:26 +02:00
parent a08779e06a
commit c471d475eb
8 changed files with 45 additions and 92 deletions
+7
View File
@@ -0,0 +1,7 @@
cdef inline unsigned char point_in_polygon(int nr_verts, double *xp, double *yp,
double x, double y)
cdef void points_in_polygon(int nr_verts, double *xp, double *yp,
int nr_points, double *x, double *y,
unsigned char *result)
+27
View File
@@ -0,0 +1,27 @@
#cython: cdivison=True
#cython: boundscheck=False
#cython: nonecheck=False
#cython: wraparound=False
cdef inline unsigned char point_in_polygon(int nr_verts, double *xp, double *yp,
double x, double y):
cdef int i
cdef unsigned char c = 0
cdef int j = nr_verts - 1
for i in range(nr_verts):
if (
(((yp[i] <= y) and (y < yp[j])) or
((yp[j] <= y) and (y < yp[i])))
and (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i])
):
c = not c
j = i
return c
cdef void points_in_polygon(int nr_verts, double *xp, double *yp,
int nr_points, double *x, double *y,
unsigned char *result):
cdef int n
for n in range(nr_points):
result[n] = point_in_polygon(nr_verts, xp, yp, x[n], y[n])
+2
View File
@@ -13,9 +13,11 @@ def configuration(parent_package='', top_path=None):
config = Configuration('_shared', parent_package, top_path)
config.add_data_dir('tests')
cython(['geometry.pyx'], working_path=base_path)
cython(['interpolation.pyx'], working_path=base_path)
cython(['transform.pyx'], working_path=base_path)
config.add_extension('geometry', sources=['geometry.c'])
config.add_extension('interpolation', sources=['interpolation.c'],
include_dirs=[get_numpy_include_dirs()])
config.add_extension('transform', sources=['transform.c'],