uber / geojson2h3

Conversion utilities between H3 indexes and GeoJSON
Apache License 2.0
226 stars 22 forks source link

featureToH3Set is not deterministic (reproducible) #7

Closed christophercliff closed 3 years ago

christophercliff commented 5 years ago

node v10.16.0 (also in Chrome) geojson2h3 v1.0.1

Using test data calls.json from https://gist.github.com/christophercliff/dffe5c23c8fa396c40b7ab774ee2de72.

calls.json has three sets of args, [a, b, c], like:

[[Feature, number], [Feature, number], [Feature, number]]

Calling c alone works:

const assert = require('assert')
const geojson2h3 = require('geojson2h3')
const [a, b, c] = require('./calls.json')

const hexArr = geojson2h3.featureToH3Set(...c)
const hexSet = new Set(hexArr)

assert(hexArr.length === 11486)
assert(hexSet.size === 11486)

Calling three times in order [a, b, c] produces incorrect output:

const assert = require('assert')
const geojson2h3 = require('geojson2h3')
const [a, b, c] = require('./calls.json')

geojson2h3.featureToH3Set(...a)
geojson2h3.featureToH3Set(...b)
const hexArr = geojson2h3.featureToH3Set(...c)
const hexSet = new Set(hexArr)

assert(hexArr.length === 11486)
assert(hexSet.size === 11486)

The order matters. Calling [a, c], [b, c], [b, a, c] appear to work.

nrabinowitz commented 3 years ago

I believe this to be fixed in https://github.com/uber/h3-js/pull/104, closing unless there's a separate issue.