Add psimpl.js

This commit is contained in:
Alfred Melch 2019-07-19 19:33:27 +02:00
parent a58bf97dee
commit 1ca4dbf890
7 changed files with 300 additions and 1 deletions

14
lib/psimpl-js/Makefile Normal file
View File

@ -0,0 +1,14 @@
OPTIMIZE="-O3"
psimpl.wasm psimpl.js: psimpl.cpp
emcc \
${OPTIMIZE} \
--bind \
--closure 1 \
-s WASM=1 \
-s ALLOW_MEMORY_GROWTH=1 \
-s MODULARIZE=1 \
-s EXPORT_ES6=1 \
-o psimpl.js \
-I ../ \
psimpl.cpp

View File

@ -0,0 +1,39 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
</head>
<body>
<div>Original array: <span id="src">Loading...</span></div>
<div>Simplified array: <span id="dest">Loading...</span></div>
<script type="module">
import moduleFactory from './psimpl.js'
import { storeCoords, unflattenCoords } from '../wasm-util/coordinates.js'
const module = moduleFactory()
const data = [
[0, 0],
[1, 1],
[1, 2],
[2, 2],
[5, 5],
[5, 0],
[6, 10],
[10, 10]
]
document.getElementById('src').innerText = JSON.stringify(data)
module.onRuntimeInitialized = async _ => {
const buffer = storeCoords(module, data)
const result = module.douglas_peucker(buffer, data.length * 2, 2)
module._free(buffer)
const simplified = unflattenCoords(result)
document.getElementById('dest').innerText = JSON.stringify(simplified)
}
</script>
</body>
</html>

89
lib/psimpl-js/index.js Normal file
View File

@ -0,0 +1,89 @@
/*
This file is meant to be processed in the context of an asset bundler.
Specifically the import of 'psimpl.wasm' is meant to be resolved by the
corresponding path to that file. Configure a file loader to resolve .wasm
files (e.g. Webpack: file-loader) accordingly.
Otherwise you have to use the module factory 'psimple.js' manually and
reproduce the steps from below to fit your build context. See example.html.
Other than wrapping the memory handling for convenience this method also makes
sure the module is only loaded once.
*/
import wasmModuleFactory from './psimpl.js'
import wasmUrl from './psimpl.wasm'
import { initEmscriptenModule } from '../../lib/initEmscripten.js'
import { storeCoords, unflattenCoords } from '../../lib/heapUtil.js'
export async function simplify_nth_point(coords, tol) {
const module = await getModule()
const buffer = storeCoords(module, coords)
const result = module.nth_point(buffer, coords.length * 2, tol)
module._free(buffer)
return unflattenCoords(result)
}
export async function simplify_radial_distance(coords, tol) {
const module = await getModule()
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) {
const module = await getModule()
const buffer = storeCoords(module, coords)
const result = module.perpendicular_distance(buffer, coords.length * 2, tol)
module._free(buffer)
return unflattenCoords(result)
}
export async function simplify_reumann_witkam(coords, tol) {
const module = await getModule()
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, tol) {
const module = await getModule()
const buffer = storeCoords(module, coords)
const result = module.opheim(buffer, coords.length * 2, tol)
module._free(buffer)
return unflattenCoords(result)
}
export async function simplify_lang(coords, tol) {
const module = await getModule()
const buffer = storeCoords(module, coords)
const result = module.lang(buffer, coords.length * 2, tol)
module._free(buffer)
return unflattenCoords(result)
}
export async function simplify_douglas_peucker(coords, tol) {
const module = await getModule()
const buffer = storeCoords(module, coords)
const result = module.douglas_peucker(buffer, coords.length * 2, tol)
module._free(buffer)
return unflattenCoords(result)
}
export async function simplify_douglas_peucker_n(coords, tol) {
const module = await getModule()
const buffer = storeCoords(module, coords)
const result = module.douglas_peucker_n(buffer, coords.length * 2, tol)
module._free(buffer)
return unflattenCoords(result)
}
let emscriptenModule
export async function getModule() {
if (!emscriptenModule)
emscriptenModule = initEmscriptenModule(wasmModuleFactory, wasmUrl)
return await emscriptenModule
}

82
lib/psimpl-js/psimpl.cpp Normal file
View File

