X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=bgl.cpp;h=325617eca59b114fff476833f347eeb3cc718e90;hb=4a1ef2e9fce14d796b3fb10884e177d39d493745;hp=0d1f355323cb9f064281e0079e709f1e55f61d9d;hpb=47850b1d988483f5939b5bdb4a3bd60604f6930c;p=moebius2.git diff --git a/bgl.cpp b/bgl.cpp index 0d1f355..325617e 100644 --- a/bgl.cpp +++ b/bgl.cpp @@ -98,8 +98,8 @@ class OutEdgeIterator : } static int voe_min(int _v) { return (_v & YMASK) ? 2 : 3; } - static int voe_max(int _v) { return (~_v & YMASK) ? V6 : 4; } - static int voe_degree(int _v) { return (_v & YMASK | ~_v & YMASK) ? 4 : V6; } + static int voe_max(int _v) { return (_v & YMASK)==(Y-1) ? V6 : 4; } + static int voe_degree(int _v) { return RIM_VERTEX_P(_v) ? 4 : V6; } }; typedef counting_iterator VertexIterator; @@ -201,14 +201,18 @@ double graph_layout_cost(const Vertices v, const double vertex_areas[N]) { double a1= vertex_areas[v1]; single_source_shortest_paths(v1, edge_weights, vertex_distances); FOR_VERTEX(v2) { + if (v1 == v2) continue; double a2= vertex_areas[v2]; double d2= hypotD2plus(v[v1],v[v2], d2_epsilon); double s= vertex_distances[v2]; - double sd= s / d2; - double sd2= sd*sd; + double s2= s*s + d2_epsilon; + double sd2= s2 / d2; double cost_contrib= a1*a2 * (sd2 - 1) / (d2*d2); - //printf("layout %03x..%03x (a=%g,%g) s=%g d2=%g cost+=%g\n", - // v1,v2, a1,a2, s,d2, cost_contrib); + if (cost_contrib < -1e-4) { + printf("layout %03x..%03x (a=%g,%g) s=%g s2=%g d2=%g sd2=%g" + " cost+=%g\n", v1,v2, a1,a2, s,s2,d2,sd2, cost_contrib); + abort(); + } total_cost += cost_contrib; } }