From a578f1c7fe30cc637bffe9a68c51ffb081bccf48 Mon Sep 17 00:00:00 2001 From: Denis Date: Sun, 29 Oct 2017 14:37:27 -0400 Subject: [PATCH] Add GeoJSON test fixture --- package.json | 2 +- test/geo-voronoi-test.js | 18 +- test/in/points.json | 105 +++++++ test/out/points.json | 621 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 743 insertions(+), 3 deletions(-) create mode 100644 test/in/points.json create mode 100644 test/out/points.json diff --git a/package.json b/package.json index 9f5c9d0..ad56ca5 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,6 @@ "package-preamble": "0.1", "rollup": "0.49", "tape": "4", - "uglify-js": "32" + "uglify-js": "*" } } diff --git a/test/geo-voronoi-test.js b/test/geo-voronoi-test.js index d3346e4..17fc88f 100644 --- a/test/geo-voronoi-test.js +++ b/test/geo-voronoi-test.js @@ -1,5 +1,7 @@ -var tape = require("tape"), - geoVoronoi = require("../"); +var fs = require('fs'); +var path = require('path'); +var tape = require("tape"); +var geoVoronoi = require("../"); tape("geoVoronoi() returns a Diagram.", function(test) { test.equal(typeof geoVoronoi, 'object'); @@ -43,3 +45,15 @@ tape("geoVoronoi.triangles(sites) returns circumcenters.", function(test) { test.ok( (Math.abs(u[0]-v[0]) < 1e-6) && (Math.abs(u[1]-v[1]) < 1e-6) ); test.end(); }); + +tape('geoVoronoi.polygons(points) saves geojson', function(test) { + var points = require('./in/points') + var result = geoVoronoi.geoVoronoi().polygons(points) + + // Save result to GeoJSON + result.features = result.features.concat(points.features) + var out = path.join(__dirname, 'out', 'points.json') + if (process.env.REGEN) fs.writeFileSync(out, JSON.stringify(result, null, 2)) + test.deepEqual(JSON.parse(fs.readFileSync(out)), result) + test.end(); +}); diff --git a/test/in/points.json b/test/in/points.json new file mode 100644 index 0000000..ae7da5b --- /dev/null +++ b/test/in/points.json @@ -0,0 +1,105 @@ +{ + "type": "FeatureCollection", + "bbox": [143, -38, 146, -35], + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 144.33837890625, + -37.14280344371683 + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 144.931640625, + -37.35269280367274 + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 145.140380859375, + -36.456636011596196 + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 145.469970703125, + -36.77409249464194 + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 145.755615234375, + -37.090239803072066 + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 145.4150390625, + -37.52715361723378 + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 145.887451171875, + -37.483576550426996 + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 144.60205078125, + -36.57142382346275 + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 144.86572265625, + -37.596824001083654 + ] + } + } + ] +} \ No newline at end of file diff --git a/test/out/points.json b/test/out/points.json new file mode 100644 index 0000000..4d5f0c7 --- /dev/null +++ b/test/out/points.json @@ -0,0 +1,621 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 144.79842834742678, + -36.95343291262166 + ], + [ + 144.54202588904857, + -37.41351460403107 + ], + [ + -34.73845305969832, + 36.880739391555835 + ], + [ + -34.80327732898669, + 37.06887028009773 + ], + [ + 144.79842834742678, + -36.95343291262166 + ] + ] + ] + }, + "properties": { + "site": { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 144.33837890625, + -37.14280344371683 + ] + }, + "index": 0 + }, + "sitecoordinates": [ + 144.33837890625, + -37.14280344371683 + ], + "neighbours": [ + 1, + 7, + 8 + ] + } + }, + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 144.94826578790284, + -36.912911676242565 + ], + [ + 145.2914453460504, + -37.116714209309194 + ], + [ + 145.32235534068843, + -37.1783781179493 + ], + [ + 145.1307598462881, + -37.513973802114776 + ], + [ + 144.54202588904857, + -37.41351460403107 + ], + [ + 144.79842834742678, + -36.95343291262166 + ], + [ + 144.94826578790284, + -36.912911676242565 + ] + ] + ] + }, + "properties": { + "site": { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 144.931640625, + -37.35269280367274 + ] + }, + "index": 1 + }, + "sitecoordinates": [ + 144.931640625, + -37.35269280367274 + ], + "neighbours": [ + 0, + 7, + 3, + 4, + 8, + 5 + ] + } + }, + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -36.003882702583915, + 37.65824934176859 + ], + [ + -40.23506836412599, + 40.0249481111103 + ], + [ + 144.9772377844883, + -36.833531524348615 + ], + [ + -34.91161514364437, + 37.16584766868451 + ], + [ + -36.003882702583915, + 37.65824934176859 + ] + ] + ] + }, + "properties": { + "site": { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 145.140380859375, + -36.456636011596196 + ] + }, + "index": 2 + }, + "sitecoordinates": [ + 145.140380859375, + -36.456636011596196 + ], + "neighbours": [ + 3, + 7 + ] + } + }, + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 145.2914453460504, + -37.116714209309194 + ], + [ + 144.94826578790284, + -36.912911676242565 + ], + [ + 144.9772377844883, + -36.833531524348615 + ], + [ + -40.23506836412599, + 40.0249481111103 + ], + [ + 145.2914453460504, + -37.116714209309194 + ] + ] + ] + }, + "properties": { + "site": { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 145.469970703125, + -36.77409249464194 + ] + }, + "index": 3 + }, + "sitecoordinates": [ + 145.469970703125, + -36.77409249464194 + ], + "neighbours": [ + 7, + 1, + 2, + 4 + ] + } + }, + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -40.23506836412599, + 40.0249481111103 + ], + [ + -36.003882702583915, + 37.65824934176859 + ], + [ + 145.62539040977168, + -37.328319473898695 + ], + [ + 145.32235534068843, + -37.1783781179493 + ], + [ + 145.2914453460504, + -37.116714209309194 + ], + [ + -40.23506836412599, + 40.0249481111103 + ] + ] + ] + }, + "properties": { + "site": { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 145.755615234375, + -37.090239803072066 + ] + }, + "index": 4 + }, + "sitecoordinates": [ + 145.755615234375, + -37.09023980307207 + ], + "neighbours": [ + 3, + 1, + 5, + 6 + ] + } + }, + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 145.32235534068843, + -37.1783781179493 + ], + [ + 145.62539040977168, + -37.328319473898695 + ], + [ + 147.03986813191804, + -45.84546490443107 + ], + [ + 145.1307598462881, + -37.513973802114776 + ], + [ + 145.32235534068843, + -37.1783781179493 + ] + ] + ] + }, + "properties": { + "site": { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 145.4150390625, + -37.52715361723378 + ] + }, + "index": 5 + }, + "sitecoordinates": [ + 145.4150390625, + -37.527153617233786 + ], + "neighbours": [ + 1, + 4, + 6, + 8 + ] + } + }, + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -34.80327732898669, + 37.06887028009773 + ], + [ + -34.73845305969832, + 36.880739391555835 + ], + [ + 147.03986813191804, + -45.84546490443107 + ], + [ + 145.62539040977168, + -37.328319473898695 + ], + [ + -36.003882702583915, + 37.65824934176859 + ], + [ + -34.91161514364437, + 37.16584766868451 + ], + [ + -34.80327732898669, + 37.06887028009773 + ] + ] + ] + }, + "properties": { + "site": { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 145.887451171875, + -37.483576550426996 + ] + }, + "index": 6 + }, + "sitecoordinates": [ + 145.887451171875, + -37.483576550426996 + ], + "neighbours": [ + 5, + 4, + 8 + ] + } + }, + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 144.9772377844883, + -36.833531524348615 + ], + [ + 144.94826578790284, + -36.912911676242565 + ], + [ + 144.79842834742678, + -36.95343291262166 + ], + [ + -34.80327732898669, + 37.06887028009773 + ], + [ + -34.91161514364437, + 37.16584766868451 + ], + [ + 144.9772377844883, + -36.833531524348615 + ] + ] + ] + }, + "properties": { + "site": { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 144.60205078125, + -36.57142382346275 + ] + }, + "index": 7 + }, + "sitecoordinates": [ + 144.60205078125, + -36.57142382346275 + ], + "neighbours": [ + 3, + 1, + 2, + 0 + ] + } + }, + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 147.03986813191804, + -45.84546490443107 + ], + [ + -34.73845305969832, + 36.880739391555835 + ], + [ + 144.54202588904857, + -37.41351460403107 + ], + [ + 145.1307598462881, + -37.513973802114776 + ], + [ + 147.03986813191804, + -45.84546490443107 + ] + ] + ] + }, + "properties": { + "site": { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 144.86572265625, + -37.596824001083654 + ] + }, + "index": 8 + }, + "sitecoordinates": [ + 144.86572265625, + -37.596824001083654 + ], + "neighbours": [ + 1, + 5, + 0, + 6 + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 144.33837890625, + -37.14280344371683 + ] + }, + "index": 0 + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 144.931640625, + -37.35269280367274 + ] + }, + "index": 1 + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 145.140380859375, + -36.456636011596196 + ] + }, + "index": 2 + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 145.469970703125, + -36.77409249464194 + ] + }, + "index": 3 + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 145.755615234375, + -37.090239803072066 + ] + }, + "index": 4 + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 145.4150390625, + -37.52715361723378 + ] + }, + "index": 5 + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 145.887451171875, + -37.483576550426996 + ] + }, + "index": 6 + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 144.60205078125, + -36.57142382346275 + ] + }, + "index": 7 + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Point", + "coordinates": [ + 144.86572265625, + -37.596824001083654 + ] + }, + "index": 8 + } + ] +} \ No newline at end of file