simplify-geometry
simplify-geometry copied to clipboard
simplifyGeometry() simplifies too much for tolerance=0
I'm working on a project that use your simplifyGeometry function a lot (https://github.com/Wilkins/gpx-simplify-optimizer).
And I found that sometimes with a tolerance = 0
it simplifies more than it should.
I made a little snippet to reproduce my problem :
var simplifyGeometry = require("./index");
var case1 = [
[-60.501,47.001,0],
[-60.323,46.867,0],
[-60.317,46.861,0], // This value get stripped
[-60.311,46.855,0],
[-60.305,46.834,0],
[-60.606,46.21,0],
[-60.606,46.21,0],
[-60.605,46.211,0],
[-60.6,46.201,0],
[-60.736,46.057,0],
[-60.501,47.001,0]
];
// Same as case 1 but narrowed
var case2 = [
[-60.323,46.867,0],
[-60.317,46.861,0], // This value get stripped
[-60.311,46.855,0],
];
var case3 = [
[45.759,-63.257],
[45.754,-63.257], // This value get stripped
[45.743,-63.257]
];
var case4 = [
[45.294,-61.007],
[45.294,-61.017], // This value get stripped
[45.294,-61.027]
];
console.log(simplifyGeometry(case1, 0));
console.log(simplifyGeometry(case2, 0));
console.log(simplifyGeometry(case3, 0));
console.log(simplifyGeometry(case4, 0));
I guess this is a geometry reason, but I think it should not strip anything if tolerance=0
.
Maybe a simple if (tolerance === 0) { return points; }
would correct this particular case.
But maybe it's a more complex geometry problem that need to be solved for other cases.