Skip to content

Commit f67e6b5

Browse files
committed
Update docs
1 parent 08cda02 commit f67e6b5

File tree

3 files changed

+52
-27
lines changed

3 files changed

+52
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# example/links is made by example/run_example.sh
22
example/links
33
node_modules
4+
__pycache__

docs/CircuitBoardLines.js

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

docs/QuickConnection.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ export class QuickConnection {
233233
const buttonShift = [
234234
isInput ? -32 : +32,
235235
// force for now so the dots don't move around when the tooltip pops up.
236-
// No need to avoid tool tip if we're using the input, tool tip is visible to the right of dot
236+
// No need to avoid tool tip if we're using the input,
237+
// tool tip is visible to the right of dot
237238
isInput ? 0 : LiteGraph.NODE_SLOT_HEIGHT,
238239
/*
239240
(true || this.acceptingNodes.length === 1 || hasNodeTooltip)
@@ -322,15 +323,22 @@ export class QuickConnection {
322323
boxRect = rRect.slice(0);
323324
} else {
324325
if (boxRect[0] > rRect[0]) {
326+
// eslint-disable-next-line prefer-destructuring
325327
boxRect[0] = rRect[0];
326328
}
327329
if (boxRect[2] < rRect[2]) {
330+
// eslint-disable-next-line prefer-destructuring
328331
boxRect[2] = rRect[2];
329332
}
330333
boxRect[3] += rRect[3];
331334
}
332335

333-
textsToDraw.push({x:textxy[0], y:textxy[1], acceptingText, textAlign});
336+
textsToDraw.push({
337+
x: textxy[0],
338+
y: textxy[1],
339+
acceptingText,
340+
textAlign,
341+
});
334342

335343
let isInsideRect;
336344
if (this.connectDotOnly) {
@@ -346,11 +354,11 @@ export class QuickConnection {
346354
isInsideRect = LiteGraph.isInsideRectangle(
347355
mouseX,
348356
mouseY,
349-
isInput ? box[0] : (linkPos[0] - (LiteGraph.NODE_SLOT_HEIGHT/2) ),
357+
isInput ? box[0] : (linkPos[0] - (LiteGraph.NODE_SLOT_HEIGHT / 2)),
350358
linkPos[1] - 10,
351359
isInput ?
352-
((linkPos[0] - box[0]) + LiteGraph.NODE_SLOT_HEIGHT/2 )
353-
: (rRect[2] + LiteGraph.NODE_SLOT_HEIGHT/2 ),
360+
((linkPos[0] - box[0]) + LiteGraph.NODE_SLOT_HEIGHT / 2)
361+
: (rRect[2] + LiteGraph.NODE_SLOT_HEIGHT / 2),
354362
rRect[3],
355363
);
356364
}
@@ -397,7 +405,6 @@ export class QuickConnection {
397405
ctx.closePath();
398406
}
399407

400-
401408
linkPos[1] += LiteGraph.NODE_SLOT_HEIGHT * scale;
402409
return false;
403410
});
@@ -423,9 +430,9 @@ export class QuickConnection {
423430
textsToDraw.filter((textToDraw) => {
424431
ctx.textAlign = textToDraw.textAlign;
425432
ctx.fillText(textToDraw.acceptingText, textToDraw.x, textToDraw.y);
433+
return true;
426434
});
427435

428-
429436
ctx.font = oldFont;
430437
}
431438
}

0 commit comments

Comments
 (0)