00001 00007 #include <math.h> 00008 #include "rectangle.h" 00009 #include "image.h" 00010 00011 Rectangle::Rectangle() : Shape() 00012 { 00013 } 00014 00015 Rectangle::Rectangle(BoundingBox& box) 00016 { 00017 m_box = box; 00018 } 00019 00020 Rectangle::~Rectangle() 00021 { 00022 } 00023 00024 SHAPE_TYPE Rectangle::GetType() const{ 00025 return RECTANGLE; 00026 } 00027 00028 const std::string& Rectangle::GetName() const { 00029 static const std::string s_name = "RECTANGLE"; 00030 return s_name; 00031 } 00032 00033 void Rectangle::Draw(QPainter* p, int fact) 00034 { 00035 p->drawRect(m_box.GetOriginX() * fact, 00036 m_box.GetOriginY() * fact, 00037 m_box.GetWidth() * fact, 00038 m_box.GetHeight() * fact); 00039 } 00040 00041 double Rectangle::SumValues(Image* pData) 00042 { 00043 double s = 0; 00044 for (int y = m_box.GetOriginY(); y < m_box.GetEndY(); y++) { 00045 for (int x = m_box.GetOriginX(); x < m_box.GetEndX(); x++) { 00046 s += (double)pData->GetData(x, y); 00047 } 00048 } 00049 return s; 00050 } 00051 00052 double Rectangle::GetSurface() const 00053 { 00054 return (double)(GetWidth() * GetHeight()); 00055 } 00056 00057 bool Rectangle::IsInside(int x, int y) const 00058 { 00059 return m_box.IsInside(x, y); 00060 }