chiark / gitweb /
attempts to fix 125; really need to combine edge length variation and bending costs
authorIan Jackson <ian@turbine>
Thu, 9 Oct 2008 23:30:13 +0000 (00:30 +0100)
committerIan Jackson <ian@turbine>
Thu, 9 Oct 2008 23:30:13 +0000 (00:30 +0100)
energy.c
minimise.h

index 308aebfa3f890aea945bafc0aa38fc1feb18f9c8..9bd66e31a93e0360c8c9614d0f3760afa6ef3fa8 100644 (file)
--- a/energy.c
+++ b/energy.c
@@ -59,7 +59,21 @@ static const CostContribution costs[]= {
     COST(  1e18,   noncircular_rim_cost)
 #endif
 
-#if XBITS>=5 /* nonsense follows but never mind */
+#if XBITS==5
+#define STOP_EPSILON 1.2e-4
+    COST(  3e7,   line_bending_cost)
+    COST( 10e2,   prop_edge_length_variation_cost)
+    COST( 9.0e3,  rim_proximity_cost) // 5e1 is too much
+                                     // 2.5e1 is too little
+    // 0.2e1 grows compared to previous ?
+    // 0.6e0 shrinks compared to previous ?
+
+//    COST(  1e12,   edge_angle_cost)
+                  #define EDGE_ANGLE_COST_CIRCCIRCRAT (0.5/1.3)
+    COST(  1e18,   noncircular_rim_cost)
+#endif
+
+#if XBITS>=6 /* nonsense follows but never mind */
 #define STOP_EPSILON 1e-6
     COST(  3e5,   line_bending_cost)
     COST( 10e2,   edge_length_variation_cost)
@@ -289,6 +303,32 @@ double edge_length_variation_cost(const Vertices vertices, int section) {
   return cost;
 }
 
+/*---------- proportional edge length variation ----------*/
+
+  /*
+   * Definition:
+   *
+   *    See the diagram above.
+   *                                r
+   *       cost    = ( |PQ| - |QR| )
+   *           Q,e
+   */
+
+double prop_edge_length_variation_cost(const Vertices vertices, int section) {
+  double cost= 0, exponent_r= 2;
+  int q, e,r, eback;
+
+  FOR_EDGE(q,e,r, OUTER) {
+    eback= edge_reverse(q,e);
+    double le= edge_lengths[q][e];
+    double leback= edge_lengths[q][eback];
+    double diff= le - leback;
+    double num= MIN(le, leback);
+    cost += pow(diff / (num + 1e-6), exponent_r);
+  }
+  return cost;
+}
+
 /*---------- rim proximity cost ----------*/
 
 static void find_nearest_oncircle(double oncircle[D3], const double p[D3]) {
index c2e13e7b40fef83169495c5b2754fc91333c90d1..c611b89edf5f3b48ecc15549b7db3bd575724bc4 100644 (file)
@@ -23,6 +23,7 @@ extern const double edge_angle_cost_circcircrat;
 double line_bending_cost(const Vertices vertices, int section);
 double noncircular_rim_cost(const Vertices vertices, int section);
 double edge_length_variation_cost(const Vertices vertices, int section);
+double prop_edge_length_variation_cost(const Vertices vertices, int section);
 double rim_proximity_cost(const Vertices vertices, int section);
 double edge_angle_cost(const Vertices vertices, int section);
 double small_triangles_cost(const Vertices vertices, int section);