Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Быстрый алгоритм разделения и слияния при помощи мостиков / source / ConvexHull / TPoint
.cpp// TPoint.cpp: implementation of the TPoint class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ConvexHull.h"
#include "TPoint.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#include <math.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
TPoint::TPoint(double _x, double _y):x(_x),y(_y)
{
used = FALSE;
}
TPoint::~TPoint()
{
}
int TPoint::classify(TPoint & p0, TPoint & p1)
{
TPoint p2 = *this;
TPoint a = p1 - p0;
TPoint b = p2 - p0;
double sa = a.x * b.y - b.x * a.y;
if (sa > 0.0)
return LEFT;
if (sa < 0.0)
return RIGHT;
if ((a.x * b.x < 0.0) || (a.y * b.y < 0.0))
return BEHIND;
if (a.length() < b.length())
return BEYOND;
if (p0==p2)//(p0 == p2)
return ORIGIN;
if (p1==p2)//(p1 == p2)
return DESTINATION;
return BETWEEN;
}
TPoint TPoint::operator+(TPoint& p)
{
return TPoint(x + p.x, y + p.y);
}
TPoint TPoint::operator-(TPoint& p)
{
return TPoint(x - p.x, y - p.y);
}
TPoint operator*(double s, TPoint& p)
{
return TPoint(s * p.x, s * p.y);
}
double TPoint::operator[](int i)
{
return (i == 0) ? x : y;
}
int TPoint::operator==(TPoint& p)
{
return(x == p.x) && (y == p.y);
}
int TPoint::operator!=(TPoint& p)
{
return !(*this == p);
}
int TPoint::operator<(TPoint& p)
{
return ((x < p.x) || ((x==p.x) && (y < p.y)));
}
int TPoint::operator>(TPoint& p)
{
return ((x > p.x) || ((x==p.x) && (y > p.y)));
}
double TPoint::length(void)
{
double tmp = sqrt(x*x + y*y);
return tmp;//sqrt(x*x + y*y);
}
int TPoint::GetType(void)
{
return G_POINT;
}
Соседние файлы в папке ConvexHull