Skip to content

Commit

Permalink
Merge pull request #238 from enthought/fix/points-in-polygon-dtype
Browse files Browse the repository at this point in the history
Change points_in_polygon to return boolean array
  • Loading branch information
corranwebster committed Aug 17, 2016
2 parents b8eea9c + b93f58b commit 168e222
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions kiva/agg/src/agg_typemaps.i
Expand Up @@ -83,18 +83,18 @@
}

// --------------------------------------------------------------------------
// Typemaps for (int* results, int Nresults)
// Typemaps for (unsigned char* results, int Nresults)
//
// For: points_in_polygon
//
// This typemap takes any N input.
//
// --------------------------------------------------------------------------

%typemap(in) (int* results, int Nresults) (PyArrayObject* ary=NULL,
%typemap(in) (unsigned char* results, int Nresults) (PyArrayObject* ary=NULL,
int is_new_object)
{
ary = obj_to_array_contiguous_allow_conversion($input, PyArray_INT,
ary = obj_to_array_contiguous_allow_conversion($input, PyArray_BOOL,
is_new_object);
int size[1] = {-1};
if (!ary ||
Expand All @@ -103,11 +103,11 @@
{
goto fail;
}
$1 = (int*) ary->data;
$1 = (unsigned char*) ary->data;
$2 = ary->dimensions[0];
}

%typemap(freearg) (int* results, int Nresults)
%typemap(freearg) (unsigned char* results, int Nresults)
{
if (is_new_object$argnum)
{
Expand Down
8 changes: 4 additions & 4 deletions kiva/agg/src/hit_test.i
Expand Up @@ -7,18 +7,18 @@

%apply (double* point_array, int point_count) {(double* pts, int Npts)};
%apply (double* point_array, int point_count) {(double* poly_pts, int Npoly_pts)};
%apply (int* results, int Nresults) {(int* results, int Nresults)};
%apply (unsigned char* results, int Nresults) {(unsigned char* results, int Nresults)};

namespace kiva
{
bool point_in_polygon(double x, double y, double* poly_pts, int Npoly_pts);
void points_in_polygon(double* pts, int Npts,
double* poly_pts, int Npoly_pts,
int* results, int Nresults);
unsigned char* results, int Nresults);
bool point_in_polygon_winding(double x, double y, double* poly_pts, int Npoly_pts);
void points_in_polygon_winding(double* pts, int Npts,
double* poly_pts, int Npoly_pts,
int* results, int Nresults);
unsigned char* results, int Nresults);
}

%pythoncode
Expand Down Expand Up @@ -88,7 +88,7 @@ def points_in_polygon(pts, poly_pts, use_winding=False):
else:
raise ValueError('poly_pts must be an Nx2 or 2xN array')

results = zeros(len(pts),int32)
results = zeros(len(pts), bool)
if use_winding:
_agg.points_in_polygon_winding(pts, poly_pts, results)
else:
Expand Down
4 changes: 2 additions & 2 deletions kiva/agg/src/kiva_hit_test.cpp
Expand Up @@ -64,7 +64,7 @@ namespace kiva

void points_in_polygon(double* pts, int Npts,
double* poly_pts, int Npoly_pts,
int* results, int Nresults)
unsigned char* results, int Nresults)
{
// Nresults and Npts should match.

Expand Down Expand Up @@ -136,7 +136,7 @@ namespace kiva

void points_in_polygon_winding(double* pts, int Npts,
double* poly_pts, int Npoly_pts,
int* results, int Nresults)
unsigned char* results, int Nresults)
{
// Nresults and Npts should match.

Expand Down
4 changes: 2 additions & 2 deletions kiva/agg/src/kiva_hit_test.h
Expand Up @@ -7,12 +7,12 @@ namespace kiva
double* poly_pts, int Npoly_pts);
void points_in_polygon(double* pts, int Npts,
double* poly_pts, int Npoly_pts,
int* results, int Nresults);
unsigned char* results, int Nresults);
bool point_in_polygon_winding(double x, double y,
double* poly_pts, int Npoly_pts);
void points_in_polygon_winding(double* pts, int Npts,
double* poly_pts, int Npoly_pts,
int* results, int Nresults);
unsigned char* results, int Nresults);

}
#endif

0 comments on commit 168e222

Please sign in to comment.