Helper function for geoGetPointsInRange(): given a sorted set score * representing a point, and a GeoShape, appends this entry as a geoPoint * into the specified geoArray only if the point is within the search area. * * returns C_OK if the point is included, or REIDS_ERR if it is outside. */
| 215 | * |
| 216 | * returns C_OK if the point is included, or REIDS_ERR if it is outside. */ |
| 217 | int geoAppendIfWithinShape(geoArray *ga, GeoShape *shape, double score, sds member) { |
| 218 | double distance = 0, xy[2]; |
| 219 | |
| 220 | if (!decodeGeohash(score,xy)) return C_ERR; /* Can't decode. */ |
| 221 | /* Note that geohashGetDistanceIfInRadiusWGS84() takes arguments in |
| 222 | * reverse order: longitude first, latitude later. */ |
| 223 | if (shape->type == CIRCULAR_TYPE) { |
| 224 | if (!geohashGetDistanceIfInRadiusWGS84(shape->xy[0], shape->xy[1], xy[0], xy[1], |
| 225 | shape->t.radius*shape->conversion, &distance)) return C_ERR; |
| 226 | } else if (shape->type == RECTANGLE_TYPE) { |
| 227 | if (!geohashGetDistanceIfInRectangle(shape->t.r.width * shape->conversion, |
| 228 | shape->t.r.height * shape->conversion, |
| 229 | shape->xy[0], shape->xy[1], xy[0], xy[1], &distance)) |
| 230 | return C_ERR; |
| 231 | } |
| 232 | |
| 233 | /* Append the new element. */ |
| 234 | geoPoint *gp = geoArrayAppend(ga); |
| 235 | gp->longitude = xy[0]; |
| 236 | gp->latitude = xy[1]; |
| 237 | gp->dist = distance; |
| 238 | gp->member = member; |
| 239 | gp->score = score; |
| 240 | return C_OK; |
| 241 | } |
| 242 | |
| 243 | /* Query a Redis sorted set to extract all the elements between 'min' and |
| 244 | * 'max', appending them into the array of geoPoint structures 'gparray'. |
no test coverage detected