一、目的
MFC提供的CPoint和CSize很好用,实现了各种构造函数和运算符,但没提供浮点数版本,这对于一些不以像素为单元的图像处理带来了很大的不便,在此,提供这两个类的浮点数版本。
二、代码实现
1、 代码结构:基本与CPoint和CSize一致,成员名称也一样,重载运算符,提供加减乘除法操作;
2、 源码
#pragma once
/*************************************************
Copyright: mlizhi.com
Author: Juncheng Lin
Date: 2018-01-05
Description:CPoint和CSize的浮点数版本
**************************************************/
#include <ocidl.h>
template<typename T>
inline int Round(T f)
{
return f < 0? f - 0.5f: f + 0.5f;
}
/**
类名: CPointF
功能: 提供浮点坐标点的与CPoint相似的运算符操作
*/
class CPointF :
public tagPOINTF
{
public:
CPointF(FLOAT _x = 0, FLOAT _y = 0)
{
x = _x;
y = _y;
}
CPointF(const POINTF &pt)
{
x = pt.x;
y =