@SOAR 2016-10-28 11:51 采纳率: 100%
浏览 1174
已采纳

mfc画图时为什么需要首先计算封闭矩形

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);
}

  • 写回答

2条回答 默认 最新

  • oyljerry 2016-10-28 11:57
    关注

    因为这些API画图形的时候就是根据这个最外侧矩形来组成的

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装