Tomki

KEK

Nov 9th, 2018
752
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4.  
  5. long long rectangle_rotation(int a, int b)
  6. {
  7.  
  8.     // TODO: fix mistakes while calculating big coords
  9.  
  10.     std::cout << a << '\t' << b << '\n';
  11.  
  12.     std::vector<std::pair<double, double>> coords;
  13.  
  14.     coords.emplace_back(-a/2*cos(M_PI/4) - b/2*sin(M_PI/4), -a/2*sin(M_PI/4) + b/2*cos(M_PI/4));
  15.     coords.emplace_back(-a/2*cos(M_PI/4) + b/2*sin(M_PI/4), -a/2*sin(M_PI/4) - b/2*cos(M_PI/4));
  16.     coords.emplace_back((-1)*(coords[0].first), (-1)*(coords[0].second));
  17.     coords.emplace_back((-1)*(coords[1].first), (-1)*(coords[1].second));
  18.  
  19.     for (auto& i : coords)
  20.         std::cout << i.first << '\t' << i.second << '\n';
  21.  
  22.     double left_edge = coords[0].first;
  23.     double right_edge = -1*left_edge;
  24.     double subEdgeLeft = (a > b) ? coords.at(1).first : coords.at(3).first;
  25.     double subEdgeRight = (a > b) ? coords.at(3).first : coords.at(1).first;
  26.  
  27.     double b03 = coords.at(3).second - coords.at(3).first;
  28.     double b01 = coords.at(0).second + coords.at(0).first;
  29.     double b32 = -b01;
  30.     double b12 = -b03;
  31.  
  32.     long long counter {0};
  33.  
  34.     int initX = static_cast<int>(floor(left_edge + 1));
  35.  
  36.     for (; initX <= subEdgeLeft; initX += 1)
  37.         for (auto coordY = static_cast<int>(floor(initX + b03)); coordY >= -initX + b01; coordY -= 1)
  38.             counter++;
  39.     if (a > b)
  40.     {
  41.         for (; initX <= subEdgeRight; initX += 1)
  42.             for (auto coordY = static_cast<long>(floor(initX + b03)); coordY >= initX + b12; coordY -= 1)
  43.                 counter++;
  44.         for (; initX <= right_edge; initX += 1)
  45.             for (auto coordY = static_cast<long>(floor(-initX + b32)); coordY >= initX + b12; coordY -= 1)
  46.                 counter++;
  47.     }
  48.     else
  49.     {
  50.         for (; initX <= subEdgeRight; initX += 1)
  51.             for (auto coordY = static_cast<long>(floor(-initX + b32)); coordY >= -initX + b01; coordY -= 1)
  52.                 counter++;
  53.         for (; initX <= right_edge; initX += 1)
  54.             for (auto coordY = static_cast<long>(floor(-initX + b32)); coordY >= initX + b12; coordY -= 1)
  55.                 counter++;
  56.     }
  57.  
  58.     return counter; // Do your magic!
  59. }
  60.  
  61. int main()
  62. {
  63.     rectangle_rotation(3706,6632);
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment