Skip to content

Commit c78deef

Browse files
author
Nicholas Rabinowitz
committed
Fix bug in pentagon-to-neighbor getH3UnidirectionalEdge
1 parent 81812d2 commit c78deef

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/apps/testapps/testH3UniEdge.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,22 @@ SUITE(h3UniEdge) {
124124
}
125125

126126
TEST(getH3UnidirectionalEdgeFromPentagon) {
127-
H3Index pentagon;
128-
setH3Index(&pentagon, 0, 4, 0);
129-
H3Index adjacent;
130-
setH3Index(&adjacent, 0, 8, 0);
131-
132-
H3Index edge = H3_EXPORT(getH3UnidirectionalEdge)(pentagon, adjacent);
133-
t_assert(edge != 0, "Produces a valid edge");
127+
H3Index pentagon = 0x801dfffffffffff;
128+
H3Index ring[7] = {0};
129+
H3Index edge;
130+
131+
H3_EXPORT(kRing)(pentagon, 1, ring);
132+
133+
for (int i = 0; i < 7; i++) {
134+
H3Index neighbor = ring[i];
135+
if (neighbor == pentagon || neighbor == 0) continue;
136+
edge = H3_EXPORT(getH3UnidirectionalEdge)(pentagon, neighbor);
137+
t_assert(H3_EXPORT(h3UnidirectionalEdgeIsValid)(edge),
138+
"pentagon-to-neighbor is a valid edge");
139+
edge = H3_EXPORT(getH3UnidirectionalEdge)(neighbor, pentagon);
140+
t_assert(H3_EXPORT(h3UnidirectionalEdgeIsValid)(edge),
141+
"neighbor-to-pentagon is a valid edge");
142+
}
134143
}
135144

136145
TEST(h3UnidirectionalEdgeIsValid) {

src/h3lib/lib/h3UniEdge.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,14 @@ H3Index H3_EXPORT(getH3UnidirectionalEdge)(H3Index origin,
110110
H3Index output = origin;
111111
H3_SET_MODE(output, H3_UNIEDGE_MODE);
112112

113+
bool isPentagon = H3_EXPORT(h3IsPentagon)(origin);
114+
113115
// Checks each neighbor, in order, to determine which direction the
114116
// destination neighbor is located. Skips CENTER_DIGIT since that
115117
// would be this index.
116118
H3Index neighbor;
117-
for (Direction direction = K_AXES_DIGIT; direction < NUM_DIGITS;
118-
direction++) {
119+
for (Direction direction = isPentagon ? J_AXES_DIGIT : K_AXES_DIGIT;
120+
direction < NUM_DIGITS; direction++) {
119121
int rotations = 0;
120122
neighbor = h3NeighborRotations(origin, direction, &rotations);
121123
if (neighbor == destination) {

0 commit comments

Comments
 (0)