Const all the things, then cast it away
@@ -106,8 +106,8 @@ bool pointInsidePolygon(const GeoPolygon* geoPolygon, const BBox* bboxes,
* @return Number of polygons containing the loop
*/
static int countContainers(const LinkedGeoLoop* loop,
- LinkedGeoPolygon** polygons, const BBox** bboxes,
- const int polygonCount) {
+ const LinkedGeoPolygon** polygons,
+ const BBox** bboxes, const int polygonCount) {
int containerCount = 0;
for (int i = 0; i < polygonCount; i++) {
if (loop != polygons[i]->first &&
@@ -126,11 +126,11 @@ static int countContainers(const LinkedGeoLoop* loop,
* @param polygonCount Number of polygons in the list
* @return Deepest container, or null if list is empty
*/
-static LinkedGeoPolygon* findDeepestContainer(LinkedGeoPolygon** polygons,
- const BBox** bboxes,
+static const LinkedGeoPolygon* findDeepestContainer(
+ const LinkedGeoPolygon** polygons, const BBox** bboxes,
const int polygonCount) {
// Set the initial return value to the first candidate
- LinkedGeoPolygon* parent = polygonCount > 0 ? polygons[0] : NULL;
+ const LinkedGeoPolygon* parent = polygonCount > 0 ? polygons[0] : NULL;
// If we have multiple polygons, they must be nested inside each other.
// Find the innermost polygon by taking the one with the most containers
@@ -159,16 +159,15 @@ static LinkedGeoPolygon* findDeepestContainer(LinkedGeoPolygon** polygons,
* @param polygonCount Number of polygons to check
* @return Pointer to parent polygon, or null if not found
*/
-static LinkedGeoPolygon* findPolygonForHole(const LinkedGeoLoop* loop,
- LinkedGeoPolygon* polygon,
- const BBox* bboxes,
- const int polygonCount) {
+static const LinkedGeoPolygon* findPolygonForHole(
+ const LinkedGeoLoop* loop, const LinkedGeoPolygon* polygon,
+ const BBox* bboxes, const int polygonCount) {
// Early exit with no polygons
if (polygonCount == 0) {
return NULL;
}
// Initialize arrays for candidate loops and their bounding boxes
- LinkedGeoPolygon** candidates =
+ const LinkedGeoPolygon** candidates =
malloc(polygonCount * sizeof(LinkedGeoPolygon*));
assert(candidates != NULL);
const BBox** candidateBBoxes = malloc(polygonCount * sizeof(BBox*));
@@ -190,7 +189,7 @@ static LinkedGeoPolygon* findPolygonForHole(const LinkedGeoLoop* loop,
}
// The most deeply nested container is the immediate parent
- LinkedGeoPolygon* parent =
+ const LinkedGeoPolygon* parent =
findDeepestContainer(candidates, candidateBBoxes, candidateCount);
// Free allocated memory
@@ -266,7 +265,8 @@ int normalizeMultiPolygon(LinkedGeoPolygon* root) {
// Find polygon for each inner loop and assign the hole to it
for (int i = 0; i < innerCount; i++) {
- polygon = findPolygonForHole(innerLoops[i], root, bboxes, outerCount);
+ polygon = (LinkedGeoPolygon*)findPolygonForHole(innerLoops[i], root,
+ bboxes, outerCount);
if (polygon) {
addLinkedLoop(polygon, innerLoops[i]);
} else {
