I’m writing a simple OpenGL game with Haskell. Whenever the user resizes the window I get their width and height. I need to calculate the largest width and height that fits inside their window while maintaining the W/H ratio of 1.6.
This is what I wrote. It works but I don’t think it’s the best way of doing it in Haskell. Can someone suggest some alternatives:
fixedRatio = 1.6
keepRatio (w,h) = head [(floor w',floor h') | w' <- [w, h*fixedRatio], h' <- [h, w/fixedRatio], w' <= w, h' <= h, w'/h' == fixedRatio ]
I’d do it with a guard (condition):