Phoenix_x

Untitled

Oct 20th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include<iostream>
  3. #include <algorithm> //min
  4.  
  5. using namespace std;
  6.  
  7. struct Circle
  8. {
  9.     int x;
  10.     int y;
  11.     int radius;
  12. };
  13.  
  14. struct BoundingBox
  15. {
  16.     int bottomLeftAngleX;
  17.     int bottomLeftAngleY;
  18.     int topRightAngleX;
  19.     int topRightAngleY;
  20. };
  21.  
  22. Circle circleCoordinates(int x, int y, int radius);
  23. BoundingBox circleBoundingBox(Circle circle);
  24. void extractCircleBoundingBox(BoundingBox boundingBox);
  25. BoundingBox boundingForTwoBoxes(BoundingBox a, BoundingBox b);
  26.  
  27. void main()
  28. {
  29.     Circle circle_1 = circleCoordinates(4, 5, 3); //create circle
  30.     Circle circle_2 = circleCoordinates(2, 8, 2);
  31.  
  32.     BoundingBox boundingBox_1 = circleBoundingBox(circle_1); //get bounding box of the circle
  33.     BoundingBox boundingBox_2 = circleBoundingBox(circle_2);
  34.  
  35.     BoundingBox boundsOfTwoBoxes = boundingForTwoBoxes(boundingBox_1, boundingBox_2); // bounds two bounding boxes
  36.     extractCircleBoundingBox(boundsOfTwoBoxes); //prints bounding box in specified format
  37.    
  38. }
  39.  
  40. BoundingBox boundingForTwoBoxes(BoundingBox a, BoundingBox b) //creates bounding box with parameter a circle
  41. {
  42.     BoundingBox boundingBox;
  43.  
  44.     boundingBox.bottomLeftAngleX = min(a.bottomLeftAngleX, b.bottomLeftAngleX); //gets smallest number
  45.     boundingBox.bottomLeftAngleY = min(a.bottomLeftAngleY, b.bottomLeftAngleY);
  46.  
  47.     boundingBox.topRightAngleX = max(a.topRightAngleX, b.topRightAngleX); //gets biggest numver
  48.     boundingBox.topRightAngleY = max(a.topRightAngleY, b.topRightAngleY);
  49.  
  50.     return boundingBox;
  51. }
  52.  
  53. Circle circleCoordinates(int x, int y, int radius) //creates circle
  54. {
  55.     struct Circle circle;
  56.     circle.x = x;
  57.     circle.y = y;
  58.     circle.radius = radius;
  59.  
  60.     return circle;
  61. }
  62.  
  63. BoundingBox circleBoundingBox(Circle circle) //creates bounding box with parameter a circle
  64. {
  65.     BoundingBox boundingBox;
  66.  
  67.     boundingBox.bottomLeftAngleX = circle.x - circle.radius;
  68.     boundingBox.bottomLeftAngleY = circle.y - circle.radius;
  69.  
  70.     boundingBox.topRightAngleX = circle.x + circle.radius;
  71.     boundingBox.topRightAngleY = circle.y + circle.radius;
  72.  
  73.     return boundingBox;
  74. }
  75.  
  76. void extractCircleBoundingBox(BoundingBox boundingBox)
  77. {
  78.     cout << "(" << boundingBox.bottomLeftAngleX << ", " << boundingBox.bottomLeftAngleY << ")"
  79.         << "(" << boundingBox.topRightAngleX << ", " << boundingBox.topRightAngleY << ")";
  80. }
Advertisement
Add Comment
Please, Sign In to add comment