This commit is contained in:
Alfred Melch 2019-07-25 09:53:20 +02:00
parent 8832e8d0ba
commit 283f685dc6

View File

@ -21,72 +21,59 @@ import {
} from '../../lib/wasm-util/coordinates.js' } from '../../lib/wasm-util/coordinates.js'
export async function simplify_nth_point(coords, n) { export async function simplify_nth_point(coords, n) {
const module = await getModule() return await callSimplification('nth_point', coords, [n])
const buffer = storeCoords(module, coords)
const result = module.nth_point(buffer, coords.length * 2, n)
module._free(buffer)
return unflattenCoords(result)
} }
export async function simplify_radial_distance(coords, tol) { export async function simplify_radial_distance(coords, tol) {
const module = await getModule() return await callSimplification('radial_distance', coords, [tol])
const buffer = storeCoords(module, coords)
const result = module.radial_distance(buffer, coords.length * 2, tol)
module._free(buffer)
return unflattenCoords(result)
} }
export async function simplify_perpendicular_distance(coords, tol, repeat) { export async function simplify_perpendicular_distance(coords, tol, repeat) {
const module = await getModule() const params = [tol, repeat]
const buffer = storeCoords(module, coords) return await callSimplification('perpendicular_distance', coords, params)
const result = module.perpendicular_distance(
buffer,
coords.length * 2,
tol,
repeat
)
module._free(buffer)
return unflattenCoords(result)
} }
export async function simplify_reumann_witkam(coords, tol) { export async function simplify_reumann_witkam(coords, tol) {
const module = await getModule() return await callSimplification('reumann_witkam', coords, [tol])
const buffer = storeCoords(module, coords)
const result = module.reumann_witkam(buffer, coords.length * 2, tol)
module._free(buffer)
return unflattenCoords(result)
} }
export async function simplify_opheim(coords, minTol, maxTol) { export async function simplify_opheim(coords, minTol, maxTol) {
const module = await getModule() return await callSimplification('opheim', coords, [minTol, maxTol])
const buffer = storeCoords(module, coords)
const result = module.opheim(buffer, coords.length * 2, minTol, maxTol)
module._free(buffer)
return unflattenCoords(result)
} }
export async function simplify_lang(coords, tol, lookAhead) { export async function simplify_lang(coords, tol, lookAhead) {
const module = await getModule() return await callSimplification('lang', coords, [tol, lookAhead])
const buffer = storeCoords(module, coords)
const result = module.lang(buffer, coords.length * 2, tol, lookAhead)
module._free(buffer)
return unflattenCoords(result)
} }
export async function simplify_douglas_peucker(coords, tol) { export async function simplify_douglas_peucker(coords, tol) {
return await callSimplification('douglas_peucker', coords, [tol])
}
export async function simplify_douglas_peucker_n(coords, count) {
return await callSimplification('douglas_peucker_n', coords, [count])
}
async function callSimplification(name, coords, params) {
if (!isSimplificationRoutine(name)) throw Error(`Routine ${name} not known`)
const module = await getModule() const module = await getModule()
const buffer = storeCoords(module, coords) const buffer = storeCoords(module, coords)
const result = module.douglas_peucker(buffer, coords.length * 2, tol) const result = module[name](buffer, coords.length * 2, ...params)
module._free(buffer) module._free(buffer)
return unflattenCoords(result) return unflattenCoords(result)
} }
export async function simplify_douglas_peucker_n(coords, count) { const simplificationRoutines = [
const module = await getModule() 'nth_point',
const buffer = storeCoords(module, coords) 'radial_distance',
const result = module.douglas_peucker_n(buffer, coords.length * 2, count) 'perpendicular_distance',
module._free(buffer) 'reumann_witkam',
return unflattenCoords(result) 'opheim',
'lang',
'douglas_peucker',
'douglas_peucker_n'
]
function isSimplificationRoutine(name) {
return simplificationRoutines.indexOf(name) !== -1
} }
let emscriptenModule let emscriptenModule