var ROS2D=function(e,t,i){"use strict";function s(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(i){if("default"!==i){var s=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,s.get?s:{enumerable:!0,get:function(){return e[i]}})}})),t.default=e,Object.freeze(t)}var n=s(t),r=s(i);n.Stage.prototype.globalToRos=function(e,t){var i=(e-this.x)/this.scaleX,s=(this.y-t)/this.scaleY;return new r.Vector3({x:i,y:s})},n.Stage.prototype.rosToGlobal=function(e){return{x:e.x*this.scaleX+this.x,y:e.y*this.scaleY+this.y}},n.Stage.prototype.rosQuaternionToGlobalTheta=function(e){var t=e.w,i=e.x,s=e.y,n=e.z;return 180*-Math.atan2(2*(t*n+i*s),1-2*(s*s+n*n))/Math.PI};class o extends n.Bitmap{constructor(e){var t=(e=e||{}).message;super(e.image),this.pose=new r.Pose({position:t.origin.position,orientation:t.origin.orientation}),this.width=t.width,this.height=t.height,this.y=-this.height*t.resolution,this.scaleX=t.resolution,this.scaleY=t.resolution,this.width*=this.scaleX,this.height*=this.scaleY,this.x+=this.pose.position.x,this.y-=this.pose.position.y}}function a(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var h,l={exports:{}}; /*! * EventEmitter2 * https://github.com/hij1nx/EventEmitter2 * * Copyright (c) 2013 hij1nx * Licensed under the MIT license. */var c,p=(h||(h=1,c=l,function(e){var t=Object.hasOwnProperty,i=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},s="object"==typeof process&&"function"==typeof process.nextTick,n="function"==typeof Symbol,r="object"==typeof Reflect,o="function"==typeof setImmediate?setImmediate:setTimeout,a=n?r&&"function"==typeof Reflect.ownKeys?Reflect.ownKeys:function(e){var t=Object.getOwnPropertyNames(e);return t.push.apply(t,Object.getOwnPropertySymbols(e)),t}:Object.keys;function h(){this._events={},this._conf&&l.call(this,this._conf)}function l(t){t&&(this._conf=t,t.delimiter&&(this.delimiter=t.delimiter),t.maxListeners!==e&&(this._maxListeners=t.maxListeners),t.wildcard&&(this.wildcard=t.wildcard),t.newListener&&(this._newListener=t.newListener),t.removeListener&&(this._removeListener=t.removeListener),t.verboseMemoryLeak&&(this.verboseMemoryLeak=t.verboseMemoryLeak),t.ignoreErrors&&(this.ignoreErrors=t.ignoreErrors),this.wildcard&&(this.listenerTree={}))}function p(e,t){var i="(node) warning: possible EventEmitter memory leak detected. "+e+" listeners added. Use emitter.setMaxListeners() to increase limit.";if(this.verboseMemoryLeak&&(i+=" Event name: "+t+"."),"undefined"!=typeof process&&process.emitWarning){var s=new Error(i);s.name="MaxListenersExceededWarning",s.emitter=this,s.count=e,process.emitWarning(s)}else console.error(i),console.trace&&console.trace()}var u=function(e,t,i){var s=arguments.length;switch(s){case 0:return[];case 1:return[e];case 2:return[e,t];case 3:return[e,t,i];default:for(var n=new Array(s);s--;)n[s]=arguments[s];return n}};function f(t,i){for(var s={},n=t.length,r=i?value.length:0,o=0;o0;)if(r===e[o])return s;n(t)}}Object.assign(d.prototype,{subscribe:function(e,t,i){var s=this,n=this._target,r=this._emitter,o=this._listeners,a=function(){var s=u.apply(null,arguments),o={data:s,name:t,original:e};if(i){var a=i.call(n,o);!1!==a&&r.emit.apply(r,[o.name].concat(s))}else r.emit.apply(r,[t].concat(s))};if(o[e])throw Error("Event '"+e+"' is already listening");this._listenersCount++,r._newListener&&r._removeListener&&!s._onNewListener?(this._onNewListener=function(i){i===t&&null===o[e]&&(o[e]=a,s._on.call(n,e,a))},r.on("newListener",this._onNewListener),this._onRemoveListener=function(i){i===t&&!r.hasListeners(i)&&o[e]&&(o[e]=null,s._off.call(n,e,a))},o[e]=null,r.on("removeListener",this._onRemoveListener)):(o[e]=a,s._on.call(n,e,a))},unsubscribe:function(e){var t,i,s,n=this,r=this._listeners,o=this._emitter,h=this._off,l=this._target;if(e&&"string"!=typeof e)throw TypeError("event must be a string");function c(){n._onNewListener&&(o.off("newListener",n._onNewListener),o.off("removeListener",n._onRemoveListener),n._onNewListener=null,n._onRemoveListener=null);var e=b.call(o,n);o._observers.splice(e,1)}if(e){if(!(t=r[e]))return;h.call(l,e,t),delete r[e],--this._listenersCount||c()}else{for(s=(i=a(r)).length;s-- >0;)e=i[s],h.call(l,e,r[e]);this._listeners={},this._listenersCount=0,c()}}});var m=y(["function"]),_=y(["object","function"]);function w(e,t,i){var s,n,r,o=0,a=new e((function(h,l,c){function p(){n&&(n=null),o&&(clearTimeout(o),o=0)}i=v(i,{timeout:0,overload:!1},{timeout:function(e,t){return("number"!=typeof(e*=1)||e<0||!Number.isFinite(e))&&t("timeout must be a positive number"),e}}),s=!i.overload&&"function"==typeof e.prototype.cancel&&"function"==typeof c;var u=function(e){p(),h(e)},f=function(e){p(),l(e)};s?t(u,f,c):(n=[function(e){f(e||Error("canceled"))}],t(u,f,(function(e){if(r)throw Error("Unable to subscribe on cancel event asynchronously");if("function"!=typeof e)throw TypeError("onCancel callback must be a function");n.push(e)})),r=!0),i.timeout>0&&(o=setTimeout((function(){var e=Error("timeout");e.code="ETIMEDOUT",o=0,a.cancel(e),l(e)}),i.timeout))}));return s||(a.cancel=function(e){if(n){for(var t=n.length,i=1;i0;)"_listeners"!==(f=m[h])&&(_=C(e,t,i[f],s+1,n))&&(w?w.push.apply(w,_):w=_);return w}if("**"===b){for((y=s+1===n||s+2===n&&"*"===S)&&i._listeners&&(w=C(e,t,i,n,n)),h=(m=a(i)).length;h-- >0;)"_listeners"!==(f=m[h])&&("*"===f||"**"===f?(i[f]._listeners&&!y&&(_=C(e,t,i[f],n,n))&&(w?w.push.apply(w,_):w=_),_=C(e,t,i[f],s,n)):_=C(e,t,i[f],f===S?s+2:s,n),_&&(w?w.push.apply(w,_):w=_));return w}i[b]&&(w=C(e,t,i[b],s+1,n))}if((d=i["*"])&&C(e,t,d,s+1,n),v=i["**"])if(s0;)"_listeners"!==(f=m[h])&&(f===S?C(e,t,v[f],s+2,n):f===b?C(e,t,v[f],s+1,n):((g={})[f]=v[f],C(e,t,{"**":g},s+1,n)));else v._listeners?C(e,t,v,n,n):v["*"]&&v["*"]._listeners&&C(e,t,v["*"],n,n);return w}function S(e,t,i){var s,n,r=0,o=0,a=this.delimiter,h=a.length;if("string"==typeof e)if(-1!==(s=e.indexOf(a))){n=new Array(5);do{n[r++]=e.slice(o,s),o=s+h}while(-1!==(s=e.indexOf(a,o)));n[r++]=e.slice(o)}else n=[e],r=1;else n=e,r=e.length;if(r>1)for(s=0;s+10&&c._listeners.length>this._maxListeners&&(c._listeners.warned=!0,p.call(this,c._listeners.length,l))):c._listeners=t,!0;return!0}function x(e,t,i,s){for(var n,r,o,h,l=a(e),c=l.length,p=e._listeners;c-- >0;)n=e[r=l[c]],o="_listeners"===r?i:i?i.concat(r):[r],h=s||"symbol"==typeof r,p&&t.push(h?o:o.join(this.delimiter)),"object"==typeof n&&x.call(this,n,t,o,h);return t}function L(e){for(var t,i,s,n=a(e),r=n.length;r-- >0;)(t=e[i=n[r]])&&(s=!0,"_listeners"===i||L(t)||delete e[i]);return s}function k(e,t,i){this.emitter=e,this.event=t,this.listener=i}function T(t,i,n){if(!0===n)a=!0;else if(!1===n)r=!0;else{if(!n||"object"!=typeof n)throw TypeError("options should be an object or true");var r=n.async,a=n.promisify,h=n.nextTick,l=n.objectify}if(r||h||a){var c=i,p=i._origin||i;if(h&&!s)throw Error("process.nextTick is not supported");a===e&&(a="AsyncFunction"===i.constructor.name),i=function(){var e=arguments,t=this,i=this.event;return a?h?Promise.resolve():new Promise((function(e){o(e)})).then((function(){return t.event=i,c.apply(t,e)})):(h?process.nextTick:o)((function(){t.event=i,c.apply(t,e)}))},i._async=!0,i._origin=p}return[i,l?new k(this,t,i):this]}function j(e){this._events={},this._newListener=!1,this._removeListener=!1,this.verboseMemoryLeak=!1,l.call(this,e)}k.prototype.off=function(){return this.emitter.off(this.event,this.listener),this},j.EventEmitter2=j,j.prototype.listenTo=function(t,s,n){if("object"!=typeof t)throw TypeError("target musts be an object");var r=this;function o(e){if("object"!=typeof e)throw TypeError("events must be an object");var i,s=n.reducers,o=b.call(r,t);i=-1===o?new d(r,t,n):r._observers[o];for(var h,l=a(e),c=l.length,p="function"==typeof s,u=0;u0;)s=i[n],e&&s._target!==e||(s.unsubscribe(t),r=!0);return r},j.prototype.delimiter=".",j.prototype.setMaxListeners=function(t){t!==e&&(this._maxListeners=t,this._conf||(this._conf={}),this._conf.maxListeners=t)},j.prototype.getMaxListeners=function(){return this._maxListeners},j.prototype.event="",j.prototype.once=function(e,t,i){return this._once(e,t,!1,i)},j.prototype.prependOnceListener=function(e,t,i){return this._once(e,t,!0,i)},j.prototype._once=function(e,t,i,s){return this._many(e,1,t,i,s)},j.prototype.many=function(e,t,i,s){return this._many(e,t,i,!1,s)},j.prototype.prependMany=function(e,t,i,s){return this._many(e,t,i,!0,s)},j.prototype._many=function(e,t,i,s,n){var r=this;if("function"!=typeof i)throw new Error("many only accepts instances of Function");function o(){return 0==--t&&r.off(e,o),i.apply(this,arguments)}return o._origin=i,this._on(e,o,s,n)},j.prototype.emit=function(){if(!this._events&&!this._all)return!1;this._events||h.call(this);var e,t,i,s,r,o,a=arguments[0],l=this.wildcard;if("newListener"===a&&!this._newListener&&!this._events.newListener)return!1;if(l&&(e=a,"newListener"!==a&&"removeListener"!==a&&"object"==typeof a)){if(i=a.length,n)for(s=0;s3)for(t=new Array(p-1),r=1;r3)for(i=new Array(u-1),o=1;o0&&this._events[t].length>this._maxListeners&&(this._events[t].warned=!0,p.call(this,this._events[t].length,t))):this._events[t]=i,o)},j.prototype.off=function(e,t){if("function"!=typeof t)throw new Error("removeListener only takes instances of Function");var s,n=[];if(this.wildcard){var r="string"==typeof e?e.split(this.delimiter):e.slice();if(!(n=C.call(this,null,r,this.listenerTree,0)))return this}else{if(!this._events[e])return this;s=this._events[e],n.push({_listeners:s})}for(var o=0;o0){for(i=0,s=(t=this._all).length;i0;)"function"==typeof(s=h[i[r]])?n.push(s):n.push.apply(n,s);return n}if(this.wildcard){if(!(o=this.listenerTree))return[];var l=[],c="string"==typeof t?t.split(this.delimiter):t.slice();return C.call(this,l,c,o,0),l}return h&&(s=h[t])?"function"==typeof s?[s]:s:[]},j.prototype.eventNames=function(e){var t=this._events;return this.wildcard?x.call(this,this.listenerTree,[],null,e):t?a(t):[]},j.prototype.listenerCount=function(e){return this.listeners(e).length},j.prototype.hasListeners=function(t){if(this.wildcard){var i=[],s="string"==typeof t?t.split(this.delimiter):t.slice();return C.call(this,i,s,this.listenerTree,0),i.length>0}var n=this._events,r=this._all;return!!(r&&r.length||n&&(t===e?a(n).length:n[t]))},j.prototype.listenersAny=function(){return this._all?this._all:[]},j.prototype.waitFor=function(t,i){var s=this,n=typeof i;return"number"===n?i={timeout:i}:"function"===n&&(i={filter:i}),w((i=v(i,{timeout:0,filter:e,handleError:!1,Promise:Promise,overload:!1},{filter:m,Promise:g})).Promise,(function(e,n,r){function o(){var r=i.filter;if(!r||r.apply(s,arguments))if(s.off(t,o),i.handleError){var a=arguments[0];a?n(a):e(u.apply(null,arguments).slice(1))}else e(u.apply(null,arguments))}r((function(){s.off(t,o)})),s._on(t,o,!1)}),{timeout:i.timeout,overload:i.overload})};var O=j.prototype;Object.defineProperties(j,{defaultMaxListeners:{get:function(){return O._maxListeners},set:function(e){if("number"!=typeof e||e<0||Number.isNaN(e))throw TypeError("n must be a non-negative number");O._maxListeners=e},enumerable:!0},once:{value:function(e,t,i){return w((i=v(i,{Promise:Promise,timeout:0,overload:!1},{Promise:g})).Promise,(function(i,s,n){var r;if("function"==typeof e.addEventListener)return r=function(){i(u.apply(null,arguments))},n((function(){e.removeEventListener(t,r)})),void e.addEventListener(t,r,{once:!0});var o,a=function(){o&&e.removeListener("error",o),i(u.apply(null,arguments))};"error"!==t&&(o=function(i){e.removeListener(t,a),s(i)},e.once("error",o)),n((function(){o&&e.removeListener("error",o),e.removeListener(t,a)})),e.once(t,a)}),{timeout:i.timeout,overload:i.overload})},writable:!0,configurable:!0}}),Object.defineProperties(O,{_maxListeners:{value:10,writable:!0,configurable:!0},_observers:{value:null,writable:!0,configurable:!0}}),c.exports=j}()),l.exports),u=a(p);class f extends n.Bitmap{constructor(e){var t=(e=e||{}).message,i=document.createElement("canvas"),s=i.getContext("2d");i.width=t.info.width,i.height=t.info.height;for(var n=s.createImageData(i.width,i.height),o=0;o2&&this.editLineShape(this.lineContainer.getChildAt(i-2),this.pointContainer.getChildAt(i-2),t),i>1){var n=this.createLineShape(t,this.pointContainer.getChildAt(0));this.lineContainer.addChild(n)}this.drawFill()}remPoint(e){var t;t=e instanceof n.Shape?this.pointContainer.getChildIndex(e):e;var i=this.pointContainer.numChildren;i<2||(i<3?this.lineContainer.removeAllChildren():(this.editLineShape(this.lineContainer.getChildAt((t-1+i)%i),this.pointContainer.getChildAt((t-1+i)%i),this.pointContainer.getChildAt((t+1)%i)),this.lineContainer.removeChildAt(t))),this.pointContainer.removeChildAt(t),this.drawFill()}movePoint(e,t){var i,s;e instanceof n.Shape?(i=this.pointContainer.getChildIndex(e),s=e):(i=e,s=this.pointContainer.getChildAt(i)),s.x=t.x,s.y=-t.y;var r=this.pointContainer.numChildren;if(r>1){var o=this.lineContainer.getChildAt((i-1+r)%r);this.editLineShape(o,this.pointContainer.getChildAt((i-1+r)%r),s);var a=this.lineContainer.getChildAt(i);this.editLineShape(a,s,this.pointContainer.getChildAt((i+1)%r))}this.drawFill()}splitLine(e){var t,i;e instanceof n.Shape?(t=this.lineContainer.getChildIndex(e),i=e):(t=e,i=this.lineContainer.getChildAt(t));var s=this.pointContainer.numChildren,o=this.pointContainer.getChildAt(t).x,a=this.pointContainer.getChildAt(t).y,h=(o+this.pointContainer.getChildAt((t+1)%s).x)/2,l=(a+this.pointContainer.getChildAt((t+1)%s).y)/2,c=new r.Vector3({x:h,y:-l}),p=this.createPointShape(c);this.pointContainer.addChildAt(p,t+1),++s;var u=this.createLineShape(p,this.pointContainer.getChildAt((t+2)%s));this.lineContainer.addChildAt(u,t+1),this.editLineShape(i,this.pointContainer.getChildAt(t),p),this.drawFill()}drawFill(){var e=this.pointContainer.numChildren;if(e>2){var t=this.fillShape.graphics;t.clear(),t.setStrokeStyle(0),t.beginStroke(),t.beginFill(this.fillColor),t.moveTo(this.pointContainer.getChildAt(0).x,this.pointContainer.getChildAt(0).y);for(var i=1;ithis.minDist&&(this.graphics.lineTo(e.position.x/this.scaleX,e.position.y/-this.scaleY),this.poses.push(e))}this.maxPoses>0&&this.maxPoses0){this.poses.shift(),this.graphics.clear(),this.graphics.setStrokeStyle(this.strokeSize),this.graphics.beginStroke(this.strokeColor),this.graphics.lineTo(this.poses[0].position.x/this.scaleX,this.poses[0].position.y/-this.scaleY);for(var e=1;e