Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "math"
  6. )
  7.  
  8. func CalcNewSize(w, h uint, maxW, maxH int32) (uint, uint) {
  9. haveF := float64(w) / float64(h)
  10. wantF := float64(maxW) / float64(maxH)
  11. if haveF < wantF {
  12. hh := float64(maxH)
  13. ww := math.Floor(haveF*hh + 0.5)
  14. return uint(ww), uint(hh)
  15. } else {
  16. ww := float64(maxW)
  17. hh := math.Floor(ww/haveF + 0.5)
  18. return uint(ww), uint(hh)
  19. }
  20. }
  21. func main() {
  22. fmt.Println(CalcNewSize(100, 150, 50, 60))
  23. fmt.Println("Hello, playground")
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement