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

Fixes bug in relation area processing #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions encode.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ module.exports = function (item, deps) {
ppositions = []
holes = []
ref0 = -1
closed = false
}
if (!deps[smembers[i].id]) continue
var member = deps[smembers[i].id]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"example": "example"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "tape test/*.js",
"get-data": "wget https://kitties.neocities.org/tmp/alexandria.pbf -O ./example/alexandria.pbf",
"encode-example": "node ./example/encode.js ./example/alexandria.pbf",
"decode-example": "node ./example/decode.js"
Expand Down
122 changes: 122 additions & 0 deletions test/multipolygon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
var decode = require('../decode')
var encode = require('../encode')
var test = require('tape')

// this multipolygon includes two non-overlapping polygon
// geometries and its dependencies. the test ensures that the
// two polygons are represented by the appropriate number of
// cells in the decoded form. 6 cell entries for the 2 polygons

var itemTwoClosedPoly = {
id: 0,
type: 'relation',
tags: {
type: 'multipolygon',
},
members: [{
type: 'way',
id: 100,
role: 'outer'
}, {
type: 'way',
id: 101,
role: 'outer'
}, {
type: 'way',
id: 102,
role: 'outer'
}, {
type: 'way',
id: 103,
role: 'outer'
}]
}

var itemOneClosedPoly = {
id: 1,
type: 'relation',
tags: {
type: 'multipolygon',
},
members: [{
type: 'way',
id: 100,
role: 'outer'
}, {
type: 'way',
id: 101,
role: 'outer'
}]
}

var deps = {
100: {
id: 100,
type: 'way',
refs: [200, 201, 202],
},
101: {
id: 2,
type: 'way',
refs: [202, 203, 200],
},
102: {
id: 3,
type: 'way',
refs: [210, 211, 212],
},
103: {
id: 4,
type: 'way',
refs: [212, 213, 210],
},
200: {
type: 'node',
lon: 10,
lat: 10,
},
201: {
type: 'node',
lon: 20,
lat: 20,
},
202: {
type: 'node',
lon: 10,
lat: 20,
},
203: {
type: 'node',
lon: 0,
lat: 20,
},
210: {
type: 'node',
lon: -10,
lat: -10,
},
211: {
type: 'node',
lon: -20,
lat: -20,
},
212: {
type: 'node',
lon: -10,
lat: -20,
},
213: {
type: 'node',
lon: 0,
lat: -20,
}
}

test('multipolygon', function (t) {
t.plan(2)

var decodedTwoPoly = decode([encode(itemTwoClosedPoly, deps)])
t.assert(Object.keys(decodedTwoPoly.area.cells).length === 6)
var decodedOnePoly = decode([encode(itemOneClosedPoly, deps)])
t.assert(Object.keys(decodedOnePoly.area.cells).length === 3)
})