📄 gpoint.cpp
字号:
//--------------------------------------------------
// Desc: POINT and RECT
// Author: artsylee/2006.8.25
//--------------------------------------------------
#include "../stdafx.h"
#include "GPoint.h"
/*
float InvSqrt(float x)
{
union
{
int intPart;
float floatPart;
} convertor;
convertor.floatPart = x;
convertor.intPart = 0x5f3759df - (convertor.intPart >> 1);
return convertor.floatPart*(1.5f - 0.4999f*x*convertor.floatPart*convertor.floatPart);
}*/
// ---------------------------------------------------------------
// GPoint members (should use inline functions)
// ---------------------------------------------------------------
ASINLINE void GPoint::Offset(int xOffset, int yOffset)
{
x += xOffset;
y += yOffset;
}
ASINLINE void GPoint::Offset(POINT point)
{
x += point.x;
y += point.y;
}
ASINLINE void GPoint::Offset(SIZE size)
{
x += size.cx;
y += size.cy;
}
ASINLINE bool GPoint::operator==(POINT const &pt) const
{
return (x == pt.x && y == pt.y);
}
ASINLINE bool GPoint::operator!=(POINT const &pt) const
{
return (x != pt.x || y != pt.y);
}
ASINLINE GPoint GPoint::operator+()
{
return GPoint(x, y);
}
ASINLINE GPoint GPoint::operator-()
{
return GPoint(-x, -y);
}
ASINLINE GPoint GPoint::operator+(POINT const &pt)
{
return GPoint(x + pt.x, y + pt.y);
}
ASINLINE GPoint GPoint::operator-(POINT const &pt)
{
return GPoint(x - pt.x, y - pt.y);
}
ASINLINE GPoint GPoint::operator*(int i)
{
return GPoint(x * i, y * i);
}
ASINLINE GPoint GPoint::operator/(int i)
{
if(i == 0)
return *this;
else
return GPoint(x / i, y / i);
}
ASINLINE GPoint GPoint::operator%(int i)
{
return GPoint(x % i, y % i);
}
ASINLINE GPoint GPoint::operator<<(int i)
{
return GPoint(x << i, y << i);
}
ASINLINE GPoint GPoint::operator>>(int i)
{
return GPoint(x >> i, y >> i);
}
/*
float GPoint::Angle(GPoint *v)
{
if(v)
{
GPoint s=*this, t=*v;
s.Normalize();
t.Normalize();
return acosf(s.Dot(&t));
}
else return atan2f(y, x);
}
POINT* GPoint::Rotate(float a)
{
POINT v;
v.x = x*cosf(a) - y*sinf(a);
v.y = x*sinf(a) + y*cosf(a);
x=v.x; y=v.y;
return this;
}
*/
// ---------------------------------------------------------------
// GRect members (should use inline functions)
// ---------------------------------------------------------------
ASINLINE int GRect::Width() const
{
return right - left;
}
ASINLINE int GRect::Height() const
{
return bottom - top;
}
ASINLINE void GRect::ZeroRect()
{
left = right = top = bottom = 0;
}
ASINLINE void GRect::NormalizeRect()
{
int nTemp;
if(left > right)
{
nTemp = left;
left = right;
right = nTemp;
}
if(top > bottom)
{
nTemp = top;
top = bottom;
bottom = nTemp;
}
}
ASINLINE void GRect::SetRect(int x1, int y1, int x2, int y2)
{
left = x1;
right = x2;
top = y1;
bottom = y2;
}
ASINLINE void GRect::SetRect(POINT topLeft, POINT bottomRight)
{
left = topLeft.x;
top = topLeft.y;
right = bottomRight.x;
bottom = bottomRight.y;
}
ASINLINE void GRect::SetRectWH(int x1, int y1, int x2, int y2)
{
left = x1;
right = x2 + x1;
top = y1;
bottom = y2 + y1;
}
ASINLINE GPoint &GRect::LeftTop() const
{
return *((GPoint*)this);
}
ASINLINE GPoint &GRect::RightBottom() const
{
return *((GPoint*)this+1);
}
ASINLINE GPoint GRect::CenterPoint() const
{
return GPoint((left+right)/2, (top+bottom)/2);
}
ASINLINE bool GRect::PtInRect(POINT point) const
{
return point.x>=left && point.x<right && point.y>=top && point.y<bottom;
}
ASINLINE void GRect::InflateRect(int x, int y)
{
::InflateRect(this, x, y);
}
ASINLINE void GRect::InflateRect(POINT pt)
{
::InflateRect(this, pt.x, pt.y);
}
ASINLINE void GRect::InflateRect(int l, int t, int r, int b)
{
left -= l;
top -= t;
right += r;
bottom += b;
}
ASINLINE void GRect::DeflateRect(int x, int y)
{
::InflateRect(this, -x, -y);
}
ASINLINE void GRect::DeflateRect(POINT pt)
{
::InflateRect(this, -pt.x, -pt.y);
}
ASINLINE void GRect::DeflateRect(int l, int t, int r, int b)
{
left += l;
top += t;
right -= r;
bottom -= b;
}
ASINLINE void GRect::OffsetRect(int x, int y)
{
::OffsetRect(this, x, y);
}
ASINLINE void GRect::OffsetRect(POINT pt)
{
::OffsetRect(this, pt.x, pt.y);
}
ASINLINE void GRect::make_extern(RECT const &rect)
{
if(left > rect.left) left = rect.left;
if(top > rect.top) top = rect.top;
if(right < rect.right) right = rect.right;
if(bottom < rect.bottom) bottom = rect.bottom;
}
ASINLINE void GRect::make_clipper(RECT const &rect)
{
if(left < rect.left) left = rect.left;
if(top < rect.top) top = rect.top;
if(right > rect.right) right = rect.right;
if(bottom > rect.bottom) bottom = rect.bottom;
}
ASINLINE void GRect::operator=(const RECT &srcRect)
{
::CopyRect(this, &srcRect);
}
ASINLINE bool GRect::operator==(const RECT &rc)
{
return left==rc.left && right==rc.right && top==rc.top && bottom==rc.bottom;
}
ASINLINE bool GRect::operator!=(const RECT &rc)
{
return left!=rc.left || right!=rc.right || top!=rc.top || bottom!=rc.bottom;
}
ASINLINE void GRect::operator+=(POINT point)
{
::OffsetRect(this, point.x, point.y);
}
ASINLINE void GRect::operator-=(POINT point)
{
::OffsetRect(this, -point.x, -point.y);
}
ASINLINE GRect GRect::operator+(POINT point)
{
return GRect(left+point.x, top+point.y, right+point.x, bottom+point.y);
}
ASINLINE GRect GRect::operator-(POINT point)
{
return GRect(left-point.x, top-point.y, right-point.x, bottom-point.y);
}
// END of this file 2006_8_29
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -