<|start_filename|>src/apps/testapps/testH3ToParent.c<|end_filename|>
/*
 * Copyright 2017-2018 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.
 */

#include <stdlib.h>
#include "h3Index.h"
#include "test.h"

SUITE(h3ToParent) {
    GeoCoord sf = {0.659966917655, 2 * 3.14159 - 2.1364398519396};

    TEST(ancestorsForEachRes) {
        H3Index child;
        H3Index comparisonParent;
        H3Index parent;

        for (int res = 1; res < 15; res++) {
            for (int step = 0; step < res; step++) {
                child = H3_EXPORT(geoToH3)(&sf, res);
                parent = H3_EXPORT(h3ToParent)(child, res - step);
                comparisonParent = H3_EXPORT(geoToH3)(&sf, res - step);

                t_assert(parent == comparisonParent, "Got expected parent");
            }
        }
    }

    TEST(invalidInputs) {
        H3Index child = H3_EXPORT(geoToH3)(&sf, 5);

        t_assert(H3_EXPORT(h3ToParent)(child, 6) == 0,
                 "Higher resolution fails");
        t_assert(H3_EXPORT(h3ToParent)(child, -1) == 0,
                 "Invalid resolution fails");
        t_assert(H3_EXPORT(h3ToParent)(child, 15) == 0,
                 "Invalid resolution fails");
    }
}


<|start_filename|>src/apps/benchmarks/benchmarkH3Api.c<|end_filename|>
/*
 * Copyright 2017 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.
 */
#include "benchmark.h"
#include "geoCoord.h"
#include "h3api.h"

// Fixtures
GeoCoord coord = {0.659966917655, -2.1364398519396};
H3Index hex = 0x89283080ddbffff;

BEGIN_BENCHMARKS();

GeoCoord outCoord;
GeoBoundary outBoundary;

BENCHMARK(geoToH3, 10000, { H3_EXPORT(geoToH3)(&coord, 9); });

BENCHMARK(h3ToGeo, 10000, { H3_EXPORT(h3ToGeo)(hex, &outCoord); });

BENCHMARK(h3ToGeoBoundary, 10000, {
    H3_EXPORT(h3ToGeoBoundary)(hex, &outBoundary);
});

END_BENCHMARKS();


<|start_filename|>src/h3lib/include/bbox.h<|end_filename|>
/*
 * Copyright 2016-2017 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 bbox.h
 * @brief   Geographic bounding box functions
 */

#ifndef BBOX_H
#define BBOX_H

#include <stdbool.h>
#include "geoCoord.h"

/** @struct BBox
 *  @brief  Geographic bounding box with coordinates defined in radians
 */
typedef struct {
    double north;  ///< north latitude
    double south;  ///< south latitude
    double east;   ///< east longitude
    double west;   ///< west longitude
} BBox;

bool bboxIsTransmeridian(const BBox* bbox);
void bboxCenter(const BBox* bbox, GeoCoord* center);
bool bboxContains(const BBox* bbox, const GeoCoord* point);
bool bboxEquals(const BBox* b1, const BBox* b2);
int bboxHexRadius(const BBox* bbox, int res);

#endif


<|start_filename|>src/apps/miscapps/generateFaceCenterPoint.c<|end_filename|>
/*
 * Copyright 2018 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 generateFaceCenterPoint.c
 * @brief Generates the faceCenterPoint table
 *
 *  usage: `generateFaceCenterPoint`
 */

#include <stdlib.h>
#include "faceijk.h"
#include "vec3d.h"

/**
 * Generates and prints the faceCenterPoint table.
 */
static void generate() {
    printf("static const Vec3d faceCenterPoint[NUM_ICOSA_FACES] = {\n");
    for (int i = 0; i < NUM_ICOSA_FACES; i++) {
        GeoCoord centerCoords = faceCenterGeo[i];
        Vec3d centerPoint;
        _geoToVec3d(&centerCoords, &centerPoint);
        printf("    {%.16f, %.16f, %.16f}, // face %2d\n", centerPoint.x,
               centerPoint.y, centerPoint.z, i);
    }
    printf("};\n");
}

int main(int argc, char* argv[]) {
    // check command line args
    if (argc > 1) {
        fprintf(stderr, "usage: %s\n", argv[0]);
        exit(1);
    }

    generate();
}


<|start_filename|>src/apps/testapps/testH3SetToVertexGraph.c<|end_filename|>
/*
 * Copyright 2017-2018 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.
 */

#include <stdio.h>
#include "algos.h"
#include "test.h"
#include "utility.h"

SUITE(h3SetToVertexGraph) {
    TEST(empty) {
        VertexGraph graph;

        h3SetToVertexGraph(NULL, 0, &graph);

        t_assert(graph.size == 0, "No edges added to graph");

        destroyVertexGraph(&graph);
    }

    TEST(singleHex) {
        VertexGraph graph;
        H3Index set[] = {0x890dab6220bffff};
        int numHexes = ARRAY_SIZE(set);

        h3SetToVertexGraph(set, numHexes, &graph);
        t_assert(graph.size == 6, "All edges of one hex added to graph");

        destroyVertexGraph(&graph);
    }

    TEST(nonContiguous2) {
        VertexGraph graph;
        H3Index set[] = {0x8928308291bffff, 0x89283082943ffff};
        int numHexes = ARRAY_SIZE(set);

        h3SetToVertexGraph(set, numHexes, &graph);
        t_assert(graph.size == 12,
                 "All edges of two non-contiguous hexes added to graph");

        destroyVertexGraph(&graph);
    }

    TEST(contiguous2) {
        VertexGraph graph;
        H3Index set[] = {0x8928308291bffff, 0x89283082957ffff};
        int numHexes = ARRAY_SIZE(set);

        h3SetToVertexGraph(set, numHexes, &graph);
        t_assert(graph.size == 10, "All edges except 2 shared added to graph");

        destroyVertexGraph(&graph);
    }

    TEST(contiguous2distorted) {
        VertexGraph graph;
        H3Index set[] = {0x894cc5365afffff, 0x894cc536537ffff};
        int numHexes = ARRAY_SIZE(set);

        h3SetToVertexGraph(set, numHexes, &graph);
        t_assert(graph.size == 12, "All edges except 2 shared added to graph");

        destroyVertexGraph(&graph);
    }

    TEST(contiguous3) {
        VertexGraph graph;
        H3Index set[] = {0x8928308288bffff, 0x892830828d7ffff,
                         0x8928308289bffff};
        int numHexes = ARRAY_SIZE(set);

        h3SetToVertexGraph(set, numHexes, &graph);
        t_assert(graph.size == 3 * 4,
                 "All edges except 6 shared added to graph");

        destroyVertexGraph(&graph);
    }

    TEST(hole) {
        VertexGraph graph;
        H3Index set[] = {0x892830828c7ffff, 0x892830828d7ffff,
                         0x8928308289bffff, 0x89283082813ffff,
                         0x8928308288fffff, 0x89283082883ffff};
        int numHexes = ARRAY_SIZE(set);

        h3SetToVertexGraph(set, numHexes, &graph);
        t_assert(graph.size == (6 * 3) + 6,
                 "All outer edges and inner hole edges added to graph");

        destroyVertexGraph(&graph);
    }
}
