-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRectangulo.cpp
More file actions
37 lines (27 loc) · 939 Bytes
/
Copy pathRectangulo.cpp
File metadata and controls
37 lines (27 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "Rectangulo.h"
#include <iomanip>
Rectangulo::Rectangulo() : x1(0), y1(0), x2(0), y2(0) {}
Rectangulo::Rectangulo(double x1, double y1, double width, double height)
: x1(x1), y1(y1), x2(x1 + width), y2(y1 + height) {}
double Rectangulo::getWidth() const {
return x2 - x1;
}
double Rectangulo::getHeight() const {
return y2 - y1;
}
double Rectangulo::getCenterX() const {
return x1 + getWidth() / 2.0;
}
double Rectangulo::getCenterY() const {
return y1 + getHeight() / 2.0;
}
double Rectangulo::getArea() const {
return getWidth() * getHeight();
}
void Rectangulo::imprimir() const {
double centroX = (x1 + x2) / 2.0;
std::cout << "[x1: " << x1 << ", y1: " << y1 << ", x2: " << x2 << ", y2: " << y2 << ", centroX: " << centroX << "]" << std::endl;
}
bool Rectangulo::intersecta(const Rectangulo& otro) const {
return !(x1 > otro.x2 || x2 < otro.x1 || y1 > otro.y2 || y2 < otro.y1);
}