Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Undirected) Edge indexing mode #654

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The public API of this library consists of the functions declared in file
## [Unreleased]
### Added
- Functions for `cellToChildPos` and `childPosToCell` (#719)
- (Undirected) edge index mode. (#654)

### Fixed
- Fixed possible signed integer overflow in `h3NeighborRotations` (#707)
Expand Down
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ set(LIB_SOURCE_FILES
src/h3lib/include/polygonAlgos.h
src/h3lib/include/h3Index.h
src/h3lib/include/directedEdge.h
src/h3lib/include/edge.h
src/h3lib/include/latLng.h
src/h3lib/include/vec2d.h
src/h3lib/include/vec3d.h
Expand All @@ -153,6 +154,7 @@ set(LIB_SOURCE_FILES
src/h3lib/lib/localij.c
src/h3lib/lib/latLng.c
src/h3lib/lib/directedEdge.c
src/h3lib/lib/edge.c
src/h3lib/lib/mathExtensions.c
src/h3lib/lib/iterators.c
src/h3lib/lib/vertexGraph.c
Expand Down Expand Up @@ -217,6 +219,8 @@ set(OTHER_SOURCE_FILES
src/apps/testapps/testVec3d.c
src/apps/testapps/testDirectedEdge.c
src/apps/testapps/testDirectedEdgeExhaustive.c
src/apps/testapps/testEdge.c
src/apps/testapps/testEdgeExhaustive.c
src/apps/testapps/testLinkedGeo.c
src/apps/testapps/mkRandGeo.c
src/apps/testapps/testH3Api.c
Expand Down Expand Up @@ -254,6 +258,7 @@ set(OTHER_SOURCE_FILES
src/apps/fuzzers/fuzzerVertexes.c
src/apps/fuzzers/fuzzerCompact.c
src/apps/fuzzers/fuzzerDirectedEdge.c
src/apps/fuzzers/fuzzerEdge.c
src/apps/fuzzers/fuzzerLocalIj.c
src/apps/fuzzers/fuzzerPolygonToCells.c
src/apps/fuzzers/fuzzerPolygonToCellsNoHoles.c
Expand All @@ -266,6 +271,7 @@ set(OTHER_SOURCE_FILES
src/apps/benchmarks/benchmarkGridDiskCells.c
src/apps/benchmarks/benchmarkGridPathCells.c
src/apps/benchmarks/benchmarkDirectedEdge.c
src/apps/benchmarks/benchmarkEdge.c
src/apps/benchmarks/benchmarkVertex.c
src/apps/benchmarks/benchmarkIsValidCell.c
src/apps/benchmarks/benchmarkH3Api.c)
Expand Down Expand Up @@ -508,6 +514,7 @@ if(BUILD_FUZZERS)
add_h3_fuzzer(fuzzerVertexes src/apps/fuzzers/fuzzerVertexes.c)
add_h3_fuzzer(fuzzerCompact src/apps/fuzzers/fuzzerCompact.c)
add_h3_fuzzer(fuzzerDirectedEdge src/apps/fuzzers/fuzzerDirectedEdge.c)
add_h3_fuzzer(fuzzerEdge src/apps/fuzzers/fuzzerEdge.c)
add_h3_fuzzer(fuzzerLocalIj src/apps/fuzzers/fuzzerLocalIj.c)
add_h3_fuzzer(fuzzerPolygonToCells src/apps/fuzzers/fuzzerPolygonToCells.c)
add_h3_fuzzer(fuzzerPolygonToCellsNoHoles src/apps/fuzzers/fuzzerPolygonToCellsNoHoles.c)
Expand All @@ -532,6 +539,7 @@ if(BUILD_BENCHMARKS)
add_h3_benchmark(benchmarkGridDiskCells src/apps/benchmarks/benchmarkGridDiskCells.c)
add_h3_benchmark(benchmarkGridPathCells src/apps/benchmarks/benchmarkGridPathCells.c)
add_h3_benchmark(benchmarkDirectedEdge src/apps/benchmarks/benchmarkDirectedEdge.c)
add_h3_benchmark(benchmarkEdge src/apps/benchmarks/benchmarkEdge.c)
add_h3_benchmark(benchmarkVertex src/apps/benchmarks/benchmarkVertex.c)
add_h3_benchmark(benchmarkIsValidCell src/apps/benchmarks/benchmarkIsValidCell.c)
add_h3_benchmark(benchmarkCellsToLinkedMultiPolygon src/apps/benchmarks/benchmarkCellsToLinkedMultiPolygon.c)
Expand Down
2 changes: 2 additions & 0 deletions CMakeTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ add_h3_test(testPolygonToCells src/apps/testapps/testPolygonToCells.c)
add_h3_test(testPolygonToCellsReported src/apps/testapps/testPolygonToCellsReported.c)
add_h3_test(testVertexGraph src/apps/testapps/testVertexGraph.c)
add_h3_test(testDirectedEdge src/apps/testapps/testDirectedEdge.c)
add_h3_test(testEdge src/apps/testapps/testEdge.c)
add_h3_test(testLatLng src/apps/testapps/testLatLng.c)
add_h3_test(testBBox src/apps/testapps/testBBox.c)
add_h3_test(testVertex src/apps/testapps/testVertex.c)
Expand All @@ -210,6 +211,7 @@ add_h3_test_with_arg(testH3NeighborRotations src/apps/testapps/testH3NeighborRot

# The "Exhaustive" part of the test name is used by the test-fast to exclude these files.
# test-fast exists so that Travis CI can run Valgrind on tests without taking a very long time.
add_h3_test(testEdgeExhaustive src/apps/testapps/testEdgeExhaustive.c)
add_h3_test(testDirectedEdgeExhaustive src/apps/testapps/testDirectedEdgeExhaustive.c)
add_h3_test(testVertexExhaustive src/apps/testapps/testVertexExhaustive.c)
add_h3_test(testCellToLocalIjExhaustive src/apps/testapps/testCellToLocalIjExhaustive.c)
Expand Down
35 changes: 35 additions & 0 deletions src/apps/benchmarks/benchmarkEdge.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2022 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 "h3api.h"
#include "latLng.h"

// Fixtures (arbitrary res 9 hexagon)
H3Index edges[6] = {0};
H3Index hex = 0x89283080ddbffff;

BEGIN_BENCHMARKS();

CellBoundary outBoundary;
H3_EXPORT(cellToEdges)(hex, edges);

BENCHMARK(edgeToBoundary, 10000, {
for (int i = 0; i < 6; i++) {
H3_EXPORT(edgeToBoundary)(edges[i], &outBoundary);
}
});

END_BENCHMARKS();
6 changes: 6 additions & 0 deletions src/apps/fuzzers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ The public API of H3 is covered in the following fuzzers:
| directedEdgeToCells | [fuzzerDirectedEdge](./fuzzerDirectedEdge.c)
| originToDirectedEdges | [fuzzerDirectedEdge](./fuzzerDirectedEdge.c)
| directedEdgeToBoundary | [fuzzerDirectedEdge](./fuzzerDirectedEdge.c)
| cellsToEdge | [fuzzerEdge](./fuzzerEdge.c)
| isValidEdge | [fuzzerEdge](./fuzzerEdge.c)
| edgeToCells | [fuzzerEdge](./fuzzerEdge.c)
| cellToEdges | [fuzzerEdge](./fuzzerEdge.c)
| edgeToBoundary | [fuzzerEdge](./fuzzerEdge.c)
| directedEdgeToEdge | [fuzzerEdge](./fuzzerEdge.c)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit (and here just because it provides a nice summary): thoughts on the value of a edgeToDirectedEdges function?

| cellToVertex | [fuzzerVertexes](./fuzzerVertexes.c)
| cellToVertexes | [fuzzerVertexes](./fuzzerVertexes.c)
| vertexToLatLng | [fuzzerVertexes](./fuzzerVertexes.c)
Expand Down
51 changes: 51 additions & 0 deletions src/apps/fuzzers/fuzzerEdge.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2022 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
* @brief Fuzzer program for cellsToEdge and related functions
*/

#include "aflHarness.h"
#include "h3api.h"
#include "utility.h"

typedef struct {
H3Index index;
H3Index index2;
} inputArgs;

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (size < sizeof(inputArgs)) {
return 0;
}
const inputArgs *args = (const inputArgs *)data;

// Note that index and index2 need to be plausibly neighbors
// for most of these
H3Index out;
H3_EXPORT(cellsToEdge)(args->index, args->index2, &out);
H3_EXPORT(isValidEdge)(args->index);
H3Index out2[2];
H3_EXPORT(edgeToCells)(args->index, out2);
H3Index out6[6];
H3_EXPORT(cellToEdges)(args->index, out6);
CellBoundary bndry;
H3_EXPORT(edgeToBoundary)(args->index, &bndry);
H3_EXPORT(directedEdgeToEdge)(args->index, out2);

return 0;
}

AFL_HARNESS_MAIN(sizeof(inputArgs));
Loading