Files
Work/common/POINT.HPP
2024-08-07 09:09:36 -04:00

192 lines
3.5 KiB
C++

#ifndef _COMMON_POINT_HPP_
#define _COMMON_POINT_HPP_
#ifndef _COMMON_WINDOWS_HPP_
#include <common/windows.hpp>
#endif
#ifndef _COMMON_STRING_HPP_
#include <common/string.hpp>
#endif
#ifndef _COMMON_STDIO_HPP_
#include <common/stdio.hpp>
#endif
#if defined(_MSC_VER)
#pragma warning(disable:4244)
#endif
typedef struct COMMONPOINT
{
short x;
short y;
}CommonPoint;
class Point : public COMMONPOINT
{
public:
Point(void);
Point(short x,short y);
Point(const Point &somePoint);
~Point();
short x(void)const;
void x(short newx);
short y(void)const;
void y(short newy);
void setPoint(short x,short y);
BOOL operator==(const Point &somePoint)const;
BOOL operator<(const Point &somePoint)const;
BOOL operator>(const Point &somePoint)const;
Point operator+(const Point &somePoint)const;
Point &operator=(const Point &somePoint);
Point &operator-=(const Point &somePoint);
Point &operator+=(const Point &somePoint);
Point &operator++(void);
Point operator++(int prefixDummy);
Point &operator--(void);
Point operator--(int prefixDummy);
Point midPoint(const Point &somePoint)const;
DWORD dsqr(const Point &somePoint)const;
operator POINT(void)const;
String toString(void)const;
private:
};
inline
Point::Point(void)
{
COMMONPOINT::x=0;
COMMONPOINT::y=0;
}
inline
Point::Point(short x,short y)
{
COMMONPOINT::x=x;
COMMONPOINT::y=y;
}
inline
Point::Point(const Point &somePoint)
{
COMMONPOINT::x=((COMMONPOINT&)somePoint).x;
COMMONPOINT::y=((COMMONPOINT&)somePoint).y;
}
inline
Point::~Point()
{
}
inline
short Point::x(void)const
{
return COMMONPOINT::x;
}
inline
void Point::x(short newx)
{
COMMONPOINT::x=newx;
}
inline
short Point::y(void)const
{
return COMMONPOINT::y;
}
inline
void Point::y(short newy)
{
COMMONPOINT::y=newy;
}
inline
BOOL Point::operator==(const Point &somePoint)const
{
return (COMMONPOINT::x==((COMMONPOINT&)somePoint).x&&COMMONPOINT::y==((COMMONPOINT&)somePoint).y);
}
inline
BOOL Point::operator<(const Point &somePoint)const
{
return (int(x())*int(x())+int(y())*int(y()))<(int(somePoint.x())*int(somePoint.x())+int(somePoint.y())*int(somePoint.y()));
}
inline
BOOL Point::operator>(const Point &somePoint)const
{
return (int(x())*int(x())+int(y())*int(y()))>(int(somePoint.x())*int(somePoint.x())+int(somePoint.y())*int(somePoint.y()));
}
inline
Point &Point::operator=(const Point &somePoint)
{
COMMONPOINT::x=((COMMONPOINT&)somePoint).x;
COMMONPOINT::y=((COMMONPOINT&)somePoint).y;
return *this;
}
inline
Point &Point::operator-=(const Point &somePoint)
{
COMMONPOINT::x-=((COMMONPOINT&)somePoint).x;
COMMONPOINT::y-=((COMMONPOINT&)somePoint).y;
return *this;
}
inline
Point &Point::operator+=(const Point &somePoint)
{
COMMONPOINT::x+=((COMMONPOINT&)somePoint).x;
COMMONPOINT::y+=((COMMONPOINT&)somePoint).y;
return *this;
}
inline
Point &Point::operator++(void)
{
COMMONPOINT::x++;
COMMONPOINT::y++;
return *this;
}
inline
Point::operator POINT(void)const
{
POINT somePoint;
somePoint.x=COMMONPOINT::x;
somePoint.y=COMMONPOINT::y;
return somePoint;
}
inline
Point Point::midPoint(const Point &somePoint)const
{
return Point((((float)x()+(float)somePoint.x())/2.00)+.50,(((float)y()+(float)somePoint.y())/2.00)+.50);
}
inline
void Point::setPoint(short x,short y)
{
COMMONPOINT::x=x;
COMMONPOINT::y=y;
}
inline
DWORD Point::dsqr(const Point &somePoint)const
{
int xDiff(somePoint.x()-x());
int yDiff(somePoint.y()-y());
return (xDiff*xDiff)+(yDiff*yDiff);
}
inline
String Point::toString(void)const
{
String strPoint;
::sprintf(strPoint.str(),"(%d,%d)",x(),y());
return strPoint;
}
#endif