This overleaf document outlines the logic flow for calculateMaxLong in section 1 and proposes a new algorithm for calculateTargetedLong in section 2. I'm posting this issue to seek feedback on the calculations.
The document or PR #882 should be referenced for an up-to-date full derivation and context.