You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
30 KiB
JavaScript

"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};function e(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n=function(){return(n=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var a in e=arguments[n])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t}).apply(this,arguments)};function r(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var r=Array(t),a=0;for(e=0;e<n;e++)for(var o=arguments[e],s=0,i=o.length;s<i;s++,a++)r[a]=o[s];return r}function a(t,e,n){if(t&&t.length){var r=e[0],a=e[1],o=Math.PI/180*n,s=Math.cos(o),i=Math.sin(o);t.forEach((function(t){var e=t[0],n=t[1];t[0]=(e-r)*s-(n-a)*i+r,t[1]=(e-r)*i+(n-a)*s+a}))}}function o(t){var e=t[0],n=t[1];return Math.sqrt(Math.pow(e[0]-n[0],2)+Math.pow(e[1]-n[1],2))}function s(t,e,n){var r=t.length;if(r<3)return!1;for(var a=[Number.MAX_SAFE_INTEGER,n],o=[e,n],s=0,p=0;p<r;p++){var l=t[p],c=t[(p+1)%r];if(u(l,c,o,a)){if(0===h(l,o,c))return i(l,o,c);s++}}return s%2==1}function i(t,e,n){return e[0]<=Math.max(t[0],n[0])&&e[0]>=Math.min(t[0],n[0])&&e[1]<=Math.max(t[1],n[1])&&e[1]>=Math.min(t[1],n[1])}function h(t,e,n){var r=(e[1]-t[1])*(n[0]-e[0])-(e[0]-t[0])*(n[1]-e[1]);return 0===r?0:r>0?1:2}function u(t,e,n,r){var a=h(t,e,n),o=h(t,e,r),s=h(n,r,t),u=h(n,r,e);return a!==o&&s!==u||(!(0!==a||!i(t,n,e))||(!(0!==o||!i(t,r,e))||(!(0!==s||!i(n,t,r))||!(0!==u||!i(n,e,r)))))}function p(t,e){var n=[0,0],o=Math.round(e.hachureAngle+90);o&&a(t,n,o);var s=function(t,e){var n=r(t);n[0].join(",")!==n[n.length-1].join(",")&&n.push([n[0][0],n[0][1]]);var a=[];if(n&&n.length>2){var o=e.hachureGap;o<0&&(o=4*e.strokeWidth),o=Math.max(o,.1);for(var s=[],i=0;i<n.length-1;i++){var h=n[i],u=n[i+1];if(h[1]!==u[1]){var p=Math.min(h[1],u[1]);s.push({ymin:p,ymax:Math.max(h[1],u[1]),x:p===h[1]?h[0]:u[0],islope:(u[0]-h[0])/(u[1]-h[1])})}}if(s.sort((function(t,e){return t.ymin<e.ymin?-1:t.ymin>e.ymin?1:t.x<e.x?-1:t.x>e.x?1:t.ymax===e.ymax?0:(t.ymax-e.ymax)/Math.abs(t.ymax-e.ymax)})),!s.length)return a;for(var l=[],c=s[0].ymin;l.length||s.length;){if(s.length){var f=-1;for(i=0;i<s.length&&!(s[i].ymin>c);i++)f=i;s.splice(0,f+1).forEach((function(t){l.push({s:c,edge:t})}))}if((l=l.filter((function(t){return!(t.edge.ymax<=c)}))).sort((function(t,e){return t.edge.x===e.edge.x?0:(t.edge.x-e.edge.x)/Math.abs(t.edge.x-e.edge.x)})),l.length>1)for(i=0;i<l.length;i+=2){var d=i+1;if(d>=l.length)break;var v=l[i].edge,g=l[d].edge;a.push([[Math.round(v.x),c],[Math.round(g.x),c]])}c+=o,l.forEach((function(t){t.edge.x=t.edge.x+o*t.edge.islope}))}}return a}(t,e);return o&&(a(t,n,-o),function(t,e,n){var r=[];t.forEach((function(t){return r.push.apply(r,t)})),a(r,e,n)}(s,n,-o)),s}var l=function(){function t(t){this.helper=t}return t.prototype.fillPolygon=function(t,e){return this._fillPolygon(t,e)},t.prototype._fillPolygon=function(t,e,n){void 0===n&&(n=!1);var r=p(t,e);if(n){var a=this.connectingLines(t,r);r=r.concat(a)}return{type:"fillSketch",ops:this.renderLines(r,e)}},t.prototype.renderLines=function(t,e){for(var n=[],r=0,a=t;r<a.length;r++){var o=a[r];n.push.apply(n,this.helper.doubleLineOps(o[0][0],o[0][1],o[1][0],o[1][1],e))}return n},t.prototype.connectingLines=function(t,e){var n=[];if(e.length>1)for(var r=1;r<e.length;r++){var a=e[r-1];if(!(o(a)<3)){var s=[e[r][0],a[1]];if(o(s)>3){var i=this.splitOnIntersections(t,s);n.push.apply(n,i)}}}return n},t.prototype.midPointInPolygon=function(t,e){return s(t,(e[0][0]+e[1][0])/2,(e[0][1]+e[1][1])/2)},t.prototype.splitOnIntersections=function(t,e){for(var n,a,i,h,p,l,c,f,d,v,g,y=Math.max(5,.1*o(e)),M=[],k=0;k<t.length;k++){var b=t[k],m=t[(k+1)%t.length];if(u.apply(void 0,r([b,m],e))){var w=(n=b,a=m,i=e[0],h=e[1],p=void 0,l=void 0,c=void 0,f=void 0,d=void 0,v=void 0,g=void 0,p=a[1]-n[1],l=n[0]-a[0],c=p*n[0]+l*n[1],f=h[1]-i[1],d=i[0]-h[0],v=f*i