package app import ( "github.com/veandco/go-sdl2/sdl" ) func getObjectScaledRect(ow, oh, cw, ch int32) sdl.Rect { aspectRatio := float64(ow) / float64(oh) w := int32(max(min(ow, cw), cw)) h := int32(max(min(oh, ch), ch)) if w < h { h = int32(float64(w) * aspectRatio) return sdl.Rect{ X: 0, Y: int32((ch / 2) - (h / 2)), W: int32(w), H: h, } } w = int32(float64(h) * aspectRatio) return sdl.Rect{ X: int32((cw / 2) - (w / 2)), Y: 0, W: w, H: int32(h), } } func getCenteredRect(ow, oh, cw, ch int32) sdl.Rect { return sdl.Rect{ X: (cw - ow) / 2, Y: (ch - oh) / 2, W: ow, H: oh, } }