@ -0,0 +1,82 @@
#include <stdio.h>
#include <emscripten/bind.h>
#include <emscripten/val.h>
#include "psimpl/psimpl.h"
using namespace emscripten;
val nth_point(uintptr_t ptr, int length, int n) {
double* begin = reinterpret_cast<double*>(ptr);
double* end = begin + length;
std::vector<double> resultCoords;
psimpl::simplify_nth_point<2>(begin, end, n, std::back_inserter(resultCoords));
return val(typed_memory_view(resultCoords.size(), &resultCoords[0]));
}
val radial_distance(uintptr_t ptr, int length, double tol) {
double* begin = reinterpret_cast<double*>(ptr);
double* end = begin + length;
std::vector<double> resultCoords;
psimpl::simplify_radial_distance<2>(begin, end, tol, std::back_inserter(resultCoords));
return val(typed_memory_view(resultCoords.size(), &resultCoords[0]));
}
val perpendicular_distance(uintptr_t ptr, int length, unsigned repeat) {
double* begin = reinterpret_cast<double*>(ptr);
double* end = begin + length;
std::vector<double> resultCoords;
psimpl::simplify_perpendicular_distance<2>(begin, end, repeat, std::back_inserter(resultCoords));
return val(typed_memory_view(resultCoords.size(), &resultCoords[0]));
}
val reumann_witkam(uintptr_t ptr, int length, double tol) {
double* begin = reinterpret_cast<double*>(ptr);
double* end = begin + length;
std::vector<double> resultCoords;
psimpl::simplify_reumann_witkam<2>(begin, end, tol, std::back_inserter(resultCoords));
return val(typed_memory_view(resultCoords.size(), &resultCoords[0]));
}
val opheim(uintptr_t ptr, int length, double minTol, double maxTol) {
double* begin = reinterpret_cast<double*>(ptr);
double* end = begin + length;
std::vector<double> resultCoords;
psimpl::simplify_opheim<2>(begin, end, minTol, maxTol, std::back_inserter(resultCoords));
return val(typed_memory_view(resultCoords.size(), &resultCoords[0]));
}
val lang(uintptr_t ptr, int length, double tol, unsigned look_ahead) {
double* begin = reinterpret_cast<double*>(ptr);
double* end = begin + length;
std::vector<double> resultCoords;
psimpl::simplify_lang<2>(begin, end, tol, look_ahead, std::back_inserter(resultCoords));
return val(typed_memory_view(resultCoords.size(), &resultCoords[0]));
}
val douglas_peucker(uintptr_t ptr, int length, double tol) {
double* begin = reinterpret_cast<double*>(ptr);
double* end = begin + length;
std::vector<double> resultCoords;
psimpl::simplify_douglas_peucker<2>(begin, end, tol, std::back_inserter(resultCoords));
return val(typed_memory_view(resultCoords.size(), &resultCoords[0]));
}
val douglas_peucker_n(uintptr_t ptr, int length, unsigned count) {
double* begin = reinterpret_cast<double*>(ptr);
double* end = begin + length;
std::vector<double> resultCoords;
psimpl::simplify_douglas_peucker_n<2>(begin, end, count, std::back_inserter(resultCoords));
return val(typed_memory_view(resultCoords.size(), &resultCoords[0]));
}
EMSCRIPTEN_BINDINGS(my_module) {
function("nth_point", &nth_point);
function("radial_distance", &radial_distance);
function("perpendicular_distance", &perpendicular_distance);
function("reumann_witkam", &reumann_witkam);
function("opheim", &opheim);
function("lang", &lang);
function("douglas_peucker", &douglas_peucker);
function("douglas_peucker_n", &douglas_peucker_n);
register_vector<double>("vector<double>");
}

75
lib/psimpl-js/psimpl.js Normal file
View File

@ -0,0 +1,75 @@
var Module = (function() {
var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined;
return (
function(Module) {
Module = Module || {};
var d;d||(d=typeof Module !== 'undefined' ? Module : {});var m={},q;for(q in d)d.hasOwnProperty(q)&&(m[q]=d[q]);d.arguments=[];d.thisProgram="./this.program";d.quit=function(a,b){throw b;};d.preRun=[];d.postRun=[];var r=!1,u=!1,aa=!1,ba=!1;r="object"===typeof window;u="function"===typeof importScripts;aa="object"===typeof process&&"function"===typeof require&&!r&&!u;ba=!r&&!aa&&!u;var v="";
if(aa){v=__dirname+"/";var ca,da;d.read=function(a,b){ca||(ca=require("fs"));da||(da=require("path"));a=da.normalize(a);a=ca.readFileSync(a);return b?a:a.toString()};d.readBinary=function(a){a=d.read(a,!0);a.buffer||(a=new Uint8Array(a));a.buffer||w("Assertion failed: undefined");return a};1<process.argv.length&&(d.thisProgram=process.argv[1].replace(/\\/g,"/"));d.arguments=process.argv.slice(2);process.on("uncaughtException",function(a){if(!(a instanceof x))throw a;});process.on("unhandledRejection",
w);d.quit=function(a){process.exit(a)};d.inspect=function(){return"[Emscripten Module object]"}}else if(ba)"undefined"!=typeof read&&(d.read=function(a){return read(a)}),d.readBinary=function(a){if("function"===typeof readbuffer)return new Uint8Array(readbuffer(a));a=read(a,"binary");"object"===typeof a||w("Assertion failed: undefined");return a},"undefined"!=typeof scriptArgs?d.arguments=scriptArgs:"undefined"!=typeof arguments&&(d.arguments=arguments),"function"===typeof quit&&(d.quit=function(a){quit(a)});
else if(r||u)u?v=self.location.href:document.currentScript&&(v=document.currentScript.src),_scriptDir&&(v=_scriptDir),0!==v.indexOf("blob:")?v=v.substr(0,v.lastIndexOf("/")+1):v="",d.read=function(a){var b=new XMLHttpRequest;b.open("GET",a,!1);b.send(null);return b.responseText},u&&(d.readBinary=function(a){var b=new XMLHttpRequest;b.open("GET",a,!1);b.responseType="arraybuffer";b.send(null);return new Uint8Array(b.response)}),d.readAsync=function(a,b,c){var e=new XMLHttpRequest;e.open("GET",a,!0);
e.responseType="arraybuffer";e.onload=function(){200==e.status||0==e.status&&e.response?b(e.response):c()};e.onerror=c;e.send(null)},d.setWindowTitle=function(a){document.title=a};var ea=d.print||("undefined"!==typeof console?console.log.bind(console):"undefined"!==typeof print?print:null),y=d.printErr||("undefined"!==typeof printErr?printErr:"undefined"!==typeof console&&console.warn.bind(console)||ea);for(q in m)m.hasOwnProperty(q)&&(d[q]=m[q]);m=void 0;
var fa={"f64-rem":function(a,b){return a%b},"debugger":function(){debugger}};"object"!==typeof WebAssembly&&y("no native wasm support detected");var z,ha=!1,ia="undefined"!==typeof TextDecoder?new TextDecoder("utf8"):void 0;
function ja(a,b,c){var e=b+c;for(c=b;a[c]&&!(c>=e);)++c;if(16<c-b&&a.subarray&&ia)return ia.decode(a.subarray(b,c));for(e="";b<c;){var f=a[b++];if(f&128){var g=a[b++]&63;if(192==(f&224))e+=String.fromCharCode((f&31)<<6|g);else{var h=a[b++]&63;f=224==(f&240)?(f&15)<<12|g<<6|h:(f&7)<<18|g<<12|h<<6|a[b++]&63;65536>f?e+=String.fromCharCode(f):(f-=65536,e+=String.fromCharCode(55296|f>>10,56320|f&1023))}}else e+=String.fromCharCode(f)}return e}
function ka(a,b,c){var e=A;if(0<c){c=b+c-1;for(var f=0;f<a.length;++f){var g=a.charCodeAt(f);if(55296<=g&&57343>=g){var h=a.charCodeAt(++f);g=65536+((g&1023)<<10)|h&1023}if(127>=g){if(b>=c)break;e[b++]=g}else{if(2047>=g){if(b+1>=c)break;e[b++]=192|g>>6}else{if(65535>=g){if(b+2>=c)break;e[b++]=224|g>>12}else{if(b+3>=c)break;e[b++]=240|g>>18;e[b++]=128|g>>12&63}e[b++]=128|g>>6&63}e[b++]=128|g&63}}e[b]=0}}"undefined"!==typeof TextDecoder&&new TextDecoder("utf-16le");
function la(a){0<a%65536&&(a+=65536-a%65536);return a}var buffer,B,A,ma,na,C,D,oa,pa;function qa(){d.HEAP8=B=new Int8Array(buffer);d.HEAP16=ma=new Int16Array(buffer);d.HEAP32=C=new Int32Array(buffer);d.HEAPU8=A=new Uint8Array(buffer);d.HEAPU16=na=new Uint16Array(buffer);d.HEAPU32=D=new Uint32Array(buffer);d.HEAPF32=oa=new Float32Array(buffer);d.HEAPF64=pa=new Float64Array(buffer)}var ra=d.TOTAL_MEMORY||16777216;5242880>ra&&y("TOTAL_MEMORY should be larger than TOTAL_STACK, was "+ra+"! (TOTAL_STACK=5242880)");
d.buffer?buffer=d.buffer:"object"===typeof WebAssembly&&"function"===typeof WebAssembly.Memory?(z=new WebAssembly.Memory({initial:ra/65536}),buffer=z.buffer):buffer=new ArrayBuffer(ra);qa();C[1812]=5250160;function sa(a){for(;0<a.length;){var b=a.shift();if("function"==typeof b)b();else{var c=b.Ea;"number"===typeof c?void 0===b.ua?d.dynCall_v(c):d.dynCall_vi(c,b.ua):c(void 0===b.ua?null:b.ua)}}}var ta=[],ua=[],va=[],wa=[],xa=!1;function ya(){var a=d.preRun.shift();ta.unshift(a)}
var E=0,za=null,G=null;d.preloadedImages={};d.preloadedAudios={};function Aa(){var a=H;return String.prototype.startsWith?a.startsWith("data:application/octet-stream;base64,"):0===a.indexOf("data:application/octet-stream;base64,")}var H="psimpl.wasm";if(!Aa()){var Ba=H;H=d.locateFile?d.locateFile(Ba,v):v+Ba}function Ca(){try{if(d.wasmBinary)return new Uint8Array(d.wasmBinary);if(d.readBinary)return d.readBinary(H);throw"both async and sync fetching of the wasm failed";}catch(a){w(a)}}
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}
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<a.length;++e)Q(a[e],b[e])}a.forEach(function(a){Ma[a]=b});var f=Array(b.length),g=[],h=0;b.forEach(function(a,b){M.hasOwnProperty(a)?f[b]=M[a]:(g.push(a),L.hasOwnProperty(a)||(L[a]=[]),L[a].push(function(){f[b]=M[a];++h;h===g.length&&e(f)}))});0===g.length&&e(f)}
function Q(a,b,c){c=c||{};if(!("argPackAdvance"in b))throw new TypeError("registerType registeredInstance requires argPackAdvance");var e=b.name;a||O('type "'+e+'" must have a positive integer typeid pointer');if(M.hasOwnProperty(a)){if(c.Ia)return;O("Cannot register type '"+e+"' twice")}M[a]=b;delete Ma[a];L.hasOwnProperty(a)&&(b=L[a],delete L[a],b.forEach(function(a){a()}))}function Sa(a){return{count:a.count,na:a.na,pa:a.pa,ea:a.ea,fa:a.fa,ha:a.ha,ia:a.ia}}
function Ta(a){O(a.ba.fa.da.name+" instance already deleted")}var R=void 0,S=[];function Ua(){for(;S.length;){var a=S.pop();a.ba.na=!1;a["delete"]()}}function T(){}var Va={};function Wa(a,b,c){if(void 0===a[b].ga){var e=a[b];a[b]=function(){a[b].ga.hasOwnProperty(arguments.length)||O("Function '"+c+"' called with an invalid number of arguments ("+arguments.length+") - expects one of ("+a[b].ga+")!");return a[b].ga[arguments.length].apply(this,arguments)};a[b].ga=[];a[b].ga[e.ra]=e}}
function Xa(a,b,c){d.hasOwnProperty(a)?((void 0===c||void 0!==d[a].ga&&void 0!==d[a].ga[c])&&O("Cannot register public name '"+a+"' twice"),Wa(d,a,a),d.hasOwnProperty(c)&&O("Cannot register multiple overloads of a function with the same number of arguments ("+c+")!"),d[a].ga[c]=b):(d[a]=b,void 0!==c&&(d[a].Pa=c))}function Ya(a,b,c,e,f,g,h,l){this.name=a;this.constructor=b;this.oa=c;this.ma=e;this.ja=f;this.Fa=g;this.qa=h;this.Da=l;this.Ka=[]}
function Za(a,b,c){for(;b!==c;)b.qa||O("Expected null or instance of "+c.name+", got an instance of "+b.name),a=b.qa(a),b=b.ja;return a}function $a(a,b){if(null===b)return this.va&&O("null is not a valid "+this.name),0;b.ba||O('Cannot pass "'+U(b)+'" as a '+this.name);b.ba.ea||O("Cannot pass deleted object as a pointer of type "+this.name);return Za(b.ba.ea,b.ba.fa.da,this.da)}
function ab(a,b){if(null===b){this.va&&O("null is not a valid "+this.name);if(this.ta){var c=this.La();null!==a&&a.push(this.ma,c);return c}return 0}b.ba||O('Cannot pass "'+U(b)+'" as a '+this.name);b.ba.ea||O("Cannot pass deleted object as a pointer of type "+this.name);!this.sa&&b.ba.fa.sa&&O("Cannot convert argument of type "+(b.ba.ia?b.ba.ia.name:b.ba.fa.name)+" to parameter type "+this.name);c=Za(b.ba.ea,b.ba.fa.da,this.da);if(this.ta)switch(void 0===b.ba.ha&&O("Passing raw pointer to smart pointer is illegal"),
this.Na){case 0:b.ba.ia===this?c=b.ba.ha:O("Cannot convert argument of type "+(b.ba.ia?b.ba.ia.name:b.ba.fa.name)+" to parameter type "+this.name);break;case 1:c=b.ba.ha;break;case 2:if(b.ba.ia===this)c=b.ba.ha;else{var e=b.clone();c=this.Ma(c,bb(function(){e["delete"]()}));null!==a&&a.push(this.ma,c)}break;default:O("Unsupporting sharing policy")}return c}
function cb(a,b){if(null===b)return this.va&&O("null is not a valid "+this.name),0;b.ba||O('Cannot pass "'+U(b)+'" as a '+this.name);b.ba.ea||O("Cannot pass deleted object as a pointer of type "+this.name);b.ba.fa.sa&&O("Cannot convert argument of type "+b.ba.fa.name+" to parameter type "+this.name);return Za(b.ba.ea,b.ba.fa.da,this.da)}function db(a){return this.fromWireType(D[a>>2])}function eb(a,b,c){if(b===c)return a;if(void 0===c.ja)return null;a=eb(a,b,c.ja);return null===a?null:c.Da(a)}
var V={};function fb(a,b){for(void 0===b&&O("ptr should not be undefined");a.ja;)b=a.qa(b),a=a.ja;return V[b]}function gb(a,b){b.fa&&b.ea||Ra("makeClassHandle requires ptr and ptrType");!!b.ia!==!!b.ha&&Ra("Both smartPtrType and smartPtr must be specified");b.count={value:1};return Object.create(a,{ba:{value:b}})}
function W(a,b,c,e){this.name=a;this.da=b;this.va=c;this.sa=e;this.ta=!1;this.ma=this.Ma=this.La=this.Ba=this.Na=this.Ja=void 0;void 0!==b.ja?this.toWireType=ab:(this.toWireType=e?$a:cb,this.ka=null)}function hb(a,b,c){d.hasOwnProperty(a)||Ra("Replacing nonexistant public symbol");void 0!==d[a].ga&&void 0!==c?d[a].ga[c]=b:(d[a]=b,d[a].ra=c)}
function X(a,b){a=K(a);if(void 0!==d["FUNCTION_TABLE_"+a])var c=d["FUNCTION_TABLE_"+a][b];else if("undefined"!==typeof FUNCTION_TABLE)c=FUNCTION_TABLE[b];else{c=d["dynCall_"+a];void 0===c&&(c=d["dynCall_"+a.replace(/f/g,"d")],void 0===c&&O("No dynCall invoker for signature: "+a));for(var e=[],f=1;f<a.length;++f)e.push("a"+f);f="return function "+("dynCall_"+a+"_"+b)+"("+e.join(", ")+") {\n";f+=" return dynCall(rawFunction"+(e.length?", ":"")+e.join(", ")+");\n";c=(new Function("dynCall","rawFunction",
f+"};\n"))(c,b)}"function"!==typeof c&&O("unknown function pointer with signature "+a+": "+b);return c}var ib=void 0;function jb(a){a=kb(a);var b=K(a);Y(a);return b}function lb(a,b){function c(a){f[a]||M[a]||(Ma[a]?Ma[a].forEach(c):(e.push(a),f[a]=!0))}var e=[],f={};b.forEach(c);throw new ib(a+": "+e.map(jb).join([", "]));}function mb(a,b){for(var c=[],e=0;e<a;e++)c.push(C[(b>>2)+e]);return c}function nb(a){for(;a.length;){var b=a.pop();a.pop()(b)}}
function ob(a){var b=Function;if(!(b instanceof Function))throw new TypeError("new_ called with constructor type "+typeof b+" which is not a function");var c=Oa(b.name||"unknownFunctionName",function(){});c.prototype=b.prototype;c=new c;a=b.apply(c,a);return a instanceof Object?a:c}
function pb(a,b,c,e,f){var g=b.length;2>g&&O("argTypes array size mismatch! Must at least get return value and 'this' types!");var h=null!==b[1]&&null!==c,l=!1;for(c=1;c<b.length;++c)if(null!==b[c]&&void 0===b[c].ka){l=!0;break}var p="void"!==b[0].name,k="",n="";for(c=0;c<g-2;++c)k+=(0!==c?", ":"")+"arg"+c,n+=(0!==c?", ":"")+"arg"+c+"Wired";a="return function "+Na(a)+"("+k+") {\nif (arguments.length !== "+(g-2)+") {\nthrowBindingError('function "+a+" called with ' + arguments.length + ' arguments, expected "+
(g-2)+" args!');\n}\n";l&&(a+="var destructors = [];\n");var t=l?"destructors":"null";k="throwBindingError invoker fn runDestructors retType classParam".split(" ");e=[O,e,f,nb,b[0],b[1]];h&&(a+="var thisWired = classParam.toWireType("+t+", this);\n");for(c=0;c<g-2;++c)a+="var arg"+c+"Wired = argType"+c+".toWireType("+t+", arg"+c+"); // "+b[c+2].name+"\n",k.push("argType"+c),e.push(b[c+2]);h&&(n="thisWired"+(0<n.length?", ":"")+n);a+=(p?"var rv = ":"")+"invoker(fn"+(0<n.length?", ":"")+n+");\n";if(l)a+=
"runDestructors(destructors);\n";else for(c=h?1:2;c<b.length;++c)g=1===c?"thisWired":"arg"+(c-2)+"Wired",null!==b[c].ka&&(a+=g+"_dtor("+g+"); // "+b[c].name+"\n",k.push(g+"_dtor"),e.push(b[c].ka));p&&(a+="var ret = retType.fromWireType(rv);\nreturn ret;\n");k.push(a+"}\n");return ob(k).apply(null,e)}var qb=[],Z=[{},{value:void 0},{value:null},{value:!0},{value:!1}];function rb(a){4<a&&0===--Z[a].wa&&(Z[a]=void 0,qb.push(a))}
function bb(a){switch(a){case void 0:return 1;case null:return 2;case !0:return 3;case !1:return 4;default:var b=qb.length?qb.pop():Z.length;Z[b]={wa:1,value:a};return b}}function U(a){if(null===a)return"null";var b=typeof a;return"object"===b||"array"===b||"function"===b?a.toString():""+a}function sb(a,b){switch(b){case 2:return function(a){return this.fromWireType(oa[a>>2])};case 3:return function(a){return this.fromWireType(pa[a>>3])};default:throw new TypeError("Unknown float type: "+a);}}
function tb(a,b,c){switch(b){case 0:return c?function(a){return B[a]}:function(a){return A[a]};case 1:return c?function(a){return ma[a>>1]}:function(a){return na[a>>1]};case 2:return c?function(a){return C[a>>2]}:function(a){return D[a>>2]};default:throw new TypeError("Unknown integer type: "+a);}}function ub(){return B.length}function vb(a){a=la(a);var b=buffer.byteLength;try{return-1!==z.grow((a-b)/65536)?(buffer=z.buffer,!0):!1}catch(c){return!1}}for(var wb=Array(256),xb=0;256>xb;++xb)wb[xb]=String.fromCharCode(xb);
La=wb;N=d.BindingError=Pa("BindingError");Qa=d.InternalError=Pa("InternalError");T.prototype.isAliasOf=function(a){if(!(this instanceof T&&a instanceof T))return!1;var b=this.ba.fa.da,c=this.ba.ea,e=a.ba.fa.da;for(a=a.ba.ea;b.ja;)c=b.qa(c),b=b.ja;for(;e.ja;)a=e.qa(a),e=e.ja;return b===e&&c===a};T.prototype.clone=function(){this.ba.ea||Ta(this);if(this.ba.pa)return this.ba.count.value+=1,this;var a=Object.create(Object.getPrototypeOf(this),{ba:{value:Sa(this.ba)}});a.ba.count.value+=1;a.ba.na=!1;return a};
T.prototype["delete"]=function(){this.ba.ea||Ta(this);this.ba.na&&!this.ba.pa&&O("Object already scheduled for deletion");--this.ba.count.value;if(0===this.ba.count.value){var a=this.ba;a.ha?a.ia.ma(a.ha):a.fa.da.ma(a.ea)}this.ba.pa||(this.ba.ha=void 0,this.ba.ea=void 0)};T.prototype.isDeleted=function(){return!this.ba.ea};T.prototype.deleteLater=function(){this.ba.ea||Ta(this);this.ba.na&&!this.ba.pa&&O("Object already scheduled for deletion");S.push(this);1===S.length&&R&&R(Ua);this.ba.na=!0;return this};
W.prototype.Ga=function(a){this.Ba&&(a=this.Ba(a));return a};W.prototype.za=function(a){this.ma&&this.ma(a)};W.prototype.argPackAdvance=8;W.prototype.readValueFromPointer=db;W.prototype.deleteObject=function(a){if(null!==a)a["delete"]()};
W.prototype.fromWireType=function(a){function b(){return this.ta?gb(this.da.oa,{fa:this.Ja,ea:c,ia:this,ha:a}):gb(this.da.oa,{fa:this,ea:a})}var c=this.Ga(a);if(!c)return this.za(a),null;var e=fb(this.da,c);if(void 0!==e){if(0===e.ba.count.value)return e.ba.ea=c,e.ba.ha=a,e.clone();e=e.clone();this.za(a);return e}e=this.da.Fa(c);e=Va[e];if(!e)return b.call(this);e=this.sa?e.Ca:e.pointerType;var f=eb(c,this.da,e.da);return null===f?b.call(this):this.ta?gb(e.da.oa,{fa:e,ea:f,ia:this,ha:a}):gb(e.da.oa,
{fa:e,ea:f})};d.getInheritedInstanceCount=function(){return Object.keys(V).length};d.getLiveInheritedInstances=function(){var a=[],b;for(b in V)V.hasOwnProperty(b)&&a.push(V[b]);return a};d.flushPendingDeletes=Ua;d.setDelayFunction=function(a){R=a;S.length&&R&&R(Ua)};ib=d.UnboundTypeError=Pa("UnboundTypeError");d.count_emval_handles=function(){for(var a=0,b=5;b<Z.length;++b)void 0!==Z[b]&&++a;return a};d.get_first_emval=function(){for(var a=5;a<Z.length;++a)if(void 0!==Z[a])return Z[a];return null};
var zb=d.asm({},{b:w,v:function(){},h:function(a){return yb(a)},f:function(a){"uncaught_exception"in Ha?Ha.ya++:Ha.ya=1;throw a;},n:function(a){d.___errno_location&&(C[d.___errno_location()>>2]=a);return a},u:function(a,b){I=b;try{return Ja.Ha(),J(),J(),J(),J(),0}catch(c){return"undefined"!==typeof FS&&c instanceof FS.xa||w(c),-c.Aa}},m:function(a,b){I=b;try{var c=J(),e=J(),f=J();for(b=a=0;b<f;b++){for(var g=C[e+8*b>>2],h=C[e+(8*b+4)>>2],l=0;l<h;l++){var p=A[g+l],k=Ia[c];0===p||10===p?((1===c?ea:
y)(ja(k,0)),k.length=0):k.push(p)}a+=h}return a}catch(n){return"undefined"!==typeof FS&&n instanceof FS.xa||w(n),-n.Aa}},t:function(a,b){I=b;try{return Ja.Ha(),0}catch(c){return"undefined"!==typeof FS&&c instanceof FS.xa||w(c),-c.Aa}},s:function(a,b,c,e,f){var g=Ka(c);b=K(b);Q(a,{name:b,fromWireType:function(a){return!!a},toWireType:function(a,b){return b?e:f},argPackAdvance:8,readValueFromPointer:function(a){if(1===c)var e=B;else if(2===c)e=ma;else if(4===c)e=C;else throw new TypeError("Unknown boolean type size: "+
b);return this.fromWireType(e[a>>g])},ka:null})},r:function(a,b,c,e,f,g,h,l,p,k,n,t,Da){n=K(n);g=X(f,g);l&&(l=X(h,l));k&&(k=X(p,k));Da=X(t,Da);var F=Na(n);Xa(F,function(){lb("Cannot construct "+n+" due to unbound types",[e])});P([a,b,c],e?[e]:[],function(b){b=b[0];if(e){var c=b.da;var f=c.oa}else f=T.prototype;b=Oa(F,function(){if(Object.getPrototypeOf(this)!==h)throw new N("Use 'new' to construct "+n);if(void 0===p.la)throw new N(n+" has no accessible constructor");var a=p.la[arguments.length];if(void 0===
a)throw new N("Tried to invoke ctor of "+n+" with invalid number of parameters ("+arguments.length+") - expected ("+Object.keys(p.la).toString()+") parameters instead!");return a.apply(this,arguments)});var h=Object.create(f,{constructor:{value:b}});b.prototype=h;var p=new Ya(n,b,h,Da,c,g,l,k);c=new W(n,p,!0,!1);f=new W(n+"*",p,!1,!1);var t=new W(n+" const*",p,!1,!0);Va[a]={pointerType:f,Ca:t};hb(F,b);return[c,f,t]})},q:function(a,b,c,e,f,g){var h=mb(b,c);f=X(e,f);P([],[a],function(a){a=a[0];var c=
"constructor "+a.name;void 0===a.da.la&&(a.da.la=[]);if(void 0!==a.da.la[b-1])throw new N("Cannot register multiple constructors with identical number of parameters ("+(b-1)+") for class '"+a.name+"'! Overload resolution is currently only performed using the parameter count, not actual type info!");a.da.la[b-1]=function(){lb("Cannot construct "+a.name+" due to unbound types",h)};P([],h,function(e){a.da.la[b-1]=function(){arguments.length!==b-1&&O(c+" called with "+arguments.length+" arguments, expected "+
(b-1));var a=[],k=Array(b);k[0]=g;for(var h=1;h<b;++h)k[h]=e[h].toWireType(a,arguments[h-1]);k=f.apply(null,k);nb(a);return e[0].fromWireType(k)};return[]});return[]})},k:function(a,b,c,e,f,g,h,l){var p=mb(c,e);b=K(b);g=X(f,g);P([],[a],function(a){function e(){lb("Cannot call "+f+" due to unbound types",p)}a=a[0];var f=a.name+"."+b;l&&a.da.Ka.push(b);var k=a.da.oa,F=k[b];void 0===F||void 0===F.ga&&F.className!==a.name&&F.ra===c-2?(e.ra=c-2,e.className=a.name,k[b]=e):(Wa(k,b,f),k[b].ga[c-2]=e);P([],
p,function(e){e=pb(f,e,a,g,h);void 0===k[b].ga?(e.ra=c-2,k[b]=e):k[b].ga[c-2]=e;return[]});return[]})},C:function(a,b){b=K(b);Q(a,{name:b,fromWireType:function(a){var b=Z[a].value;rb(a);return b},toWireType:function(a,b){return bb(b)},argPackAdvance:8,readValueFromPointer:db,ka:null})},p:function(a,b,c){c=Ka(c);b=K(b);Q(a,{name:b,fromWireType:function(a){return a},toWireType:function(a,b){if("number"!==typeof b&&"boolean"!==typeof b)throw new TypeError('Cannot convert "'+U(b)+'" to '+this.name);return b},
argPackAdvance:8,readValueFromPointer:sb(b,c),ka:null})},g:function(a,b,c,e,f,g){var h=mb(b,c);a=K(a);f=X(e,f);Xa(a,function(){lb("Cannot call "+a+" due to unbound types",h)},b-1);P([],h,function(c){c=[c[0],null].concat(c.slice(1));hb(a,pb(a,c,null,f,g),b-1);return[]})},e:function(a,b,c,e,f){function g(a){return a}b=K(b);-1===f&&(f=4294967295);var h=Ka(c);if(0===e){var l=32-8*c;g=function(a){return a<<l>>>l}}var p=-1!=b.indexOf("unsigned");Q(a,{name:b,fromWireType:g,toWireType:function(a,c){if("number"!==
typeof c&&"boolean"!==typeof c)throw new TypeError('Cannot convert "'+U(c)+'" to '+this.name);if(c<e||c>f)throw new TypeError('Passing a number "'+U(c)+'" from JS side to C/C++ side to an argument of type "'+b+'", which is outside the valid range ['+e+", "+f+"]!");return p?c>>>0:c|0},argPackAdvance:8,readValueFromPointer:tb(b,h,0!==e),ka:null})},c:function(a,b,c){function e(a){a>>=2;var b=D;return new f(b.buffer,b[a+1],b[a])}var f=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,
Float32Array,Float64Array][b];c=K(c);Q(a,{name:c,fromWireType:e,argPackAdvance:8,readValueFromPointer:e},{Ia:!0})},o:function(a,b){b=K(b);var c="std::string"===b;Q(a,{name:b,fromWireType:function(a){var b=D[a>>2];if(c){var e=A[a+4+b],h=0;0!=e&&(h=e,A[a+4+b]=0);var l=a+4;for(e=0;e<=b;++e){var p=a+4+e;if(0==A[p]){l=l?ja(A,l,void 0):"";if(void 0===k)var k=l;else k+=String.fromCharCode(0),k+=l;l=p+1}}0!=h&&(A[a+4+b]=h)}else{k=Array(b);for(e=0;e<b;++e)k[e]=String.fromCharCode(A[a+4+e]);k=k.join("")}Y(a);
return k},toWireType:function(a,b){b instanceof ArrayBuffer&&(b=new Uint8Array(b));var e="string"===typeof b;e||b instanceof Uint8Array||b instanceof Uint8ClampedArray||b instanceof Int8Array||O("Cannot pass non-string to std::string");var f=(c&&e?function(){for(var a=0,c=0;c<b.length;++c){var e=b.charCodeAt(c);55296<=e&&57343>=e&&(e=65536+((e&1023)<<10)|b.charCodeAt(++c)&1023);127>=e?++a:a=2047>=e?a+2:65535>=e?a+3:a+4}return a}:function(){return b.length})(),l=yb(4+f+1);D[l>>2]=f;if(c&&e)ka(b,l+
4,f+1);else if(e)for(e=0;e<f;++e){var p=b.charCodeAt(e);255<p&&(Y(l),O("String has UTF-16 code units that do not fit in 8 bits"));A[l+4+e]=p}else for(e=0;e<f;++e)A[l+4+e]=b[e];null!==a&&a.push(Y,l);return l},argPackAdvance:8,readValueFromPointer:db,ka:function(a){Y(a)}})},B:function(a,b,c){c=K(c);if(2===b){var e=function(){return na};var f=1}else 4===b&&(e=function(){return D},f=2);Q(a,{name:c,fromWireType:function(a){for(var b=e(),c=D[a>>2],g=Array(c),k=a+4>>f,n=0;n<c;++n)g[n]=String.fromCharCode(b[k+
n]);Y(a);return g.join("")},toWireType:function(a,c){var g=e(),h=c.length,k=yb(4+h*b);D[k>>2]=h;for(var n=k+4>>f,t=0;t<h;++t)g[n+t]=c.charCodeAt(t);null!==a&&a.push(Y,k);return k},argPackAdvance:8,readValueFromPointer:db,ka:function(a){Y(a)}})},A:function(a,b){b=K(b);Q(a,{Oa:!0,name:b,argPackAdvance:0,fromWireType:function(){},toWireType:function(){}})},j:rb,i:function(a){4<a&&(Z[a].wa+=1)},d:function(a,b){var c=M[a];void 0===c&&O("_emval_take_value has unknown type "+jb(a));a=c.readValueFromPointer(b);
return bb(a)},l:function(){d.abort()},z:ub,y:function(a,b,c){A.set(A.subarray(b,b+c),a)},x:function(a){if(2147418112<a)return!1;for(var b=Math.max(ub(),16777216);b<a;)536870912>=b?b=la(2*b):b=Math.min(la((3*b+2147483648)/4),2147418112);if(!vb(b))return!1;qa();return!0},w:function(){w("OOM")},a:7248},buffer);d.asm=zb;d.___errno_location=function(){return d.asm.D.apply(null,arguments)};
var kb=d.___getTypeName=function(){return d.asm.E.apply(null,arguments)},Y=d._free=function(){return d.asm.F.apply(null,arguments)},yb=d._malloc=function(){return d.asm.G.apply(null,arguments)},Ga=d.globalCtors=function(){return d.asm.aa.apply(null,arguments)};d.dynCall_i=function(){return d.asm.H.apply(null,arguments)};d.dynCall_ii=function(){return d.asm.I.apply(null,arguments)};d.dynCall_iidiiii=function(){return d.asm.J.apply(null,arguments)};
d.dynCall_iii=function(){return d.asm.K.apply(null,arguments)};d.dynCall_iiii=function(){return d.asm.L.apply(null,arguments)};d.dynCall_iiiid=function(){return d.asm.M.apply(null,arguments)};d.dynCall_iiiidd=function(){return d.asm.N.apply(null,arguments)};d.dynCall_iiiidi=function(){return d.asm.O.apply(null,arguments)};d.dynCall_iiiii=function(){return d.asm.P.apply(null,arguments)};d.dynCall_jiji=function(){return d.asm.Q.apply(null,arguments)};
d.dynCall_v=function(){return d.asm.R.apply(null,arguments)};d.dynCall_vi=function(){return d.asm.S.apply(null,arguments)};d.dynCall_vii=function(){return d.asm.T.apply(null,arguments)};d.dynCall_viid=function(){return d.asm.U.apply(null,arguments)};d.dynCall_viii=function(){return d.asm.V.apply(null,arguments)};d.dynCall_viiid=function(){return d.asm.W.apply(null,arguments)};d.dynCall_viiidd=function(){return d.asm.X.apply(null,arguments)};d.dynCall_viiidi=function(){return d.asm.Y.apply(null,arguments)};
d.dynCall_viiii=function(){return d.asm.Z.apply(null,arguments)};d.dynCall_viiiii=function(){return d.asm._.apply(null,arguments)};d.dynCall_viiiiii=function(){return d.asm.$.apply(null,arguments)};d.asm=zb;d.then=function(a){if(d.calledRun)a(d);else{var b=d.onRuntimeInitialized;d.onRuntimeInitialized=function(){b&&b();a(d)}}return d};function x(a){this.name="ExitStatus";this.message="Program terminated with exit("+a+")";this.status=a}x.prototype=Error();x.prototype.constructor=x;
G=function Ab(){d.calledRun||Bb();d.calledRun||(G=Ab)};
function Bb(){function a(){if(!d.calledRun&&(d.calledRun=!0,!ha)){xa||(xa=!0,sa(ua));sa(va);if(d.onRuntimeInitialized)d.onRuntimeInitialized();if(d.postRun)for("function"==typeof d.postRun&&(d.postRun=[d.postRun]);d.postRun.length;){var a=d.postRun.shift();wa.unshift(a)}sa(wa)}}if(!(0<E)){if(d.preRun)for("function"==typeof d.preRun&&(d.preRun=[d.preRun]);d.preRun.length;)ya();sa(ta);0<E||d.calledRun||(d.setStatus?(d.setStatus("Running..."),setTimeout(function(){setTimeout(function(){d.setStatus("")},1);
a()},1)):a())}}d.run=Bb;function w(a){if(d.onAbort)d.onAbort(a);void 0!==a?(ea(a),y(a),a=JSON.stringify(a)):a="";ha=!0;throw"abort("+a+"). Build with -s ASSERTIONS=1 for more info.";}d.abort=w;if(d.preInit)for("function"==typeof d.preInit&&(d.preInit=[d.preInit]);0<d.preInit.length;)d.preInit.pop()();d.noExitRuntime=!0;Bb();
return Module
}
);
})();
export default Module;

BIN
lib/psimpl-js/psimpl.wasm Normal file

Binary file not shown.

View File

@ -1,6 +1,6 @@
OPTIMIZE="-O3"
simplify.wasm module.js: simplify.c
simplify.wasm simplify.js: simplify.c
emcc \
${OPTIMIZE} \
--closure 1 \