Advertisement
Guest User

Untitled

a guest
Feb 28th, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 KB | None | 0 0
  1. public static int NSD(int a, int b)
  2.     {
  3.         for (int i = 2; ; i++)
  4.         {
  5.             if (a % i == 0 && b % i == 0)
  6.             {
  7.                 return i;
  8.             }
  9.         }
  10.         return 1;
  11.     }
  12.  
  13.     public static Size CalculateOptimalSize(int width, int height)
  14.     {
  15.         Size vr = new Size(width, height);
  16.         int sirkaSloupce = 480;
  17.         if (width > sirkaSloupce)
  18.         {
  19.             //int gcd = NSD(width, height);
  20.             //if (gcd != 1)
  21.             //{
  22.             //    if (sirkaSloupce < width)
  23.             //    {
  24.             //        int i = 1;
  25.             //        while (true)
  26.             //        {
  27.             //            if (gcd * i > width)
  28.             //            {
  29.             //                break;
  30.             //            }
  31.             //            i++;
  32.             //        }
  33.             //        vr.Height = (height / gcd) * i;
  34.             //        vr.Width = (width / gcd) * i;
  35.             //    }
  36.             //    else
  37.             //    {
  38.             //        //W:15 H:55
  39.             //        //W:55 H:15
  40.             //        int w = gcd;
  41.             //        int pric = 1;
  42.             //        while (true)
  43.             //        {
  44.             //            if (w > sirkaSloupce)
  45.             //            {
  46.             //                break;
  47.             //            }
  48.             //            pric++;
  49.             //        }
  50.             //        vr.Height = gcd * pric;
  51.             //        vr.Width = w;
  52.             //    }
  53.             //}
  54.             //else
  55.             //{
  56.             //    //-W:1000 H:500
  57.             //    if (width > height)
  58.             //    {
  59.             //        vr = CalculateOptimalSize2(width, height, sirkaSloupce);
  60.             //    }
  61.             //    else
  62.             //    {
  63.  
  64.             //    }
  65.  
  66.             //}
  67.             vr.Width = sirkaSloupce;
  68.  
  69.             // mohl by ses ještě rozhodovat jestli round, nebo floor, nebo ceil
  70.             vr.Height = sirkaSloupce * height / width;
  71.         }
  72.        
  73.         return vr;
  74.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement