Prevent overlap/edge crosses when moving a vertex

This commit is contained in:
Anna Rose 2011-07-04 02:52:12 -04:00
parent aa21bb9d39
commit 06902c4377
2 changed files with 12 additions and 2 deletions

View File

@ -101,6 +101,16 @@ void GameData::handle_click(int x, int y)
if (current == NULL) return; if (current == NULL) return;
int dist = MathUtils::distance(current->x, current->y, current->z, int dist = MathUtils::distance(current->x, current->y, current->z,
x, y, 0); x, y, 0);
Vertex* temp = new Vertex(x, y, 0, NODE_RADIUS);
if (crosses_edge(current, temp) ||
vertex_would_overlap(x, y, 0, NODE_RADIUS))
{
delete temp;
return;
}
delete temp;
if (dist <= get_range()) if (dist <= get_range())
{ {
if (turn->spend_energy(dist)) if (turn->spend_energy(dist))

View File

@ -42,10 +42,10 @@ class Graph
protected: protected:
list<Vertex*> vertices; list<Vertex*> vertices;
bool crosses_edge(Vertex* a, Vertex* b);
bool vertex_would_overlap(int x, int y, int z, int r);
private: private:
bool vertex_would_overlap(int x, int y, int z, int r);
bool crosses_edge(Vertex* a, Vertex* b);
bool planar; bool planar;
}; };