KV_PiGroup: vector of Locations

Das ist ein vector mit KV_PiEleLocs.
Dazu kommen ein paar Methoden, z.B. zur Überprüfung, ob ein Element an
diese Gruppe angrenzt.
This commit is contained in:
Jonny007-MKD 2014-01-05 19:16:02 +01:00
parent 184555aa26
commit 17f4b32239
2 changed files with 87 additions and 0 deletions

62
GDE_3_2008/KV_PiGroup.cpp Normal file
View file

@ -0,0 +1,62 @@
#include "stdafx.h"
#include "KV_PiEleLoc.h"
#include "KV_PiGroup.h"
using namespace std;
bool KV_PiGroup::LiesNextTo(KV_PiEleLoc* &el)
{
for (uint i = 0; i < this->elements.size(); i++)
{
KV_PiEleLoc* elG = this->elements[i];
if (elG->h - el->h == 0 && abs(elG->w - el->w) == 1 ||
elG->w - el->w == 0 && abs(elG->h - el->h) == 1)
return true;
}
return false;
}
void KV_PiGroup::Add(KV_PiEleLoc* &el)
{
this->elements.push_back(el);
}
void KV_PiGroup::MakeCoords()
{
uint x1, x2, y1, y2;
uint X1 = -1, X2 = 0, Y1 = -1, Y2 = 0;
KV_PiEleLoc* loc;
for (uint i = 0; i < this->elements->size(); i++)
{
loc = this->elements[i];
x1 = loc->w * (this->edgeLength + 1) + this->VarY_Length; // Upper coord
x2 = x1 + this->edgeLength; // Lower coord
y1 = loc->h * (this->edgeLength + 1) + this->VarX_Length; // Left coord
y2 = y1 + this->edgeLength; // Right coord
this->X1 = min(this->X1, x1);
this->X2 = max(this->X2, x2);
this->Y1 = min(this->Y1, y1);
this->Y2 = max(this->Y2, y2);
}
this->X1 = X1;
this->X2 = X2;
this->Y1 = Y1;
this->Y2 = Y2;
}
KV_PiEleLoc* KV_PiGroup::operator[](uint &index)
{
return this->elements.at(index);
}
KV_PiEleLoc* KV_PiGroup::at(uint &index)
{
return this->elements.at(index);
}
uint KV_PiGroup::size()
{
return this->elements.size();
}

25
GDE_3_2008/KV_PiGroup.h Normal file
View file

@ -0,0 +1,25 @@
#pragma once
#include "stdafx.h"
#include <vector>
#include "KV_PiEleLoc.h"
using namespace std;
extern uint dimension;
class KV_PiGroup
{
private:
vector<KV_PiEleLoc*> elements;
public:
bool LiesNextTo(KV_PiEleLoc* &el);
void Add(KV_PiEleLoc* &el);
void MakeCoords();
KV_PiEleLoc* operator[](uint &index);
KV_PiEleLoc* at(uint &index);
uint size();
uint X1, X2, Y1, Y2;
};