Created
August 6, 2014 14:07
-
-
Save moimikey/2dc958319220771a8230 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Returns an object with a new width and height | |
# constraining the proportions of the given max width | |
# and max height | |
# | |
# examples: | |
# Util.scaleProportion(200, 200, 2000, 2000); | |
# > Object {width: 200, height: 200} | |
# scaleProportion(200, 200, 2582, 2394) | |
# > Object {width: 200, height: 185} | |
# | |
Util.scaleProportion = (maxW, maxH, currW, currH) -> | |
ratio = currH / currW | |
if currW >= maxW and ratio <= 1 | |
currW = maxW | |
currH = currW * ratio | |
else if currH >= maxH | |
currH = maxH | |
currW = currH / ratio | |
width: ~~currW, height: ~~currH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment