UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 4.92 kB
var UNDEF,isWithinCircle=function(a,b,c,d,e){var f=Math.pow;return f(c-a,2)+f(d-b,2)<=f(e,2)},mathPI=Math.PI,mathCos=Math.cos,mathSin=Math.sin,mathMax=Math.max,mathMin=Math.min,deg2rad=mathPI/180,rad=function(a){return a%360*deg2rad},orientation=function(a,b,c,d,e,f){var g,h,i;return g=(d-b)*(e-c),h=(c-a)*(f-d),isNaN(g)&&(g=0),isNaN(h)&&(h=0),i=g-h,0===i?0:0<i?1:2},onSegment=function(a,b,c,d,e,f){return!!(c<=mathMax(a,e)&&c>=mathMin(a,e)&&d<=mathMax(b,f)&&d>=mathMin(b,f))},doIntersect=function(a,b,c,d,e,f,g,h){var i=orientation(a,b,c,d,e,f),j=orientation(a,b,c,d,g,h),k=orientation(e,f,g,h,a,b),l=orientation(e,f,g,h,c,d);return!(i===j||k===l)||!!(0===i&&onSegment(a,b,e,f,c,d))||!!(0===j&&onSegment(a,b,g,h,c,d))||!!(0===k&&onSegment(e,f,a,b,g,h))||!!(0===l&&onSegment(e,f,c,d,g,h))},isWithinPolygon=function(a,b,c,d,e,f,g){var h,j,k,l,m,n,o,p=0,q=!1;if(isWithinCircle(a,b,c,d,e)&&3<=f){for(j=g===UNDEF?.5*mathPI:rad(g),o=2*mathPI/f,k=c+e*mathCos(-j),n=d+e*mathSin(-j),h=0;h<f;h++){if(j+=o,l=c+e*mathCos(-j),m=d+e*mathSin(-j),doIntersect(k,n,l,m,a,b,1/0,b)){if(0===orientation(k,n,a,b,l,m))return onSegment(k,n,a,b,l,m);p++}k=l,n=m}q=0!=p%2}return q},_compair2closest=(a,b)=>!a||a&&b&&b.i>a.i?b:a;function kdTreeAbs(a){'use strict';function b(a,b,c){var d=a[b];a[b]=a[c],a[c]=d}function c(a,b,d,g){var h,i={},j=g?'y':'x';return b===d?(i.point=a[b],i):1==d-b?(a[b][j]>a[d][j]?(i.point=a[b],i.left={point:a[d]}):(i.point=a[d],i.left={point:a[b]}),i):(h=b+d>>1,g?f(a,h,b,d):e(a,h,b,d),i.point=a[h],i.left=c(a,b,h-1,!g),i.right=c(a,h+1,d,!g),i)}var d,e,f,g=a&&a[0]&&a[0].r||5,h=Math.max,l=Math.floor,o=Math.sqrt,p=Math.min,q=Math.log,r=Math.exp,j=Math.pow;for(e=function(a,c,d,f){for(var g,k,u,v,w,x,y,A,B,C;f>d;){for(600<f-d&&(g=f-d+1,k=c-d+1,u=q(g),v=.5*r(2*u/3),w=.5*o(u*v*(g-v)/g)*(0>k-g/2?-1:1),x=h(d,l(c-k*v/g+w)),y=p(f,l(c+(g-k)*v/g+w)),e(a,c,x,y)),A=a[c],B=d,C=f,b(a,d,c),a[f].x>A.x&&b(a,d,f);B<C;){for(b(a,B,C),B++,C--;a[B].x<A.x;)B++;for(;a[C].x>A.x;)C--}a[d].x===A.x?b(a,d,C):(C++,b(a,C,f)),C<=c&&(d=C+1),c<=C&&(f=C-1)}},f=function(a,c,d,e){for(var g,k,u,v,w,x,y,A,B,C;e>d;){for(600<e-d&&(g=e-d+1,k=c-d+1,u=q(g),v=.5*r(2*u/3),w=.5*o(u*v*(g-v)/g)*(0>k-g/2?-1:1),x=h(d,l(c-k*v/g+w)),y=p(e,l(c+(g-k)*v/g+w)),f(a,c,x,y)),A=a[c],B=d,C=e,b(a,d,c),a[e].y>A.y&&b(a,d,e);B<C;){for(b(a,B,C),B++,C--;a[B].y<A.y;)B++;for(;a[C].y>A.y;)C--}a[d].y===A.y?b(a,d,C):(C++,b(a,C,e)),C<=c&&(d=C+1),c<=C&&(e=C-1)}},a=a||[],d=a.length;d--;)a[d].r>g&&(g=a[d].r),a[d].i=d,a[d].x=+a[d].x,a[d].y=+a[d].y;return{tree:0===a.length?{}:c(a,0,a.length-1,!1),search:function(c,d,e,a){function f(a,b,c,d){return o(j(a-c,2)+j(b-d,2))}function b(g,a){return'circle'===e?f(g,a,c,d)<=q:g>=q&&g<=r&&a>=s&&a<=t}function h(b,a,c){return b>=a&&b<=c}function i(a){var b=h(c,a.x1,a.x2)&&h(d,a.y1,a.y2),e=f(c,d,a.point.x,a.point.y);return l?void(b?u?a.point.i>l.point.i&&(l=a,u=b,v=e):(l=a,u=b,v=e):!u&&e<v&&(l=a,u=b,v=e)):(l=a,u=b,void(v=e))}function k(a,b){'circle'===e?q=a:(q=c-a||0,r=c+a||0,s=d-b||0,t=d+b||0)}var l,m,n,p=this.tree,q=c-g,r=c+g,s=d-g,t=d+g,u=!1,v=0;return a=a||{},n=function(c){var d,e;c&&c.point&&(d=a.rx||c.point.r,e=a.ry||c.point.r,k(d,e),b(c.point.x,c.point.y)&&i(c),s<=c.point.y&&m(c.left),t>=c.point.y&&m(c.right))},m=function(c){var d,e;c&&c.point&&(d=a.rx||c.point.r,e=a.ry||c.point.r,k(d,e),b(c.point.x,c.point.y)&&i(c),q<=c.point.x&&n(c.left),r>=c.point.x&&n(c.right))},m(p),l&&l.point||l}}}class KdTree{constructor(a){var b=this;b.configure(a)}configure(a){var b=this;b.validatorFn=a?b.shapeValidator():b.defaultValidator()}defaultValidator(){var a=Math.pow,b=this;return function(c){var d=b.mousePoint;return!!(c&&1>=a((c.x-d.x)/b.xLimit,2)+a((c.y-d.y)/b.yLimit,2))}}shapeValidator(){var a=this;return function(b){var c,d,e,f,g,h,i,j,k,l=a.mousePoint,m=b&&b.shapeInfo,n=!1,o=l.x,p=l.y;return c=m&&m.type,'circle'===c?(e=m.radius,n=isWithinCircle(o,p,b.x,b.y,e)):'arc'===c?(d=m.innerradius,e=m.radius,n=!isWithinCircle(o,p,b.x,b.y,d)&&isWithinCircle(o,p,b.x,b.y,e)):'polygon'===c?(e=m.radius,g=m.startAngle,f=m.sides,n=isWithinPolygon(o,p,b.x,b.y,e,f,g)):'rect'===c||'rectangle'===c?(h=b.x,j=b.y,i=h+(m.width||0),k=j+(m.height||0),n=o>=h&&o<=i&&p>=j&&p<=k):'default'===c?n=!1:void 0,n}}buildKdTree(a){return this.kdTree=kdTreeAbs(a),this.tree=this.kdTree.tree,this}getNeighbour(a,b,c){var d=this,e=d.tree,f={x1:a.x-d.xLimit,x2:a.x+d.xLimit,y1:a.y-d.yLimit,y2:a.y+d.yLimit},g=d.validatorFn;return d.mousePoint=a,b?this.kdTree&&this.kdTree.search(a.x,a.y,c,a.options):e?d._searchBtwnLimit(f,e,!0,g):void 0}_searchBtwnLimit(a,b,c,d){var e,f,g=this,h=c?'x':'y',i=c?a.x1:a.y1,j=c?a.x2:a.y2;if(e=b&&b.point&&b.point[h],e!==UNDEF)return d(b.point)&&(f=b.point),e>=i&&b.left&&(f=_compair2closest(f,g._searchBtwnLimit(a,b.left,!c,d))),e<=j&&b.right&&(f=_compair2closest(f,g._searchBtwnLimit(a,b.right,!c,d))),f}_setSearchLimit(a,b){var c=this;c.xLimit=a,c.yLimit=b}}KdTree.prototype.constructor=KdTree;export default KdTree;