+void csr_auto_fit( csr_target *rt, float padding )
+{
+ // Correct aspect ratio to be square
+ float dx, dy, d, l, cx, cy;
+ dx = rt->bounds[1][0] - rt->bounds[0][0];
+ dy = rt->bounds[1][1] - rt->bounds[0][1];
+
+ l = fmaxf( dx, dy );
+ d = l * ( l / dx ) * .5f;
+
+ cx = (rt->bounds[1][0] + rt->bounds[0][0]) * .5f;
+ cy = (rt->bounds[1][1] + rt->bounds[0][1]) * .5f;
+
+ rt->bounds[0][0] = cx - d - padding;
+ rt->bounds[1][0] = cx + d + padding;
+ rt->bounds[0][1] = cy - d - padding;
+ rt->bounds[1][1] = cy + d + padding;
+
+ rt->scale = d + padding;
+}
+