@@ -97,6 +97,7 @@ class MapLinks {
9797 this . lastPathId = 10000000 ;
9898 this . paths = [ ] ;
9999 this . lineSpace = Math . floor ( LiteGraph . NODE_SLOT_HEIGHT / 2 ) ;
100+ this . maxDirectLineDistance = Number . MAX_SAFE_INTEGER ;
100101 this . debug = false ;
101102 }
102103
@@ -140,13 +141,13 @@ class MapLinks {
140141 }
141142 }
142143 }
143- return closest ;
144+ return { clipped : closest , closestDistance } ;
144145 }
145146
146147 testPath ( path ) {
147148 const len1 = ( path . length - 1 ) ;
148149 for ( let p = 0 ; p < len1 ; ++ p ) {
149- const clipped = this . findClippedNode ( path [ p ] , path [ p + 1 ] ) ;
150+ const { clipped } = this . findClippedNode ( path [ p ] , path [ p + 1 ] ) ;
150151 if ( clipped ) {
151152 return clipped ;
152153 }
@@ -155,10 +156,13 @@ class MapLinks {
155156 }
156157
157158 mapFinalLink ( outputXY , inputXY ) {
158- const clipped = this . findClippedNode ( outputXY , inputXY ) ;
159+ const { clipped } = this . findClippedNode ( outputXY , inputXY ) ;
159160 if ( ! clipped ) {
160- // direct, nothing blocking us
161- return { path : [ outputXY , inputXY ] } ;
161+ const dist = Math . sqrt ( ( ( outputXY [ 0 ] - inputXY [ 0 ] ) ** 2 ) + ( ( outputXY [ 1 ] - inputXY [ 1 ] ) ** 2 ) ) ;
162+ if ( dist < this . maxDirectLineDistance ) {
163+ // direct, nothing blocking us
164+ return { path : [ outputXY , inputXY ] } ;
165+ }
162166 }
163167
164168 const horzDistance = inputXY [ 0 ] - outputXY [ 0 ] ;
@@ -255,7 +259,7 @@ class MapLinks {
255259 } ;
256260 }
257261
258- mapLink ( outputXY , inputXY , targetNodeInfo , isBlocked , lastDirection ) {
262+ mapLink ( outputXY , inputXY , targetNodeInfo , isBlocked /* , lastDirection */ ) {
259263 const { clippedHorz, clippedVert, path } = this . mapFinalLink ( outputXY , inputXY ) ;
260264 if ( path ) {
261265 return path ;
@@ -273,7 +277,8 @@ class MapLinks {
273277 let linesArea ;
274278
275279 let thisDirection = null ;
276- if ( lastDirection !== 'horz' && horzDistanceAbs > vertDistanceAbs ) {
280+ // if (lastDirection !== 'horz' && horzDistanceAbs > vertDistanceAbs) {
281+ if ( horzDistanceAbs > vertDistanceAbs ) {
277282 // horz then vert to avoid blocking node
278283 blockedNodeId = clippedHorz . node . node . id ;
279284 // blockedArea = clippedHorz.node.area;
@@ -322,7 +327,8 @@ class MapLinks {
322327 lastPathLocation [ 1 ] += 1 ;
323328 }
324329 thisDirection = 'vert' ;
325- } else if ( lastDirection !== 'vert' ) {
330+ // } else if (lastDirection !== 'vert') {
331+ } else {
326332 // vert then horz to avoid blocking node
327333 blockedNodeId = clippedVert . node . node . id ;
328334 // blockedArea = clippedVert.node.area;
@@ -351,7 +357,7 @@ class MapLinks {
351357
352358 lastPathLocation = [
353359 horzDistanceViaBlockLeft <= horzDistanceViaBlockRight ?
354- ( linesArea [ 0 ] - 1 )
360+ ( linesArea [ 0 ] - 1 )
355361 : ( linesArea [ 2 ] ) ,
356362 vertEdge ,
357363 ] ;
@@ -372,9 +378,9 @@ class MapLinks {
372378 // lastPathLocation[0] += 1; //this.lineSpace;
373379 }
374380 thisDirection = 'horz' ;
375- } else {
376- console . log ( 'blocked will not go backwards' , outputXY , inputXY ) ; // eslint-disable-line no-console
377- return [ outputXY , inputXY ] ;
381+ // } else {
382+ // console.log('blocked will not go backwards', outputXY, inputXY);
383+ // return [outputXY, inputXY];
378384 }
379385
380386 // console.log('is blocked check',isBlocked, blockedNodeId);
@@ -495,8 +501,8 @@ class MapLinks {
495501 const outputXYConnection = node . getConnectionPos ( false , slot , linkPos ) ;
496502 const outputNodeInfo = this . nodesById [ node . id ] ;
497503 let outputXY = Array . from ( outputXYConnection ) ;
498- outputXY [ 0 ] = outputNodeInfo . linesArea [ 2 ] ;
499504 output . links . filter ( ( linkId ) => {
505+ outputXY [ 0 ] = outputNodeInfo . linesArea [ 2 ] ;
500506 const link = this . canvas . graph . links [ linkId ] ;
501507 if ( ! link ) {
502508 return false ;
@@ -522,7 +528,8 @@ class MapLinks {
522528 this . getNodeOnPos ( outputXY ) ;
523529
524530 let path = null ;
525- // console.log('blocked', inputBlockedByNode, outputBlockedByNode, 'inputXY', inputXY);
531+ // console.log('blocked', inputBlockedByNode, outputBlockedByNode,
532+ // 'inputXY', inputXY, 'outputXY', outputXY);
526533 if ( ! inputBlockedByNode && ! outputBlockedByNode ) {
527534 const pathFound = this . mapLink ( outputXY , inputXY , nodeInfo , { } , null ) ;
528535 if ( pathFound && pathFound . length > 2 ) {
@@ -637,12 +644,20 @@ class MapLinks {
637644 afterPos [ 1 ] = cornerPos [ 1 ] + cornerRadius * ySignAfter ;
638645 }
639646
640- ctx . lineTo ( beforePos [ 0 ] , beforePos [ 1 ] ) ;
641- corners . push ( cornerPos ) ;
642- // ctx.lineTo(cornerPos[0], cornerPos[1]);
643- // ctx.lineTo(beforePos[0], beforePos[1]);
644- ctx . quadraticCurveTo ( cornerPos [ 0 ] , cornerPos [ 1 ] , afterPos [ 0 ] , afterPos [ 1 ] ) ;
645- isPrevDotRound = true ;
647+ if ( isPrevDotRound
648+ && Math . abs ( isPrevDotRound [ 0 ] - beforePos [ 0 ] ) <= cornerRadius
649+ && Math . abs ( isPrevDotRound [ 1 ] - beforePos [ 1 ] ) <= cornerRadius
650+ ) {
651+ // if two rounded corners are too close, draw a straight line so it doesn't look funny
652+ ctx . lineTo ( cornerPos [ 0 ] , cornerPos [ 1 ] ) ;
653+ // ctx.lineTo(beforePos[0], beforePos[1]);
654+ // ctx.lineTo(afterPos[0], afterPos[1]);
655+ } else {
656+ ctx . lineTo ( beforePos [ 0 ] , beforePos [ 1 ] ) ;
657+ corners . push ( cornerPos ) ;
658+ ctx . quadraticCurveTo ( cornerPos [ 0 ] , cornerPos [ 1 ] , afterPos [ 0 ] , afterPos [ 1 ] ) ;
659+ }
660+ isPrevDotRound = beforePos ;
646661 drawn = true ;
647662 }
648663 }
@@ -704,6 +719,7 @@ export class CircuitBoardLines {
704719 this . canvas = null ;
705720 this . mapLinks = null ;
706721 this . enabled = true ;
722+ this . maxDirectLineDistance = Number . MAX_SAFE_INTEGER ;
707723 }
708724
709725 setEnabled ( e ) { this . enabled = e ; }
@@ -755,6 +771,7 @@ export class CircuitBoardLines {
755771
756772 recalcMapLinks ( ) {
757773 this . mapLinks = new MapLinks ( this . canvas ) ;
774+ this . mapLinks . maxDirectLineDistance = this . maxDirectLineDistance ;
758775 this . mapLinks . debug = this . debug ;
759776 const nodesByExecution = this . canvas . graph . computeExecutionOrder ( ) || [ ] ;
760777 this . mapLinks . mapLinks ( nodesByExecution ) ;
0 commit comments