Rotating canvas and roi altogether

Hello. I am trying to rotate canvas +90 or -90 degrees, along with all roi on it (just the roi rectangle(s)). I succesfully managed to rotate canvas and then selected roi but after rotation of selected roi, roi went out of canvas. Then I understand canvas must be square-shaped to rotate roi succesfully. Made it with canvas size, then another problem appeared, upon resize of canvas, roi moves to its new position…
Here is the macro I tried, you will see the problem upon executing macro while an image open with some roi rectangles on it;

origwd=getWidth();
orighg=getHeight();
if (origwd==orighg){
	rotateplus90();
	waitForUser("all-equal");
}

if (origwd>orighg){
		print(origwd," wider ",orighg);
		
	run("Canvas Size...", "width="+origwd+" height="+origwd+" position=Bottom-Center");
	waitForUser("1");
	rotateplus90();
	waitForUser("2");
	run("Canvas Size...", "width="+orighg+" height="+origwd+" position=Center-Left");
	waitForUser("3");
}

if (origwd<orighg){
	run("Canvas Size...", "width="+orighg+" height="+orighg+"  position=Center-Left");
	rotateplus90();
	run("Canvas Size...", "width="+orighg+" height="+origwd+"  position=Top-Center");
	print(origwd," & ",orighg);
}



   function rotateplus90() {
nroi= roiManager("count");
for (i=0; i<nroi; i++) {

roiManager("Select", i);
run("Rotate...", "rotate angle=90");
roiManager("Update");
}
run("Rotate 90 Degrees Right");
   }

   function rotateminus90() {
nroi= roiManager("count");
for (i=0; i<nroi; i++) {

roiManager("Select", i);
run("Rotate...", "rotate angle=-90");
roiManager("Update");
}
run("Rotate 90 Degrees Left");
   }