From 2ef2cda0774a32d4c529c00303b2e7a4aa966546 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 4 Jan 2008 02:15:46 +0000 Subject: [PATCH] new energy functions --- energy.c | 27 +++++++++++++++------------ view.c | 5 ++++- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/energy.c b/energy.c index 867330c..b53199e 100644 --- a/energy.c +++ b/energy.c @@ -40,7 +40,7 @@ static double compute_energy(const Vertices vertices) { COST(1e2, edgewise_vertex_displacement_cost(vertices)); // COST(1e0, graph_layout_cost(vertices,vertex_areas)); - COST(1e4, noncircular_rim_cost(vertices)); +// COST(1e4, noncircular_rim_cost(vertices)); if (printing) printf("| total %# e |", energy); @@ -222,7 +222,7 @@ int main(int argc, const char *const *argv) { * * Giving energy contribution: * - * 2 + * 3 * l delta * E = F . -------- * vd, edge PQ vd d @@ -231,7 +231,7 @@ int main(int argc, const char *const *argv) { * (The dimensions of this are those of F_vd.) * * We calculate delta as atan2(|AxB|, A.B) - * where A = RM, B = MS + * where A = PQ, B = QR * * In practice to avoid division by zero we'll add epsilon to d and * |AxB| and the huge energy ought then to be sufficient for the @@ -241,22 +241,25 @@ int main(int argc, const char *const *argv) { double edgewise_vertex_displacement_cost(const Vertices vertices) { static const double axb_epsilon= 1e-6; - int pi,e,qi,ri,si, k; - double m[D3], a[D3], b[D3], axb[D3]; + int pi,e,qi,ri, k; //,si + double a[D3], b[D3], axb[D3]; //m[D3], double total_cost= 0; - FOR_EDGE(pi,e,qi) { - ri= EDGE_END2(pi,(e+1)%V6); if (ri<0) continue; - si= EDGE_END2(pi,(e+5)%V6); if (si<0) continue; + FOR_EDGE(qi,e,ri) { + pi= EDGE_END2(qi,(e+3)%V6); if (pi<0) continue; - K m[k]= (vertices[pi][k] + vertices[qi][k]) * 0.5; - K a[k]= -vertices[ri][k] + m[k]; - K b[k]= -m[k] + vertices[si][k]; +// K m[k]= (vertices[pi][k] + vertices[qi][k]) * 0.5; + K a[k]= -vertices[pi][k] + vertices[qi][k]; + K b[k]= -vertices[qi][k] + vertices[ri][k]; xprod(axb,a,b); double delta= atan2(magnD(axb) + axb_epsilon, dotprod(a,b)); - double cost= delta * delta; + double cost= pow(delta,3); + + if (!e && !(qi & YMASK)) + cost *= 1e3; + total_cost += cost; } return total_cost; diff --git a/view.c b/view.c index d265011..8983f62 100644 --- a/view.c +++ b/view.c @@ -659,7 +659,10 @@ int main(int argc, const char *const *argv) { polls[i].events= wantedevents; r= poll(polls, nxfds+1, motion_deferred ? 0 : 200); - if (r<0) diee("poll"); + if (r<0) { + if (errno==EINTR) continue; + diee("poll"); + } for (i=0; i