polygon.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #ifndef POLYGON_H
  20. #define POLYGON_H
  21. #include <stdbool.h>
  22. #include "bbox.h"
  23. #include "geoCoord.h"
  24. #include "h3api.h"
  25. #include "linkedGeo.h"
  26. // Macros for use with polygonAlgos.h
  27. /** Macro: Init iteration vars for Geofence */
  28. #define INIT_ITERATION_GEOFENCE int loopIndex = -1
  29. /** Macro: Increment Geofence loop iteration, or break if done. */
  30. #define ITERATE_GEOFENCE(geofence, vertexA, vertexB) \
  31. if (++loopIndex >= geofence->numVerts) break; \
  32. vertexA = geofence->verts[loopIndex]; \
  33. vertexB = geofence->verts[(loopIndex + 1) % geofence->numVerts]
  34. /** Macro: Whether a Geofence is empty */
  35. #define IS_EMPTY_GEOFENCE(geofence) geofence->numVerts == 0
  36. // Defined directly in polygon.c:
  37. void bboxesFromGeoPolygon(const GeoPolygon* polygon, BBox* bboxes);
  38. bool pointInsidePolygon(const GeoPolygon* geoPolygon, const BBox* bboxes,
  39. const GeoCoord* coord);
  40. // The following functions are created via macro in polygonAlgos.h,
  41. // so their signatures are documented here:
  42. /**
  43. * Create a bounding box from a Geofence
  44. * @param geofence Input Geofence
  45. * @param bbox Output bbox
  46. */
  47. void bboxFromGeofence(const Geofence* loop, BBox* bbox);
  48. /**
  49. * Take a given Geofence data structure and check if it
  50. * contains a given geo coordinate.
  51. * @param loop The geofence
  52. * @param bbox The bbox for the loop
  53. * @param coord The coordinate to check
  54. * @return Whether the point is contained
  55. */
  56. bool pointInsideGeofence(const Geofence* loop, const BBox* bbox,
  57. const GeoCoord* coord);
  58. /**
  59. * Whether the winding order of a given Geofence is clockwise
  60. * @param loop The loop to check
  61. * @return Whether the loop is clockwise
  62. */
  63. bool isClockwiseGeofence(const Geofence* geofence);
  64. #endif