Created
          July 21, 2017 16:42 
        
      - 
      
- 
        Save garystorey/d586cbfd4c7a7e6942a05dac3db58978 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