Straighten a 2d shape or polygon

Does D3 has a method that helps to straighten a 2d shape or polygon?

For example given the image
Screenshot 2021-12-11 at 15.02.36

Could it be rotated from any of its corners to have it in perfect straight alignment, like the image below?
Screenshot 2021-12-11 at 15.02.36

The rotation angle needed to make it squared is Right Triangle Calculator

The way the rotation is applied depends on the data type of the image, svg, bitmap…