diff --git a/lib/psimpl-js/index.js b/lib/psimpl-js/index.js index d11a6e1..f19b0ee 100644 --- a/lib/psimpl-js/index.js +++ b/lib/psimpl-js/index.js @@ -14,13 +14,16 @@ import wasmModuleFactory from './psimpl.js' import wasmUrl from './psimpl.wasm' -import { initEmscriptenModule } from '../../lib/initEmscripten.js' -import { storeCoords, unflattenCoords } from '../../lib/heapUtil.js' +import { initEmscriptenModule } from '../../lib/wasm-util/initEmscripten.js' +import { + storeCoords, + unflattenCoords +} from '../../lib/wasm-util/coordinates.js' -export async function simplify_nth_point(coords, tol) { +export async function simplify_nth_point(coords, n) { const module = await getModule() const buffer = storeCoords(module, coords) - const result = module.nth_point(buffer, coords.length * 2, tol) + const result = module.nth_point(buffer, coords.length * 2, n) module._free(buffer) return unflattenCoords(result) } @@ -33,10 +36,15 @@ export async function simplify_radial_distance(coords, tol) { return unflattenCoords(result) } -export async function simplify_perpendicular_distance(coords, tol) { +export async function simplify_perpendicular_distance(coords, tol, repeat) { const module = await getModule() const buffer = storeCoords(module, coords) - const result = module.perpendicular_distance(buffer, coords.length * 2, tol) + const result = module.perpendicular_distance( + buffer, + coords.length * 2, + tol, + repeat + ) module._free(buffer) return unflattenCoords(result) } @@ -49,18 +57,18 @@ export async function simplify_reumann_witkam(coords, tol) { return unflattenCoords(result) } -export async function simplify_opheim(coords, tol) { +export async function simplify_opheim(coords, minTol, maxTol) { const module = await getModule() const buffer = storeCoords(module, coords) - const result = module.opheim(buffer, coords.length * 2, tol) + const result = module.opheim(buffer, coords.length * 2, minTol, maxTol) module._free(buffer) return unflattenCoords(result) } -export async function simplify_lang(coords, tol) { +export async function simplify_lang(coords, tol, lookAhead) { const module = await getModule() const buffer = storeCoords(module, coords) - const result = module.lang(buffer, coords.length * 2, tol) + const result = module.lang(buffer, coords.length * 2, tol, lookAhead) module._free(buffer) return unflattenCoords(result) } @@ -73,10 +81,10 @@ export async function simplify_douglas_peucker(coords, tol) { return unflattenCoords(result) } -export async function simplify_douglas_peucker_n(coords, tol) { +export async function simplify_douglas_peucker_n(coords, count) { const module = await getModule() const buffer = storeCoords(module, coords) - const result = module.douglas_peucker_n(buffer, coords.length * 2, tol) + const result = module.douglas_peucker_n(buffer, coords.length * 2, count) module._free(buffer) return unflattenCoords(result) } diff --git a/lib/psimpl-js/psimpl.cpp b/lib/psimpl-js/psimpl.cpp index 17b4c70..e0dea99 100644 --- a/lib/psimpl-js/psimpl.cpp +++ b/lib/psimpl-js/psimpl.cpp @@ -21,11 +21,11 @@ val radial_distance(uintptr_t ptr, int length, double tol) { return val(typed_memory_view(resultCoords.size(), &resultCoords[0])); } -val perpendicular_distance(uintptr_t ptr, int length, unsigned repeat) { +val perpendicular_distance(uintptr_t ptr, int length, double tol, unsigned repeat) { double* begin = reinterpret_cast(ptr); double* end = begin + length; std::vector resultCoords; - psimpl::simplify_perpendicular_distance<2>(begin, end, repeat, std::back_inserter(resultCoords)); + psimpl::simplify_perpendicular_distance<2>(begin, end, tol, repeat, std::back_inserter(resultCoords)); return val(typed_memory_view(resultCoords.size(), &resultCoords[0])); } diff --git a/lib/psimpl-js/psimpl.js b/lib/psimpl-js/psimpl.js index 9df6034..c4b63b7 100644 --- a/lib/psimpl-js/psimpl.js +++ b/lib/psimpl-js/psimpl.js @@ -19,7 +19,7 @@ var E=0,za=null,G=null;d.preloadedImages={};d.preloadedAudios={};function Aa(){v function Ea(){return d.wasmBinary||!r&&!u||"function"!==typeof fetch?new Promise(function(a){a(Ca())}):fetch(H,{credentials:"same-origin"}).then(function(a){if(!a.ok)throw"failed to load wasm binary file at '"+H+"'";return a.arrayBuffer()}).catch(function(){return Ca()})} function Fa(a){function b(a){d.asm=a.exports;E--;d.monitorRunDependencies&&d.monitorRunDependencies(E);0==E&&(null!==za&&(clearInterval(za),za=null),G&&(a=G,G=null,a()))}function c(a){b(a.instance)}function e(a){Ea().then(function(a){return WebAssembly.instantiate(a,f)}).then(a,function(a){y("failed to asynchronously prepare wasm: "+a);w(a)})}var f={env:a,global:{NaN:NaN,Infinity:Infinity},"global.Math":Math,asm2wasm:fa};E++;d.monitorRunDependencies&&d.monitorRunDependencies(E);if(d.instantiateWasm)try{return d.instantiateWasm(f, b)}catch(g){return y("Module.instantiateWasm callback failed with error: "+g),!1}d.wasmBinary||"function"!==typeof WebAssembly.instantiateStreaming||Aa()||"function"!==typeof fetch?e(c):WebAssembly.instantiateStreaming(fetch(H,{credentials:"same-origin"}),f).then(c,function(a){y("wasm streaming compile failed: "+a);y("falling back to ArrayBuffer instantiation");e(c)});return{}} -d.asm=function(a,b){b.memory=z;b.table=new WebAssembly.Table({initial:94,maximum:94,element:"anyfunc"});b.__memory_base=1024;b.__table_base=0;return Fa(b)};ua.push({Ea:function(){Ga()}});function Ha(){return!!Ha.ya}var Ia=[null,[],[]],I=0;function J(){I+=4;return C[I-4>>2]}var Ja={};function Ka(a){switch(a){case 1:return 0;case 2:return 1;case 4:return 2;case 8:return 3;default:throw new TypeError("Unknown type size: "+a);}}var La=void 0;function K(a){for(var b="";A[a];)b+=La[A[a++]];return b} +d.asm=function(a,b){b.memory=z;b.table=new WebAssembly.Table({initial:96,maximum:96,element:"anyfunc"});b.__memory_base=1024;b.__table_base=0;return Fa(b)};ua.push({Ea:function(){Ga()}});function Ha(){return!!Ha.ya}var Ia=[null,[],[]],I=0;function J(){I+=4;return C[I-4>>2]}var Ja={};function Ka(a){switch(a){case 1:return 0;case 2:return 1;case 4:return 2;case 8:return 3;default:throw new TypeError("Unknown type size: "+a);}}var La=void 0;function K(a){for(var b="";A[a];)b+=La[A[a++]];return b} var L={},M={},Ma={};function Na(a){if(void 0===a)return"_unknown";a=a.replace(/[^a-zA-Z0-9_]/g,"$");var b=a.charCodeAt(0);return 48<=b&&57>=b?"_"+a:a}function Oa(a,b){a=Na(a);return(new Function("body","return function "+a+'() {\n "use strict"; return body.apply(this, arguments);\n};\n'))(b)} function Pa(a){var b=Error,c=Oa(a,function(b){this.name=a;this.message=b;b=Error(b).stack;void 0!==b&&(this.stack=this.toString()+"\n"+b.replace(/^Error(:[^\n]*)?\n/,""))});c.prototype=Object.create(b.prototype);c.prototype.constructor=c;c.prototype.toString=function(){return void 0===this.message?this.name:this.name+": "+this.message};return c}var N=void 0;function O(a){throw new N(a);}var Qa=void 0;function Ra(a){throw new Qa(a);} function P(a,b,c){function e(b){b=c(b);b.length!==a.length&&Ra("Mismatched type converter count");for(var e=0;e