Limit hooks to main diagonal
Restrict Ferrers-Rogers-Ramanujan animation to traverse only the main diagonal (top-left to bottom-right) of the Ferrers diagram. Process hooks at positions (i, i) as long as a box exists, stopping when the diagonal ends. This replaces the previous diagonal traversal to avoid generating excessive hooks. X-Lovable-Edit-ID: edt-dd8be332-f1e2-49f5-9077-6354075ccfe7
This commit is contained in:
commit
9433f41cbf
1 changed files with 12 additions and 30 deletions
|
|
@ -58,49 +58,31 @@ const FerrersRogersRamanujan = () => {
|
|||
setIsAnimating(true);
|
||||
};
|
||||
|
||||
// Animation effect
|
||||
// Animation effect - traverse main diagonal only
|
||||
useEffect(() => {
|
||||
if (!isAnimating || committedPartition.length === 0) return;
|
||||
|
||||
const partition = committedPartition;
|
||||
|
||||
// Find the hook at current animation step
|
||||
let found = false;
|
||||
let hookCount = 0;
|
||||
let targetRow = 0, targetCol = 0;
|
||||
// Main diagonal: positions (0,0), (1,1), (2,2), ... while box exists
|
||||
const row = animationStep;
|
||||
const col = animationStep;
|
||||
|
||||
const maxRow = partition.length;
|
||||
const maxCol = partition[0] || 0;
|
||||
|
||||
for (let d = 0; d < maxRow + maxCol && !found; d++) {
|
||||
for (let r = 0; r <= d; r++) {
|
||||
const c = d - r;
|
||||
if (r < partition.length && c < partition[r]) {
|
||||
if (hookCount === animationStep) {
|
||||
targetRow = r;
|
||||
targetCol = c;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
hookCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
// Animation complete
|
||||
// Check if this diagonal position has a box
|
||||
if (row >= partition.length || col >= partition[row]) {
|
||||
// Animation complete - no more diagonal boxes
|
||||
setIsAnimating(false);
|
||||
setAnimatingHook(null);
|
||||
return;
|
||||
}
|
||||
|
||||
setAnimatingHook({ row: targetRow, col: targetCol });
|
||||
setAnimatingHook({ row, col });
|
||||
|
||||
// Calculate hook size
|
||||
const boxesRight = partition[targetRow] - targetCol - 1;
|
||||
// Calculate hook size: boxes to the right + boxes below + 1 (the box itself)
|
||||
const boxesRight = partition[row] - col - 1;
|
||||
let boxesBelow = 0;
|
||||
for (let r = targetRow + 1; r < partition.length; r++) {
|
||||
if (partition[r] > targetCol) {
|
||||
for (let r = row + 1; r < partition.length; r++) {
|
||||
if (partition[r] > col) {
|
||||
boxesBelow++;
|
||||
} else {
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue