Skip to content

Commit

Permalink
Don't consider curved edges in offset heuristic
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Dec 30, 2024
1 parent 1af8399 commit f32822f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/ui.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ UIMode.Connect = class extends UIMode {
const align = new Map();
const offset = new Map();
const curve = new Map();
// In our offset heuristic below, where we attempt to avoid overlap, we only
// wish to consider offset for edges that are not curved.
const offset_only = new Map();
// We only want to pick `centre` when the source and target are equally constraining
// (otherwise we end up picking `centre` far too often). So we check that they're both
// being considered equally. This means `centre` is chosen only rarely, but often in
Expand Down Expand Up @@ -351,6 +354,12 @@ UIMode.Connect = class extends UIMode {
}
offset.set(options.offset, offset.get(options.offset) + 1);
}
if (options.offset !== null && (options.curve === null || options.curve === 0)) {
if (!offset_only.has(options.offset)) {
offset_only.set(options.offset, 0);
}
offset_only.set(options.offset, offset_only.get(options.offset) + 1);
}
if (options.curve !== null) {
if (!curve.has(options.curve)) {
curve.set(options.curve, 0);
Expand Down Expand Up @@ -408,7 +417,7 @@ UIMode.Connect = class extends UIMode {
const attempt = offset_attempts.shift();
// We need to negate because the offsets in `offset` are negated, because they
// record offset candidates, rather than offsets that are present.
if (!offset.has(-attempt)) {
if (!offset_only.has(-attempt)) {
options.offset = attempt;
break;
}
Expand Down

0 comments on commit f32822f

Please sign in to comment.