async function buildTopology(traceResult, options) {
options = Object.assign({ smooth: true }, options);
options.round ??= options.smooth;
const geojson = await buildGeoJsonRaw(traceResult);
let topology = topojson.topology({traced: geojson});
topology.properties = { options };
topology.bbox = traceResult.bbox;
if (options.smooth) {
smoothTopology(topology, traceResult.coordClasses);
const simplified = topojson.presimplify(topology);
simplified.arcs.flat()
.filter(c => c[2] == 0 && traceResult.coordClasses.get(c) == "junction")
.forEach(c => c[2] = Infinity);
topology = topojson.simplify(simplified, 0.5 / smoothTopology.roundFactor);
if (options.round) scaleTopology(topology, smoothTopology.roundFactor);
}
return topology;
}