-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathh3_polyfill.h
84 lines (75 loc) · 3.15 KB
/
h3_polyfill.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* Copyright 2023 Uber Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** @file polyfill.h
* @brief Functions relating to the polygon-to-cells functionality
*/
#ifndef POLYFILL_H
#define POLYFILL_H
#include <stdbool.h>
#include "h3_bbox.h"
#include "h3_h3api.h"
#include "h3_iterators.h"
/**
* IterCellsPolygonCompact: struct for iterating through all the cells
* within a given polygon, outputting a compact set.
*
* Constructors:
*
* Initialize with `iterInitPolygon`. This will save a reference to the
* input polygon and allocate memory for data structures used in the
* iteration. Iterators initialized in this way must be destroyed by
* `iterDestroyPolygon` to free allocated memory.
*
* Iteration:
*
* Step iterator with `iterStepPolygonCompact`.
* During the lifetime of the `iterCellsPolygonCompact`, the current iterate
* is accessed via the `iterCellsPolygonCompact.cell` member. When the iterator
* is exhausted or if there was an error in initialization or iteration,
* `iterCellsPolygonCompact.cell` will be `H3_NULL` after calling
* `iterStepChild`. It is the responsibiliy of the caller to check
* `iterCellsPolygonCompact.error` when `H3_NULL` is received.
*
* Cleanup:
*
* Destroy the iterator and free allocated memory with `iterDestroyPolygon`.
*/
typedef struct {
H3Index cell; // current value
H3Error error; // error, if any
int _res; // target resolution
uint32_t _flags; // Mode flags for the polygonToCells operation
const GeoPolygon *_polygon; // the polygon we're filling
BBox *_bboxes; // Bounding box(es) for the polygon and its holes
bool _started; // Whether iteration has started
} IterCellsPolygonCompact;
DECLSPEC IterCellsPolygonCompact
iterInitPolygonCompact(const GeoPolygon *polygon, int res, uint32_t flags);
DECLSPEC void iterStepPolygonCompact(IterCellsPolygonCompact *iter);
DECLSPEC void iterDestroyPolygonCompact(IterCellsPolygonCompact *iter);
typedef struct {
H3Index cell; // current value
H3Error error; // error, if any
IterCellsPolygonCompact _cellIter; // sub-iterator for compact cells
IterCellsChildren _childIter; // sub-iterator for cell children
} IterCellsPolygon;
DECLSPEC IterCellsPolygon iterInitPolygon(const GeoPolygon *polygon, int res,
uint32_t flags);
DECLSPEC void iterStepPolygon(IterCellsPolygon *iter);
DECLSPEC void iterDestroyPolygon(IterCellsPolygon *iter);
H3Error cellToBBox(H3Index cell, BBox *out, bool coverChildren);
H3Index baseCellNumToCell(int baseCellNum);
#endif