Given a triangle $T$, how can I calculate the smallest square that contains $T$?
Using GeoGebra, I implemented a heuristic that seems to work well in practice. The problem is, I have no proof that it is always correct. Here is the heuristic:
Try to construct a square whose diagonal is the longest side of $T$. This works if both angles near the longest side are at most 45 degrees (it is shown in green in the demo above).
Otherwise, try to construct a square whose side contains the shortest side of $T$. The side length will be the maximum between the shortest side of $T$ and the height to the shortest side of $T$ (it is shown in blue or cyan in the demo above).
Is this heuristic always correct? If not, what is a correct method for calculating the smallest containing square?