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

Add h3ToIj #102

Merged
merged 18 commits into from
Oct 3, 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
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ The public API of this library consists of the functions declared in file
[h3api.h](./src/h3lib/include/h3api.h).

## [Unreleased]
### Fixed
- Added #include <stdio.h> to benchmark.h
### Added
- `experimentalH3ToLocalIj` function for getting local coordinates for an index. (#102)
- `experimentalLocalIjToH3` function for getting an index from local coordinates. (#102)
- Benchmarks for the kRing method for k's of size 10, 20, 30, and 40.
### Changed
- Internal `h3ToIjk` function renamed to `h3ToLocalIjk`. (#102)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this supposed to be h3ToLocalIj like elsewhere or no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, as below the IJK functions need to be kept for internal implementation.

- `h3ToIjk` filter application replaced with `h3ToLocalIj`. (#102)
### Fixed
- Added `#include <stdio.h>` to `benchmark.h` (#142)

## [3.1.1] - 2018-08-29
### Fixed
Expand Down
14 changes: 10 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ set(LIB_SOURCE_FILES
src/h3lib/include/vec2d.h
src/h3lib/include/vec3d.h
src/h3lib/include/linkedGeo.h
src/h3lib/include/localij.h
src/h3lib/include/baseCells.h
src/h3lib/include/faceijk.h
src/h3lib/include/vertexGraph.h
Expand All @@ -108,6 +109,7 @@ set(LIB_SOURCE_FILES
src/h3lib/lib/vec2d.c
src/h3lib/lib/vec3d.c
src/h3lib/lib/linkedGeo.c
src/h3lib/lib/localij.c
src/h3lib/lib/geoCoord.c
src/h3lib/lib/h3UniEdge.c
src/h3lib/lib/mathExtensions.c
Expand All @@ -130,7 +132,7 @@ set(EXAMPLE_SOURCE_FILES
examples/edge.c)
set(OTHER_SOURCE_FILES
src/apps/filters/h3ToGeo.c
src/apps/filters/h3ToIjk.c
src/apps/filters/h3ToLocalIj.c
src/apps/filters/h3ToComponents.c
src/apps/filters/geoToH3.c
src/apps/filters/h3ToGeoBoundary.c
Expand Down Expand Up @@ -162,7 +164,9 @@ set(OTHER_SOURCE_FILES
src/apps/testapps/mkRandGeo.c
src/apps/testapps/testH3Api.c
src/apps/testapps/testH3SetToLinkedGeo.c
src/apps/testapps/testH3ToIjk.c
src/apps/testapps/testH3ToLocalIj.c
src/apps/testapps/testH3Distance.c
src/apps/testapps/testCoordIj.c
src/apps/miscapps/h3ToGeoBoundaryHier.c
src/apps/miscapps/h3ToGeoHier.c
src/apps/miscapps/generateBaseCellNeighbors.c
Expand Down Expand Up @@ -288,7 +292,7 @@ endmacro()
add_h3_executable(geoToH3 src/apps/filters/geoToH3.c ${APP_SOURCE_FILES})
add_h3_executable(h3ToComponents src/apps/filters/h3ToComponents.c ${APP_SOURCE_FILES})
add_h3_executable(h3ToGeo src/apps/filters/h3ToGeo.c ${APP_SOURCE_FILES})
add_h3_executable(h3ToIjk src/apps/filters/h3ToIjk.c ${APP_SOURCE_FILES})
add_h3_executable(h3ToLocalIj src/apps/filters/h3ToLocalIj.c ${APP_SOURCE_FILES})
add_h3_executable(h3ToGeoBoundary src/apps/filters/h3ToGeoBoundary.c ${APP_SOURCE_FILES})
add_h3_executable(hexRange src/apps/filters/hexRange.c ${APP_SOURCE_FILES})
add_h3_executable(kRing src/apps/filters/kRing.c ${APP_SOURCE_FILES})
Expand Down Expand Up @@ -460,7 +464,9 @@ if(BUILD_TESTING)
add_h3_test(testPolygon src/apps/testapps/testPolygon.c)
add_h3_test(testVec2d src/apps/testapps/testVec2d.c)
add_h3_test(testVec3d src/apps/testapps/testVec3d.c)
add_h3_test(testH3ToIjk src/apps/testapps/testH3ToIjk.c)
add_h3_test(testH3ToLocalIj src/apps/testapps/testH3ToLocalIj.c)
add_h3_test(testH3Distance src/apps/testapps/testH3Distance.c)
add_h3_test(testCoordIj src/apps/testapps/testCoordIj.c)

add_h3_test_with_arg(testH3NeighborRotations src/apps/testapps/testH3NeighborRotations.c 0)
add_h3_test_with_arg(testH3NeighborRotations src/apps/testapps/testH3NeighborRotations.c 1)
Expand Down
21 changes: 12 additions & 9 deletions src/apps/filters/h3ToIjk.c → src/apps/filters/h3ToLocalIj.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@
* limitations under the License.
*/
/** @file
* @brief stdin/stdout filter that converts from H3 indexes to relative IJK
* @brief stdin/stdout filter that converts from H3 indexes to local IJ
* coordinates. This is experimental.
*
* usage: `h3ToIjk [origin]`
* usage: `h3ToLocalIj [origin]`
*
* The program reads H3 indexes from stdin and outputs the corresponding
* IJK coordinates to stdout, until EOF is encountered. The H3 indexes
* should be in integer form. `-1 -1 -1` is printed if the IJK coordinates
* IJ coordinates to stdout, until EOF is encountered. The H3 indexes
* should be in integer form. `NA` is printed if the IJ coordinates
* could not be obtained.
*
* `origin` indicates the origin (or anchoring) index for the IJK coordinate
* `origin` indicates the origin (or anchoring) index for the IJ coordinate
* space.
*
* This program has the same limitations as the `experimentalH3ToLocalIj`
* function.
*/

#include <inttypes.h>
Expand All @@ -37,11 +40,11 @@
#include "utility.h"

void doCell(H3Index h, H3Index origin) {
CoordIJK ijk;
if (h3ToIjk(origin, h, &ijk)) {
printf("-1 -1 -1\n");
CoordIJ ij;
if (H3_EXPORT(experimentalH3ToLocalIj)(origin, h, &ij)) {
printf("NA\n");
} else {
printf("%d %d %d\n", ijk.i, ijk.j, ijk.k);
printf("%d %d\n", ij.i, ij.j);
}
}

Expand Down
65 changes: 65 additions & 0 deletions src/apps/testapps/testCoordIj.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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
* @brief tests IJ grid functions and IJK distance functions.
*
* usage: `testCoordIj`
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "algos.h"
#include "baseCells.h"
#include "constants.h"
#include "h3Index.h"
#include "h3api.h"
#include "localij.h"
#include "stackAlloc.h"
#include "test.h"
#include "utility.h"

SUITE(coordIj) {
TEST(ijkToIj_zero) {
CoordIJK ijk = {0};
CoordIJ ij = {0};

ijkToIj(&ijk, &ij);
t_assert(ij.i == 0, "ij.i zero");
t_assert(ij.j == 0, "ij.j zero");

ijToIjk(&ij, &ijk);
t_assert(ijk.i == 0, "ijk.i zero");
t_assert(ijk.j == 0, "ijk.j zero");
t_assert(ijk.k == 0, "ijk.k zero");
}

TEST(ijkToIj_roundtrip) {
for (Direction dir = CENTER_DIGIT; dir < NUM_DIGITS; dir++) {
CoordIJK ijk = {0};
_neighbor(&ijk, dir);

CoordIJ ij = {0};
ijkToIj(&ijk, &ij);

CoordIJK recovered = {0};
ijToIjk(&ij, &recovered);

t_assert(_ijkMatches(&ijk, &recovered),
"got same ijk coordinates back");
}
}
}
Loading