function recursiveBlur(
imageData, depth, intensity
) {
// Base case: stop recursing
if (depth <= 0 || intensity < 0.1)
return imageData;
// Apply blur at current intensity
const blurred =
applyBlur(imageData, intensity);
// Recurse with reduced depth & intensity
return recursiveBlur(
blurred, depth - 1, intensity * 0.7
);
}
function flattenLayers(layerGroup) {
const result = [];
for (const item of layerGroup.children) {
if (item.type === 'layer') {
result.push(item);
} else if (item.type === 'group') {
// Recursion: group can contain groups
result.push(...flattenLayers(item));
}
}
return result;
}
function deepClone(obj) {
if (obj === null ||
typeof obj !== 'object') return obj;
if (Array.isArray(obj))
return obj.map(
item => deepClone(item)
);
const clone = {};
for (const key in obj) {
clone[key] = deepClone(obj[key]);
}
return clone;
}
Add recursion depth limits to prevent stack overflow. Compare: recursive Fibonacci (exponential — SLOW) vs iterative (linear — fast). Visualize: draw the call tree for recursiveBlur(img, 4, 1.0).
git switch -c feature/PIXELCRAFT-058-recursion
git add server/ src/
git commit -m "Add recursive blur + fix nested layers (PIXELCRAFT-058)"
git push origin feature/PIXELCRAFT-058-recursion
# PR → Review → Merge → Close ticket ✅
Recursion solves problems that contain smaller versions of themselves.
Recursive thinking is a fundamental problem-solving paradigm. Every recursive solution has an iterative equivalent, but some problems are naturally recursive.