e){
if(currentTool==='polygonSelect'){
const [x,y]=getCanvasCoordinates(e);
if(currentSelection.length>0&&
Math.abs(x-currentSelection[0].x)<5&&
Math.abs(y-currentSelection[0].y)<5){
completePolygonSelection();
}else{
currentSelection.push({x,y});
drawImage();
}
}else if(currentTool==='magicWand'){
const [x,y]=getCanvasCoordinates(e);
magicWandSelect(Math.floor(x),Math.floor(y),30);
}
}
function drawSelectionPreview(){
ctx.strokeStyle='#ff0000';
ctx.lineWidth=2/scale;
ctx.beginPath();
currentSelection.forEa