Prevent overlap/edge crosses when moving a vertex
This commit is contained in:
parent
aa21bb9d39
commit
06902c4377
10
gamedata.cpp
10
gamedata.cpp
|
@ -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))
|
||||||
|
|
4
graph.h
4
graph.h
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user