vc++ 2013 入门经典画图时,为什么构造函数都要进行封闭图形计算?
其中InflateRect()NormalizeRect();函数什么意思啊,重点是为什么要调用它们?
他们起什么作用,请指点迷津,小弟不胜感激。。
代码示例如下
```CEllipse:: CEllipse (const CPoint& center, const CPoint& end, COLORREF color) : CElement(center, color)
{
// Create the rectangle enclosing the ellipse
int halfWidth{ abs(center.x - end.x) }; // Half the width of the defining rectangle
int halfHeight{ abs(center.y - end.y) }; // Half the height of the defining rectangle
m_StartPoint = m_BottomRight = center;
m_StartPoint.Offset(-halfWidth, -halfHeight); // Top left is offset by minus half height and half width
m_BottomRight.Offset(halfWidth, halfHeight); // Bottom right point you add to the center coordinates
// Points must differ by 2 in x & y for valid rectangle
if (m_StartPoint.x - m_BottomRight.x < 2) m_BottomRight.x += 2;
if (m_StartPoint.y - m_BottomRight.y < 2) m_BottomRight.y += 2;
m_EnclosingRect = CRect{ m_StartPoint, m_BottomRight };
m_EnclosingRect.NormalizeRect();
m_EnclosingRect.InflateRect(m_PenWidth, m_PenWidth);
}
CLine::CLine(const CPoint& start, const CPoint& end, COLORREF color) :
CElement { start, color }, m_EndPoint { end }
{
// Define the enclosing rectangle
m_EnclosingRect = CRect { start, end };
m_EnclosingRect.NormalizeRect();
m_EnclosingRect.InflateRect(m_PenWidth, m_PenWidth);
}
```CCircle::CCircle(const CPoint& start, const CPoint& end, COLORREF color) : CElement { start, color }
{
// Calculate the radius using floating-point values
// because that is required by sqrt() function (in cmath)
long radius { static_cast<long> (sqrt(
static_cast<double>((end.x - start.x)*(end.x - start.x) + (end.y - start.y)*(end.y - start.y)))) };
if (radius < 1L) radius = 1L; // Circle radius must be >= 1
// Define left-top and right-bottom points of rectangle for MM_TEXT mode
m_StartPoint = CPoint { start.x - radius, start.y - radius };
m_BottomRight = CPoint { start.x + radius, start.y + radius };
// Define the enclosing rectangle
m_EnclosingRect = CRect {m_StartPoint.x, m_StartPoint.y, m_BottomRight.x, m_BottomRight.y };
m_EnclosingRect.InflateRect(m_PenWidth, m_PenWidth);
}
因为这些API画图形的时候就是根据这个最外侧矩形来组成的
但是,看孙鑫的视频时也没见他加上这些代码画图啊 ?如果不加有什么后果吗?查了好多的网页没见一个说明白的,头大