Skip to content

Commit 2fd690a

Browse files
author
Nick Rabinowitz
authored
Merge pull request #384 from nrabinowitz/pentagon-edge-fix
Fix bug in pentagon-to-neighbor getH3UnidirectionalEdge
2 parents 81812d2 + a4cdf4a commit 2fd690a

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/apps/testapps/testH3UniEdge.c

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

126126
TEST(getH3UnidirectionalEdgeFromPentagon) {
127+
H3Index pentagons[NUM_PENTAGONS] = {0};
128+
H3Index ring[7] = {0};
127129
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");
130+
H3Index edge;
131+
132+
for (int res = 0; res < 16; res++) {
133+
H3_EXPORT(getPentagonIndexes)(res, pentagons);
134+
for (int p = 0; p < NUM_PENTAGONS; p++) {
135+
pentagon = pentagons[p];
136+
H3_EXPORT(kRing)(pentagon, 1, ring);
137+
138+
for (int i = 0; i < 7; i++) {
139+
H3Index neighbor = ring[i];
140+
if (neighbor == pentagon || neighbor == H3_NULL) continue;
141+
edge =
142+
H3_EXPORT(getH3UnidirectionalEdge)(pentagon, neighbor);
143+
t_assert(H3_EXPORT(h3UnidirectionalEdgeIsValid)(edge),
144+
"pentagon-to-neighbor is a valid edge");
145+
edge =
146+
H3_EXPORT(getH3UnidirectionalEdge)(neighbor, pentagon);
147+
t_assert(H3_EXPORT(h3UnidirectionalEdgeIsValid)(edge),
148+
"neighbor-to-pentagon is a valid edge");
149+
}
150+
}
151+
}
134152
}
135153

136154
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)