首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

求重绘的矩形区域时,坐标系中坐标的大小比较!多谢!

2012-02-16 
求重绘的矩形区域时,坐标系中坐标的大小比较!!谢谢!!我正在看《深入浅出MFC》,里面有一张是讲:view的重绘的,

求重绘的矩形区域时,坐标系中坐标的大小比较!!谢谢!!
我正在看《深入浅出MFC》,里面有一张是讲:view的重绘的,有这样一段代码,是通过比较x,y坐标的大小,求取重绘的矩形区域:
void   CStroke::FinishStroke()
{
//   Calculate   the   bounding   rectangle.     It 's   needed   for   smart
//   repainting.

if   (m_pointArray.GetSize()==0)
{
m_rectBounding.SetRectEmpty();
return;
}
CPoint   pt   =   m_pointArray[0];
m_rectBounding   =   CRect(pt.x,   pt.y,   pt.x,   pt.y);

for   (int   i=1;   i   <   m_pointArray.GetSize();   i++)
{
    //   If   the   point   lies   outside   of   the   accumulated   bounding
    //   rectangle,   then   inflate   the   bounding   rect   to   include   it.
            pt   =   m_pointArray[i];
            m_rectBounding.left           =   min(m_rectBounding.left,   pt.x);
            m_rectBounding.right         =   max(m_rectBounding.right,   pt.x);
            m_rectBounding.top             =   min(m_rectBounding.top,   pt.y);
            m_rectBounding.bottom       =   max(m_rectBounding.bottom,   pt.y);
}

//   Add   the   pen   width   to   the   bounding   rectangle.     This   is   necessary
//   to   account   for   the   width   of   the   stroke   when   invalidating
//   the   screen.
m_rectBounding.InflateRect(CSize(m_nPenWidth,   m_nPenWidth));
return;
}
它里面对y轴进行比较的时候,是去顶部的最小值,底部的最大值,这样应该是设备坐标系,但是在调用这个函数进行比较时,点坐标已经转化为逻辑坐标存入文件,那这样比较的时候是不是应该用逻辑坐标系的方法进行比较。

设备坐标系是:x轴正向向右,y轴正向向下;
逻辑坐标系是:初始状态时x轴正向向右,y轴正向向上。

但是我将上面的代码中y周比较中的min   和   max换过后,结果是错的。


请问这是怎么回事?     谢谢!!!

[解决办法]
不管是设备坐标还是逻辑坐标,矩形的坐标都是左边小于右边,上边小于下边,即使上、下颠倒。可以用NormalizeRect来规范化矩形坐标。

热点排行