From 7c0b972a953dc505fedea5b2d8e175148e94e392 Mon Sep 17 00:00:00 2001 From: Peng Xiao Date: Tue, 2 Dec 2014 21:57:18 -0500 Subject: [PATCH] Check if the graph the user draws is planar or not --- drawing/Graph.pde | 4 +++- drawing/drawing.pde | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drawing/Graph.pde b/drawing/Graph.pde index cb8a441..322cb98 100644 --- a/drawing/Graph.pde +++ b/drawing/Graph.pde @@ -15,7 +15,9 @@ class Graph{ for(Vertex i:V){ if(i.E.size()<=min)min=i.E.size(); } - return min==3; + boolean x= (min==3); + boolean y= E.size() <= (3*V.size() -6); + return x&&y; } boolean check3edges_per_vertex(Vertex v){ if(v.E.size()<3) return true; diff --git a/drawing/drawing.pde b/drawing/drawing.pde index 6f862ef..acc1233 100644 --- a/drawing/drawing.pde +++ b/drawing/drawing.pde @@ -1,6 +1,7 @@ import papaya.*; + final int DRAW_NORMAL=1; final int DRAW_DRAG=2; final int DRAW_ANIMATION=3; @@ -129,6 +130,8 @@ class ResetEvent implements ButtonEvent { class TutteDrawEvent implements ButtonEvent { void onclick() { + if (G.ValidGraph()==false) + throw new RuntimeException("Not a valid Graph!"); int l=G.V.size(); ArrayList face=FindFace();