Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Быстрый алгоритм разделения и слияния при помощи мостиков / source / ConvexHull_1 / TPolygon
.cpp// TPolygon.cpp: implementation of the TPolygon class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ConvexHull.h"
#include "TPolygon.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
TPolygon::TPolygon(Vertex* v):_v(v)
{
resize();
}
void TPolygon::Update(Vertex *v)
{
// delete this;
_v = v;
resize();
}
TPolygon::~TPolygon()
{
/* if (_v) {
Vertex *w = _v->cw();
while (_v != w) {
delete w->remove();
w = _v->cw();
}
delete _v;
}
*/
}
Vertex* TPolygon::setV(Vertex* v)
{
return _v = v;
}
Vertex* TPolygon::insert(TPoint& p)
{
p.used = TRUE;
if (_size++ == 0)
_v = new Vertex(p);
else
_v = _v->insert(new Vertex(p));
return _v;
}
TPolygon* TPolygon::split(Vertex* b)
{
Vertex *bp = _v->split(b);
resize();
return new TPolygon(bp);
}
void TPolygon::split_ver2(Vertex* b)
{
Vertex *bp = _v->split(b);
resize();
}
void TPolygon::resize(void)
{
if (_v == NULL)
_size = 0;
else {
Vertex *v = _v->cw();
for (_size = 1; v != _v; ++_size, v = v->cw());
}
}
TPolygon::TPolygon(void):_v(NULL), _size(0)
{
}
Vertex* TPolygon::v(void)
{
_v->used = TRUE;
return _v;
}
Vertex* TPolygon::neighbor(int rotation)
{
return _v->neighbor(rotation);
}
Vertex* TPolygon::advance(int rotation)
{
return _v = _v->neighbor(rotation);
}
int TPolygon::size(void)
{
return _size;
}
TPoint TPolygon::point(void)
{
return _v->point();
}
TPolygon::TPolygon(TPolygon& p)
{
_size = p._size;
if (_size == 0)
_v = NULL;
else {
_v = new Vertex(p.point());
for (int i = 1; i < _size; i++){
p.advance(CLOCKWISE);
_v = _v->insert(new Vertex(p.point()));
}
p.advance(CLOCKWISE);
_v = _v->cw();
}
}
int TPolygon::GetType(void)
{
return G_POLYGON;
}
void TPolygon::Destroy()
{
if (_v) {
Vertex *w = _v->cw();
while (_v != w) {
delete w->remove();
w = _v->cw();
}
delete _v;
}
delete this;
}
Соседние файлы в папке ConvexHull_1