Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include<iostream>
- #include <algorithm> //min
- using namespace std;
- struct Circle
- {
- int x;
- int y;
- int radius;
- };
- struct BoundingBox
- {
- int bottomLeftAngleX;
- int bottomLeftAngleY;
- int topRightAngleX;
- int topRightAngleY;
- };
- Circle circleCoordinates(int x, int y, int radius);
- BoundingBox circleBoundingBox(Circle circle);
- void extractCircleBoundingBox(BoundingBox boundingBox);
- BoundingBox boundingForTwoBoxes(BoundingBox a, BoundingBox b);
- void main()
- {
- Circle circle_1 = circleCoordinates(4, 5, 3); //create circle
- Circle circle_2 = circleCoordinates(2, 8, 2);
- BoundingBox boundingBox_1 = circleBoundingBox(circle_1); //get bounding box of the circle
- BoundingBox boundingBox_2 = circleBoundingBox(circle_2);
- BoundingBox boundsOfTwoBoxes = boundingForTwoBoxes(boundingBox_1, boundingBox_2); // bounds two bounding boxes
- extractCircleBoundingBox(boundsOfTwoBoxes); //prints bounding box in specified format
- }
- BoundingBox boundingForTwoBoxes(BoundingBox a, BoundingBox b) //creates bounding box with parameter a circle
- {
- BoundingBox boundingBox;
- boundingBox.bottomLeftAngleX = min(a.bottomLeftAngleX, b.bottomLeftAngleX); //gets smallest number
- boundingBox.bottomLeftAngleY = min(a.bottomLeftAngleY, b.bottomLeftAngleY);
- boundingBox.topRightAngleX = max(a.topRightAngleX, b.topRightAngleX); //gets biggest numver
- boundingBox.topRightAngleY = max(a.topRightAngleY, b.topRightAngleY);
- return boundingBox;
- }
- Circle circleCoordinates(int x, int y, int radius) //creates circle
- {
- struct Circle circle;
- circle.x = x;
- circle.y = y;
- circle.radius = radius;
- return circle;
- }
- BoundingBox circleBoundingBox(Circle circle) //creates bounding box with parameter a circle
- {
- BoundingBox boundingBox;
- boundingBox.bottomLeftAngleX = circle.x - circle.radius;
- boundingBox.bottomLeftAngleY = circle.y - circle.radius;
- boundingBox.topRightAngleX = circle.x + circle.radius;
- boundingBox.topRightAngleY = circle.y + circle.radius;
- return boundingBox;
- }
- void extractCircleBoundingBox(BoundingBox boundingBox)
- {
- cout << "(" << boundingBox.bottomLeftAngleX << ", " << boundingBox.bottomLeftAngleY << ")"
- << "(" << boundingBox.topRightAngleX << ", " << boundingBox.topRightAngleY << ")";
- }
Advertisement
Add Comment
Please, Sign In to add comment