- /*
- *
- *
- *
- * Q `-_
- * / | `-_
- * R' - _ _ _/_ | `-.
- * . / M - - - - - S
- * . / | _,-'
- * . / | _,-'
- * . / , P '
- * . / ,-'
- * . /,-'
- * . /'
- * R
- *
- *
- *
- * Find R', the `expected' location of R, by
- * reflecting S in M (the midpoint of QP).
- *
- * Let 2d = |RR'|
- * b = |PQ|
- * l = |RS|
- *
- * Giving energy contribution:
- *
- * 2
- * b d
- * E = F . ----
- * vd, edge PQ vd 3
- * l
- *
- * (The dimensions of this are those of F_vd.)
- *
- * By symmetry, this calculation gives the same answer with R and S
- * exchanged. Looking at the projection in the RMS plane:
- *
- *
- * S'
- * ,'
- * ,'
- * R' ,' 2d" = |SS'| = |RR'| = 2d
- * `-._ ,'
- * `-._ ,' By congruent triangles,
- * ` M with M' = midpoint of RS,
- * ,' `-._ |MM'| = |RR'|/2 = d
- * ,' `-._
- * ,' ` S So use
- * ,' M' _ , - ' d = |MM'|
- * ,' _ , - '
- * R - '
- *
- * We choose this value for l (rather than |RM|+|MS|, say, or |RM|)
- * because we want this symmetry and because we're happy to punish
- * bending more than uneveness in the metric.
- *
- * In practice to avoid division by zero we'll add epsilon to l^3
- * and the huge energy ought then to be sufficient for the model to
- * avoid being close to R=S.
- */
+double rim_proximity_cost(const Vertices vertices) {
+ double oncircle[3], cost=0;
+ int v;
+
+ FOR_VERTEX(v) {
+ int y= v >> YSHIFT;
+ int nominal_edge_distance= y <= Y/2 ? y : Y-1-y;
+ if (nominal_edge_distance==0) continue;
+
+ find_nearest_oncircle(oncircle, vertices[v]);