Guest User

Untitled

a guest
Jan 19th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. x * size <= width //x - number of columns
  2. y * size <= height //y - number of rows
  3. x * y <= N //N - number of squares
  4. size -> max //size - size of squares
  5.  
  6. 1 1 1 1
  7. 1 1 1 1
  8. 1 1 0 0
  9.  
  10. // to make things more simple I put width as bigger size
  11. int biggerSize = this.ClientSize.Width;
  12. int lowerSize = this.ClientSize.Height;
  13. int maxSize = int.MinValue;
  14. int index = 0;
  15. int index2 = 0;
  16.  
  17. // find max suitable size
  18. for (int i = _rects.Count; i > 0; i--) {
  19. int size = biggerSize / i;
  20. int j = (int)Math.Floor((double)lowerSize / size);
  21.  
  22. if (i * j >= _boards.Count && size > maxSize) {
  23. maxSize = size;
  24. index = (int)i;
  25. index2 = (int)j;
  26. }
  27. }
  28.  
  29. int counter = 0;
  30.  
  31. // place all rectangles
  32. for (int i = 0; i < index; i++) {
  33. for (int j = 0; j < index2; j++) {
  34. if (counter < _rects.Count) {
  35. _rects[counter].Size = new Size(maxSize, maxSize);
  36. _rects[counter].Location = new Point(i * maxSize, j * maxSize);
  37. }
  38.  
  39. counter++;
  40. }
  41. }
Add Comment
Please, Sign In to add comment