k?-1:1)*n+r,y=m*(w-r)+q);this.ak();this.Ae(g);this.qf(u,v);this.qf(w,y);this.Ae(p);this.jd(0,this.getLinkPoint(b,c,d,!0,!1,e,f));this.jd(3,this.getLinkPoint(e,f,a,!1,!1,b,c))}else d=this.getLinkPoint(b,c,d,!0,!1,e,f),a=this.getLinkPoint(e,
f,a,!1,!1,b,c),this.hasCurviness()?(p=a.x-d.x,e=a.y-d.y,f=this.computeCurviness(),b=d.x+p/2,c=d.y+e/2,g=b,h=c,K.A(e,0)?h=0f&&(g=-g),g=(0>e?-1:1)*g+b,h=p*(g-b)+c),this.Ae(d),this.qf(g,h)):this.Ae(d),this.Ae(a)}else{n=this.isAvoiding;p&&(m&&n||l)&&this.ak();var z=l?this.computeCurviness():0;n=this.getLinkPoint(b,c,d,!0,m,e,f);r=u=q=0;if(m||!h||l)v=this.computeEndSegmentLength(b,c,d,!0),r=this.getLinkDirection(b,c,n,d,!0,m,e,f),l&&(h||d.w(a)||!m&&1===d.x+
a.x&&1===d.y+a.y)&&(r-=m?90:30,0>z&&(r-=180)),0>r?r+=360:360<=r&&(r-=360),l&&(v+=Math.abs(z)*(m?1:2)),0===r?q=v:90===r?u=v:180===r?q=-v:270===r?u=-v:(q=v*Math.cos(r*Math.PI/180),u=v*Math.sin(r*Math.PI/180)),d.kc()&&l&&(v=c.ga(Ac,I.alloc()),w=I.allocAt(v.x+1E3*q,v.y+1E3*u),this.getLinkPointFromPoint(b,c,v,w,!0,n),I.free(v),I.free(w));v=this.getLinkPoint(e,f,a,!1,m,b,c);var A=y=w=0;if(m||!k||l){var C=this.computeEndSegmentLength(e,f,a,!1);A=this.getLinkDirection(e,f,v,a,!1,m,b,c);l&&(k||d.w(a)||!m&&
1===d.x+a.x&&1===d.y+a.y)&&(A+=m?0:30,0>z&&(A+=180));0>A?A+=360:360<=A&&(A-=360);l&&(C+=Math.abs(z)*(m?1:2));0===A?w=C:90===A?y=C:180===A?w=-C:270===A?y=-C:(w=C*Math.cos(A*Math.PI/180),y=C*Math.sin(A*Math.PI/180));a.kc()&&l&&(a=f.ga(Ac,I.alloc()),d=I.allocAt(a.x+1E3*w,a.y+1E3*y),this.getLinkPointFromPoint(e,f,a,d,!1,v),I.free(a),I.free(d))}a=n;if(m||!h||l)a=new I(n.x+q,n.y+u);d=v;if(m||!k||l)d=new I(v.x+w,v.y+y);!p&&!m&&h&&3Math.abs(b.y-a.y)?(b.x>=a.x?b.x=a.x+9E9:b.x=a.x-9E9,b.y=a.y):(b.y>=a.y?b.y=a.y+9E9:b.y=a.y-9E9,b.x=a.x);return b}
S.prototype.getLinkPointFromPoint=function(a,b,c,d,e,f){void 0===f&&(f=new I);if(null===a||null===b)return f.assign(c),f;a.isVisible()||(e=a.findVisibleNode(),null!==e&&e!==a&&(b=e.port));a=null;e=b.panel;null===e||e.ce()||(e=e.panel);if(null===e){e=d.x;d=d.y;var g=c.x;c=c.y}else{a=e.wd;e=1/(a.m11*a.m22-a.m12*a.m21);g=a.m22*e;var h=-a.m12*e,k=-a.m21*e,l=a.m11*e,m=e*(a.m21*a.dy-a.m22*a.dx),n=e*(a.m12*a.dx-a.m11*a.dy);e=d.x*g+d.y*k+m;d=d.x*h+d.y*l+n;g=c.x*g+c.y*k+m;c=c.x*h+c.y*l+n}b.jk(e,d,g,c,f);null!==
a&&f.transform(a);return f};function op(a,b){var c=b.jp;null===c&&(c=new pp,c.port=b,c.node=b.part,b.jp=c);return qp(c,a)}
S.prototype.getLinkPoint=function(a,b,c,d,e,f,g,h){void 0===h&&(h=new I);if(c.hb()&&!mp(c))return b.ga(c,h),h;if(c.gd()){var k=op(this,b);if(null!==k){h.assign(k.Eq);if(e&&this.routing===rp){var l=op(this,g);if(null!==l&&k.gm=m.y&&a.y<=m.y+m.height?h.y=a.y:(c.xf(Hc)||c.xf(Kc))&&a.x>=m.x&&a.x<=m.x+m.width&&(h.x=a.x);I.free(k);I.free(l)}}return h}}c=
b.ga(.5===c.x&&.5===c.y?c:Ac,I.alloc());this.pointsCount>(e?6:2)?(g=d?this.i(1):this.i(this.pointsCount-2),e&&(g=np(c,g.copy()))):(k=this.computeSpot(!d,g),f=I.alloc(),g=g.ga(.5===k.x&&.5===k.y?k:Ac,f),e&&(g=np(c,g)),I.free(f));this.getLinkPointFromPoint(a,b,c,g,d,h);I.free(c);return h};
S.prototype.getLinkDirection=function(a,b,c,d,e,f,g,h){a:if(d.hb())var k=d.x>d.y?d.x>1-d.y?0:d.x<1-d.y?270:315:d.x1-d.y?90:d.x<1-d.y?180:135:.5>d.x?225:.5(f?6:2)?(h=e?this.i(1):this.i(this.pointsCount-2),h=f?np(k,h.copy()):c):(c=I.alloc(),h=h.ga(Ac,c),I.free(c));c=Math.abs(h.x-k.x)>Math.abs(h.y-k.y)?h.x>=
k.x?0:180:h.y>=k.y?90:270;I.free(k);k=c}d.kc()&&g.yd(a)&&(k+=180,360<=k&&(k-=360));if(mp(d))return k;a=b.aj();if(0===a)return k;45<=a&&135>a?k+=90:135<=a&&225>a?k+=180:225<=a&&315>a&&(k+=270);360<=k&&(k-=360);return k};S.prototype.computeEndSegmentLength=function(a,b,c,d){if(null!==b&&c.gd()&&(a=op(this,b),null!==a))return a.Av;a=d?this.fromEndSegmentLength:this.toEndSegmentLength;null!==b&&isNaN(a)&&(a=d?b.fromEndSegmentLength:b.toEndSegmentLength);isNaN(a)&&(a=10);return a};
S.prototype.computeSpot=function(a,b){void 0===b&&(b=null);a?(a=b?b:this.fromPort,null===a?a=Ac:(b=this.fromSpot,b.Nb()&&(b=a.fromSpot),a=b===$c?uc:b)):(a=b?b:this.toPort,null===a?a=Ac:(b=this.toSpot,b.Nb()&&(b=a.toSpot),a=b===$c?uc:b));return a};function mp(a){return a===uc||.5===a.x&&.5===a.y}S.prototype.computeOtherPoint=function(a,b){if(this.computeAdjusting()!==ag&&4p.width||n.y>p.height||0>n.x+n.width||0>n.y+n.height)){n=qd.alloc();n.set(g);
if(m instanceof X)h=m.tf(a,b,c,d,e,n);else if(this.path===m){if(m instanceof W)if(h=a,p=d,!1===m.pickable)h=!1;else if(n.multiply(m.transform),p)b:{var r=h,q=n;if(m.Dh(r,q))h=!0;else{if(void 0===q&&(q=m.transform,r.Ce(m.actualBounds))){h=!0;break b}h=r.left;p=r.right;var u=r.top;r=r.bottom;var v=I.alloc(),w=I.alloc(),y=I.alloc(),z=qd.alloc();z.set(q);z.Vv(m.transform);z.Et();w.x=p;w.y=u;w.transform(z);v.x=h;v.y=u;v.transform(z);q=!1;Hn(m,v,w,y)?q=!0:(v.x=p,v.y=r,v.transform(z),Hn(m,v,w,y)?q=!0:(w.x=
h,w.y=r,w.transform(z),Hn(m,v,w,y)?q=!0:(v.x=h,v.y=u,v.transform(z),Hn(m,v,w,y)&&(q=!0))));qd.free(z);I.free(v);I.free(w);I.free(y);h=q}}else h=m.Dh(h,n)}else h=kl(m,a,d,n);h&&(p=m,null!==b&&(p=b(m)),p&&(null===c||c(p))&&e.add(p));qd.free(n)}}}void 0===f&&qd.free(g);return h||null!==this.background||null!==this.areaBackground}void 0===f&&qd.free(g);return!1};
S.prototype.computeCurve=function(){if(null===this.Qf){var a=this.fromPort,b=this.isOrthogonal;this.Qf=null!==a&&a===this.toPort&&!b}return this.Qf?dg:this.curve};S.prototype.computeCorner=function(){if(this.curve===dg)return 0;var a=this.corner;if(isNaN(a)||0>a)a=10;return a};
S.prototype.findMidLabel=function(){for(var a=this.path,b=this.W.j,c=b.length,d=0;dk?-Math.PI/2:Math.PI/2;else m=Math.atan(k/Math.abs(h)),0>h&&(m=Math.PI-m);g=b.x;var n=b.y;h=d.x-g;var p=d.y-n;k=Math.sqrt(h*h+p*p);K.$(h,0)?p=0>p?-Math.PI/2:Math.PI/2:(p=Math.atan(p/Math.abs(h)),0>h&&(p=Math.PI-p));l=
k/l;m=p-m;this.jd(a,b);for(a+=1;ak?-Math.PI/2:Math.PI/2:(k=Math.atan(k/Math.abs(h)),0>h&&(k=Math.PI-k)),h=k+m,b*=l,this.K(a,g+b*Math.cos(h),n+b*Math.sin(h)));this.jd(c,d)}}return!0;case fp:f=this.i(a);n=this.i(c);if(!f.Ma(b)||!n.Ma(d)){e=f.x;f=f.y;g=n.x;n=n.y;l=(g-e)*(g-e)+(n-f)*(n-f);h=b.x;m=b.y;k=d.x;p=d.y;var r=1;if(0!==k-h){var q=(p-m)/(k-h);r=Math.sqrt(1+1/(q*q))}else q=9E9;this.jd(a,b);for(a+=1;ab?0:45<=b&&135>b?90:135<=b&&225>b?180:270;d=-45<=d&&45>d?0:45<=d&&135>d?90:135<=d&&225>d?180:270;var g=e.actualBounds.copy(),h=f.actualBounds.copy();if(g.v()&&h.v()){g.Fc(8,8);h.Fc(8,8);g.Ie(a);h.Ie(c);if(0===b)if(c.x>a.x||270===d&&c.ya.x||90===d&&c.y>a.y&&h.right>a.x){var k=new I(c.x,a.y);var l=new I(c.x,(a.y+c.y)/2);180===d?(k.x=this.computeMidOrthoPosition(a.x,a.y,c.x,c.y,!1),l.x=k.x,l.y=c.y):270===d&&c.ya.y?(k.x=a.xh.bottom)?this.computeMidOrthoPosition(a.x,a.y,c.x,c.y,!1):h.right,l.x=k.x,l.y=c.y):0===d&&a.xh.top&&a.yg.bottom)180===d&&(h.aa(a)||g.aa(c))?k.y=this.computeMidOrthoPosition(a.x,a.y,c.x,c.y,!0):
c.ya.y&&(180===d||270===d)&&(k.y=this.computeMidOrthoPosition(a.x,g.bottom,c.x,Math.min(c.y,h.top),!0)),l.x=c.x,l.y=k.y;if(k.y>g.top&&k.y=g.left&&c.x<=a.x||a.x<=h.right&&a.x>=c.x){if(90===d||270===d)k=new I(Math.max((a.x+c.x)/2,a.x),a.y),l=new I(k.x,c.y)}else k.y=270===d||(0===d||180===d)&&c.ya.y&&h.lefta.y?(k.x=a.x>h.right?this.computeMidOrthoPosition(a.x,a.y,h.right,c.y,!1):a.x>h.left&&(270===d&&a.yh.bottom)?this.computeMidOrthoPosition(a.x,a.y,c.x,c.y,!1):h.left,l.x=k.x,l.y=c.y):180===d&&a.x>h.right&&a.y>h.top&&a.y<
h.bottom&&(k.x=a.x,k.y=a.yg.bottom)0===d&&(h.aa(a)||g.aa(c))?k.y=this.computeMidOrthoPosition(a.x,a.y,c.x,c.y,!0):c.y