8000 Add the formula for number of indexes per resolution by isaacbrodsky · Pull Request #69 · uber/h3 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add the formula for number of indexes per resolution #69

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

Merged
merged 2 commits into from
Jun 8, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ set(OTHER_SOURCE_FILES
src/apps/miscapps/h3ToGeoBoundaryHier.c
src/apps/miscapps/h3ToGeoHier.c
src/apps/miscapps/generateBaseCellNeighbors.c
src/apps/miscapps/generateNumHexagons.c
src/apps/miscapps/generateFaceCenterPoint.c
src/apps/miscapps/h3ToHier.c
src/apps/benchmarks/benchmarkPolyfill.c
Expand Down Expand Up @@ -253,6 +254,7 @@ add_h3_executable(h3ToGeoBoundary src/apps/filters/h3ToGeoBoundary.c ${APP_SOURC
add_h3_executable(hexRange src/apps/filters/hexRange.c ${APP_SOURCE_FILES})
add_h3_executable(kRing src/apps/filters/kRing.c ${APP_SOURCE_FILES})
add_h3_executable(generateBaseCellNeighbors src/apps/miscapps/generateBaseCellNeighbors.c ${APP_SOURCE_FILES})
add_h3_executable(generateNumHexagons src/apps/miscapps/generateNumHexagons.c ${APP_SOURCE_FILES})
add_h3_executable(generateFaceCenterPoint src/apps/miscapps/generateFaceCenterPoint.c ${APP_SOURCE_FILES})
add_h3_executable(h3ToGeoBoundaryHier src/apps/miscapps/h3ToGeoBoundaryHier.c ${APP_SOURCE_FILES})
add_h3_executable(h3ToGeoHier src/apps/miscapps/h3ToGeoHier.c ${APP_SOURCE_FILES})
Expand Down
55 changes: 55 additions & 0 deletions src/apps/miscapps/generateNumHexagons.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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 generateNumHexagons.c
* @brief Generates the tables for numHexagons.
*
* usage: `generateNumHexagons`
*
* This program generates the number of unique indexes (not necessarily
* hexagons) at each H3 resolution. It assumes aperture 7 and 12 pentagons
* per resolution.
*/

#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include "constants.h"

#define NUM_PENTAGONS 12

/**
* Generates and prints the numHexagons table.
*/
static void generate() {
printf("static const int64_t nums[] = {\n");
int64_t count = NUM_BASE_CELLS;
for (int i = 0; i <= MAX_H3_RES; i++) {
printf(" %" PRId64 "L,\n", count);
// Each hexagon has 7 children, and each pentagon has 6 children
count = ((count - NUM_PENTAGONS) * 7) + (NUM_PENTAGONS * 6);
}
printf("};\n");
}

int main(int argc, char* argv[]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively, you could change this to int main(void) and ignore the arguments entirely.

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1

Copy link
Collaborator Author
@isaacbrodsky isaacbrodsky Jun 8, 2018

Choose a reason for hiding this comment

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

If we make that change, I think it should be made to all the filters. edit: by which I mean all the apps its relevant for.

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

generate();
}
0