- 
      
- 
        Save otienog1/2145c3d8ad6df90a008e3e9f6f392b9e to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or 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
    
  
  
    
  | function fitInto(desiredWidth, desiredHeight, actualWidth, actualHeight) { | |
| var actualSlope = actualHeight / actualWidth; | |
| if (isFinite(actualSlope || '@')) { | |
| if (desiredHeight / desiredWidth > actualSlope) { | |
| desiredHeight = desiredWidth * actualSlope; | |
| } | |
| else { | |
| desiredWidth = desiredHeight / actualSlope; | |
| } | |
| } | |
| else { | |
| desiredWidth = desiredHeight = NaN; | |
| } | |
| return { width: desiredWidth, height: desiredHeight }; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment