From 06902c437728b06a45763acd51d95a470fc4a283 Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Mon, 4 Jul 2011 02:52:12 -0400 Subject: [PATCH] Prevent overlap/edge crosses when moving a vertex --- gamedata.cpp | 10 ++++++++++ graph.h | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gamedata.cpp b/gamedata.cpp index 4c084d9..1e2c074 100644 --- a/gamedata.cpp +++ b/gamedata.cpp @@ -101,6 +101,16 @@ void GameData::handle_click(int x, int y) if (current == NULL) return; int dist = MathUtils::distance(current->x, current->y, current->z, 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 (turn->spend_energy(dist)) diff --git a/graph.h b/graph.h index 6755451..d1de18f 100644 --- a/graph.h +++ b/graph.h @@ -42,10 +42,10 @@ class Graph protected: list vertices; + bool crosses_edge(Vertex* a, Vertex* b); + bool vertex_would_overlap(int x, int y, int z, int r); private: - bool vertex_would_overlap(int x, int y, int z, int r); - bool crosses_edge(Vertex* a, Vertex* b); bool planar; };