Skip to content

Commit

Permalink
Fix use of C logical operator (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed May 11, 2021
1 parent 986751b commit 81f58d3
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 49 deletions.
2 changes: 2 additions & 0 deletions pygeos/test/test_measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ def test_hausdorff_distance_densify():
def test_hausdorff_distance_missing():
actual = pygeos.hausdorff_distance(point, None)
assert np.isnan(actual)
actual = pygeos.hausdorff_distance(point, None, densify=0.001)
assert np.isnan(actual)


def test_hausdorff_densify_nan():
Expand Down
12 changes: 6 additions & 6 deletions src/coords.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ on error, 1 on success*/
static char get_coordinates(GEOSContextHandle_t context, GEOSGeometry* geom,
PyArrayObject* out, npy_intp* cursor, int include_z) {
int type = GEOSGeomTypeId_r(context, geom);
if ((type == 0) | (type == 1) | (type == 2)) {
if ((type == 0) || (type == 1) || (type == 2)) {
return get_coordinates_simple(context, geom, out, cursor, include_z);
} else if (type == 3) {
return get_coordinates_polygon(context, geom, out, cursor, include_z);
} else if ((type >= 4) & (type <= 7)) {
} else if ((type >= 4) && (type <= 7)) {
return get_coordinates_collection(context, geom, out, cursor, include_z);
} else {
return 0;
Expand All @@ -140,7 +140,7 @@ static void* set_coordinates_simple(GEOSContextHandle_t context, GEOSGeometry* g
GEOSGeometry* ret;

/* Special case for POINT EMPTY (Point coordinate list cannot be 0-length) */
if ((type == 0) & (GEOSisEmpty_r(context, geom) == 1)) {
if ((type == 0) && (GEOSisEmpty_r(context, geom) == 1)) {
return GEOSGeom_createEmptyPoint_r(context);
}

Expand Down Expand Up @@ -288,11 +288,11 @@ correspondingly. Returns NULL on error,*/
static void* set_coordinates(GEOSContextHandle_t context, GEOSGeometry* geom,
PyArrayObject* coords, npy_intp* cursor, int include_z) {
int type = GEOSGeomTypeId_r(context, geom);
if ((type == 0) | (type == 1) | (type == 2)) {
if ((type == 0) || (type == 1) || (type == 2)) {
return set_coordinates_simple(context, geom, type, coords, cursor, include_z);
} else if (type == 3) {
return set_coordinates_polygon(context, geom, coords, cursor, include_z);
} else if ((type >= 4) & (type <= 7)) {
} else if ((type >= 4) && (type <= 7)) {
return set_coordinates_collection(context, geom, type, coords, cursor, include_z);
} else {
return NULL;
Expand Down Expand Up @@ -600,7 +600,7 @@ PyObject* PySetCoords(PyObject* self, PyObject* args) {
if (!PyArg_ParseTuple(args, "OO", &geoms, &coords)) {
return NULL;
}
if ((!PyArray_Check(geoms)) | (!PyArray_Check(coords))) {
if ((!PyArray_Check(geoms)) || (!PyArray_Check(coords))) {
PyErr_SetString(PyExc_TypeError, "Not an ndarray");
return NULL;
}
Expand Down
8 changes: 4 additions & 4 deletions src/geos.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ char geos_interpolate_checker(GEOSContextHandle_t ctx, GEOSGeometry* geom) {
type = GEOSGeomTypeId_r(ctx, geom);
if (type == -1) {
return PGERR_GEOS_EXCEPTION;
} else if ((type == GEOS_POINT) | (type == GEOS_POLYGON) | (type == GEOS_MULTIPOINT) |
} else if ((type == GEOS_POINT) || (type == GEOS_POLYGON) || (type == GEOS_MULTIPOINT) ||
(type == GEOS_MULTIPOLYGON)) {
return PGERR_GEOMETRY_TYPE;
}
Expand All @@ -324,15 +324,15 @@ char geos_interpolate_checker(GEOSContextHandle_t ctx, GEOSGeometry* geom) {
}

// For collections: also check the type and emptyness of the first geometry
if ((type == GEOS_MULTILINESTRING) | (type == GEOS_GEOMETRYCOLLECTION)) {
if ((type == GEOS_MULTILINESTRING) || (type == GEOS_GEOMETRYCOLLECTION)) {
sub_geom = GEOSGetGeometryN_r(ctx, geom, 0);
if (sub_geom == NULL) {
return PGERR_GEOS_EXCEPTION; // GEOSException
}
type = GEOSGeomTypeId_r(ctx, sub_geom);
if (type == -1) {
return PGERR_GEOS_EXCEPTION;
} else if ((type != GEOS_LINESTRING) & (type != GEOS_LINEARRING)) {
} else if ((type != GEOS_LINESTRING) && (type != GEOS_LINEARRING)) {
return PGERR_GEOMETRY_TYPE;
}
is_empty = GEOSisEmpty_r(ctx, sub_geom);
Expand Down Expand Up @@ -483,7 +483,7 @@ int get_bounds(GEOSContextHandle_t ctx, GEOSGeometry* geom, double* xmin, double
*/
GEOSGeometry* create_box(GEOSContextHandle_t ctx, double xmin, double ymin, double xmax,
double ymax, char ccw) {
if (npy_isnan(xmin) | npy_isnan(ymin) | npy_isnan(xmax) | npy_isnan(ymax)) {
if (npy_isnan(xmin) || npy_isnan(ymin) || npy_isnan(xmax) || npy_isnan(ymax)) {
return NULL;
}

Expand Down
4 changes: 2 additions & 2 deletions src/pygeom.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ static PyObject* GeometryObject_ToWKB(GeometryObject* obj) {

finish:
// Destroy the geom if it was patched (POINT EMPTY patch)
if (has_empty & (geom != NULL)) {
if (has_empty && (geom != NULL)) {
GEOSGeom_destroy_r(ctx, geom);
}
if (writer != NULL) {
Expand Down Expand Up @@ -425,7 +425,7 @@ int __Pyx_InBases(PyTypeObject* a, PyTypeObject* b) {
Py_None. Returns 0 on error, 1 on success. */
char get_geom(GeometryObject* obj, GEOSGeometry** out) {
PyTypeObject* type = ((PyObject*)obj)->ob_type;
if ((type != &GeometryType) & !(__Pyx_InBases(type, &GeometryType))) {
if ((type != &GeometryType) && !(__Pyx_InBases(type, &GeometryType))) {
if ((PyObject*)obj == Py_None) {
*out = NULL;
return 1;
Expand Down

0 comments on commit 81f58d3

Please sign in to comment.