| 1 | /* |
| 2 | * Copyright 2018 Uber Technologies, Inc. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | /** @file polygon.h |
| 17 | * @brief Polygon algorithms |
| 18 | */ |
| 19 | |
| 20 | #ifndef POLYGON_H |
| 21 | #define POLYGON_H |
| 22 | |
| 23 | #include <stdbool.h> |
| 24 | #include "bbox.h" |
| 25 | #include "geoCoord.h" |
| 26 | #include "h3api.h" |
| 27 | #include "linkedGeo.h" |
| 28 | |
| 29 | // Macros for use with polygonAlgos.h |
| 30 | /** Macro: Init iteration vars for Geofence */ |
| 31 | #define INIT_ITERATION_GEOFENCE int loopIndex = -1 |
| 32 | |
| 33 | /** Macro: Increment Geofence loop iteration, or break if done. */ |
| 34 | #define ITERATE_GEOFENCE(geofence, vertexA, vertexB) \ |
| 35 | if (++loopIndex >= geofence->numVerts) break; \ |
| 36 | vertexA = geofence->verts[loopIndex]; \ |
| 37 | vertexB = geofence->verts[(loopIndex + 1) % geofence->numVerts] |
| 38 | |
| 39 | /** Macro: Whether a Geofence is empty */ |
| 40 | #define IS_EMPTY_GEOFENCE(geofence) geofence->numVerts == 0 |
| 41 | |
| 42 | // Defined directly in polygon.c: |
| 43 | void bboxesFromGeoPolygon(const GeoPolygon* polygon, BBox* bboxes); |
| 44 | bool pointInsidePolygon(const GeoPolygon* geoPolygon, const BBox* bboxes, |
| 45 | const GeoCoord* coord); |
| 46 | |
| 47 | // The following functions are created via macro in polygonAlgos.h, |
| 48 | // so their signatures are documented here: |
| 49 | |
| 50 | /** |
| 51 | * Create a bounding box from a Geofence |
| 52 | * @param geofence Input Geofence |
| 53 | * @param bbox Output bbox |
| 54 | */ |
| 55 | void bboxFromGeofence(const Geofence* loop, BBox* bbox); |
| 56 | |
| 57 | /** |
| 58 | * Take a given Geofence data structure and check if it |
| 59 | * contains a given geo coordinate. |
| 60 | * @param loop The geofence |
| 61 | * @param bbox The bbox for the loop |
| 62 | * @param coord The coordinate to check |
| 63 | * @return Whether the point is contained |
| 64 | */ |
| 65 | bool pointInsideGeofence(const Geofence* loop, const BBox* bbox, |
| 66 | const GeoCoord* coord); |
| 67 | |
| 68 | /** |
| 69 | * Whether the winding order of a given Geofence is clockwise |
| 70 | * @param loop The loop to check |
| 71 | * @return Whether the loop is clockwise |
| 72 | */ |
| 73 | bool isClockwiseGeofence(const Geofence* geofence); |
| 74 | |
| 75 | #endif |
| 76 | |