Skip to content

Commit

Permalink
SetToLinkedGeo bug and update to latest C library (#49)
Browse files Browse the repository at this point in the history
* Correctly set next for multipolygon SetToLinkedGeo

* Update h3 C library to v3.7.2
  • Loading branch information
retbrown committed Dec 1, 2021
1 parent e7df2af commit 22412b0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion v3/H3_VERSION
@@ -1 +1 @@
v3.7.1
v3.7.2
5 changes: 5 additions & 0 deletions v3/h3.go
Expand Up @@ -609,6 +609,11 @@ func linkedGeoPolygonFromC(cg *C.LinkedGeoPolygon) LinkedGeoPolygon {
g.First = linkedGeoLoopFromC(cg.first)
g.Last = linkedGeoLoopFromC(cg.last)

if cg.next != nil {
next := linkedGeoPolygonFromC(cg.next)
g.Next = &next
}

return g
}

Expand Down
5 changes: 4 additions & 1 deletion v3/h3_algos.c
Expand Up @@ -317,7 +317,10 @@ H3Index h3NeighborRotations(H3Index origin, Direction dir, int* rotations) {
} else {
Direction oldDigit = H3_GET_INDEX_DIGIT(out, r + 1);
Direction nextDir;
if (isResClassIII(r + 1)) {
if (oldDigit == INVALID_DIGIT) {
// Only possible on invalid input
return H3_NULL;
} else if (isResClassIII(r + 1)) {
H3_SET_INDEX_DIGIT(out, r + 1, NEW_DIGIT_II[oldDigit][dir]);
nextDir = NEW_ADJUSTMENT_II[oldDigit][dir];
} else {
Expand Down
43 changes: 43 additions & 0 deletions v3/h3_test.go
Expand Up @@ -147,6 +147,32 @@ var (
0x872f5a374ffffff,
0x872f5a329ffffff,
},
{
0x89194ad36a3ffff,
0x89194ad3263ffff,
0x89194ad326fffff,
0x89194ad149bffff,
0x89194ad1493ffff,
0x89194ad322bffff,
0x89194ad3277ffff,
0x89194ad338bffff,
0x89194ad3313ffff,
0x89194ad3317ffff,
0x89194ad33bbffff,
0x89194ad3387ffff,
0x89194ad3383ffff,
0x89194ad3397ffff,
0x89194ad33b3ffff,
0x89194ad314fffff,
0x89194ad3143ffff,
0x89194ad315bffff,
0x88194ad369fffff,
0x88194ad361fffff,
0x88194ad363fffff,
0x88194ad30dfffff,
0x88194ad347fffff,
0x88194ad345fffff,
},
}

validGeoCoordB = GeoCoord{
Expand Down Expand Up @@ -501,6 +527,23 @@ func TestSetToLinkedGeo(t *testing.T) {
assert.Equal(t, float64(35.68805899195678), polygon.Last.First.Vertex.Latitude)
assert.Equal(t, float64(139.7268573711303), polygon.Last.First.Vertex.Longitude)
})
t.Run("Multipolygon", func(t *testing.T) {
t.Parallel()
polygon := SetToLinkedGeo(validLinkedIndexes[2])

assert.NotNil(t, polygon.First)
assert.NotNil(t, polygon.Last)
assert.NotNil(t, polygon.Next)

assert.Equal(t, float64(51.49710134101195), polygon.First.First.Vertex.Latitude)
assert.Equal(t, float64(-0.09036943363144687), polygon.First.First.Vertex.Longitude)

assert.Equal(t, float64(51.49794867871118), polygon.Last.First.Vertex.Latitude)
assert.Equal(t, float64(-0.07191264615040037), polygon.Last.First.Vertex.Longitude)

assert.Equal(t, float64(51.53058149905774), polygon.Next.First.First.Vertex.Latitude)
assert.Equal(t, float64(-0.07297959470277668), polygon.Next.First.First.Vertex.Longitude)
})
}

func TestLine(t *testing.T) {
Expand Down

0 comments on commit 22412b0

Please sign in to comment.