From 80e39ec1d61e5c292445d71be968434bdfb0787b Mon Sep 17 00:00:00 2001 From: Cyrille Faucheux Date: Fri, 20 Jan 2023 15:10:18 +0100 Subject: [PATCH] Unquantize Points during presimplify Simplifying a topology requires the removal of the transform (if any). This is done it the presimplify() function. presimplify() only does that on arcs, not points. If the topology is quantized again later, points will be quantized twice, yielding invalid values. With this commit, presimplify() also remove the transform of Point & MultiPoint objects. --- src/presimplify.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/presimplify.js b/src/presimplify.js index eca8289..2f72454 100644 --- a/src/presimplify.js +++ b/src/presimplify.js @@ -64,12 +64,30 @@ export default function(topology, weight) { return arc; }); + for (const key in topology.objects) { + topology.objects[key] = unquantizeGeometry(topology.objects[key]); + } + function update(triangle) { heap.remove(triangle); triangle[1][2] = weight(triangle); heap.push(triangle); } + function unquantizeGeometry(input) { + var output; + switch (input.type) { + case "GeometryCollection": output = {type: "GeometryCollection", geometries: input.geometries.map(unquantizeGeometry)}; break; + case "Point": output = {type: "Point", coordinates: point(input.coordinates)}; break; + case "MultiPoint": output = {type: "MultiPoint", coordinates: input.coordinates.map(point)}; break; + default: return input; + } + if (input.id != null) output.id = input.id; + if (input.bbox != null) output.bbox = input.bbox; + if (input.properties != null) output.properties = input.properties; + return output; + } + return { type: "Topology", bbox: topology.bbox,