 #define THREADS _THREADS_
 #define PROX _PROX_
+
+__device__ float dist(const float *a, const float *b, const int ii, const int jj){
+    return sqrt(powf(a[ii]-b[jj], 2.0f)+powf(a[ii+1]-b[jj+1], 2.0f));
+}
 
 __global__ void step(
   const int n,

      zk = a*nz+b;
      for (int k=0;k<zone_num[zk];k++){
        jj = 2*zone_node[zk*zone_leap+k];
        total_count += 1;
        dx = xy[ii] - xy[jj];
        dy = xy[ii+1] - xy[jj+1];
        dd = sqrt(dx*dx + dy*dy);
        if (dd<outer_influence_rad && dd>0.0f){
          proximity[cand_count] = jj/2;
          cand_count += 1;

        linked = false;
        break;
      }
      if (dd>max(dist(xy, xy, aa, ii), dist(xy, xy, jj, aa))){
        linked = false;
        break;
      }
    }

    dx /= dd;
    dy /= dd;

    mx += xy[jj];
    my += xy[jj+1];

    if (linked){
      links[10*i+link_count] = jj/2;
      link_count += 1;
      if (dd>spring_attract_rad){
        sx += -dx*spring_stp;
        sy += -dy*spring_stp;
      }
      else if(dd<spring_reject_rad){
        sx += dx*spring_stp;
        sy += dy*spring_stp;
      }
    }
    else{ // unlinked
      sx += dx*reject_stp;
      sy += dy*reject_stp;
    }
  }

