Skip to content

Arrow termination#3899

Open
Akshay-2007-1 wants to merge 8 commits into
source-academy:masterfrom
Akshay-2007-1:arrow-termination
Open

Arrow termination#3899
Akshay-2007-1 wants to merge 8 commits into
source-academy:masterfrom
Akshay-2007-1:arrow-termination

Conversation

@Akshay-2007-1
Copy link
Copy Markdown
Contributor

@Akshay-2007-1 Akshay-2007-1 commented May 27, 2026

Description

Closes #3789.
Closes #3755
Closes #3795

Root cause in ArrowFromText.calculateSteps() (else branch):

The else branch handles arrows where the target (to.x() >= from.x()) is to the right of the text. It computes:
preTerminalX = max(frameExitX, to.x() - terminalSegmentLength)

When frameExitX (the frame's right edge + 20px) extends past the closure's left edge, which happens when the closure is positioned within or just past the frame boundary — preTerminalX > to.x(). The arrow then travels right past the closure, turns down, and comes back LEFT to land at to.x() (the left edge), visually piercing through the closure.

Fix: detect when preTerminalX > to.x() (approach is from the right) and land at to.x() + to.width() (the right edge) instead. The two previous fixes to ArrowFromArrayUnit remain correct for their own scenario.

Before After
image image

Before After
image image

Before After
image image

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Code quality improvements

How to test

Look at the following code from #3789 and others!

function add_streams(s1, s2) {
return pair(head(s1) + head(s2),
() => add_streams(stream_tail(s1), stream_tail(s2)));
}
const strm = pair(1, () => pair(2, () => add_streams(strm, strm)));
eval_stream(strm, 10);

const y = 2;
const f = () => null;
const q = pair(y, f);

{
    const x = 1;
    const p = pair(x, 2);
    set_tail(p, q);
}

function fun(x) {
    return y => x;
}

const someName = fun(1);

Checklist

  • I have tested this code
  • I have updated the documentation

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves arrow routing logic in the CSE machine. Specifically, it updates ArrowFromArrayUnit to dynamically calculate the target X coordinate based on the source center, and updates ArrowFromText to handle cases where the arrow approaches from the right. A review comment points out an edge case in ArrowFromText where the arrow could pierce the target if frameExitX falls inside it, and provides a code suggestion to safely position preTerminalX to the right of the target.

Comment thread src/features/cseMachine/components/arrows/ArrowFromText.tsx Outdated
@RichDom2185
Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2026

Review Change Stack

Walkthrough

Two arrow routing calculations in the CSE Machine visualization are refined to compute corrected terminal X coordinates. ArrowFromArrayUnit now selects target X based on source-center spatial relationships to function values, and ArrowFromText chooses the terminal X coordinate more carefully for non-left-bending arrow paths, addressing cases where arrows previously pointed to the wrong edge of function objects.

Changes

Arrow Endpoint Selection Corrections

Layer / File(s) Summary
Array unit arrow endpoint selection for function values
src/features/cseMachine/components/arrows/ArrowFromArrayUnit.tsx
ArrowFromArrayUnit.calculateSteps now derives sourceCenterX and selects targetX by comparing the source center against the target's bounds, choosing the target's left or right edge for out-of-range cases or the target center when within range.
Text arrow endpoint selection for non-left-bending routes
src/features/cseMachine/components/arrows/ArrowFromText.tsx
ArrowFromText.calculateSteps introduces terminalTargetX logic for non-left-bending routing, choosing the target's right edge when preTerminalX overshoots the target's left edge, otherwise using the target's original X position.

🎯 2 (Simple) | ⏱️ ~8 minutes

🐰 Two arrows now find their way,
No longer lost or led astray,
They calculate with thoughtful care,
Where source and target truly pair,
Geometry bends to logic's play! 🎯

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Arrow termination' is vague and generic, providing no specific details about which component or aspect of arrow routing is being fixed. Use a more specific title like 'Fix arrow termination for right-approaching closures' to clearly indicate the nature and scope of the fix.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR correctly addresses issue #3789 by fixing arrow termination for right-approaching closures, detecting when preTerminalX > to.x() and landing at the right edge instead of left edge.
Out of Scope Changes check ✅ Passed Both file changes (ArrowFromArrayUnit and ArrowFromText) are directly related to fixing arrow termination issues as specified in issue #3789, with no unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description is comprehensive and follows the template structure. It includes a clear summary with issue references, root cause analysis, the implemented fix with visual before/after comparisons, specifies the change type as a bug fix, and provides test instructions with code examples.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Akshay-2007-1 and others added 3 commits May 27, 2026 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2 participants