- const Vector2 &other_pos=i->second->get_position();
- float dx=other_pos.x-pos.x;
- float dy=other_pos.y-pos.y;
- float d2=dx*dx+dy*dy;
- float d=sqrt(d2);
-
- unsigned other_addr=i->second->get_address();
- unsigned matching_bits=0;
- for(unsigned j=32; (j-- && !((addr^other_addr)>>j));)
- ++matching_bits;
-
- float optimal_dist=100+(24-min(matching_bits, 24U))*12;
- float f=5000.0*(1.0/optimal_dist-1.0/d);
-
- fx+=dx/d*f;
- fy+=dy/d*f;
+ const Vector2 &other_pos = i->second->get_position();
+ float dx = other_pos.x-pos.x;
+ float dy = other_pos.y-pos.y;
+ float d2 = dx*dx+dy*dy;
+ float d = sqrt(d2);
+
+ unsigned matching_bits = addr.common_prefix_length(i->second->get_address());
+
+ float optimal_dist = 100+(24-min(matching_bits, 24U))*12;
+ float f = 5000.0*(1.0/optimal_dist-1.0/d);
+
+ fx += dx/d*f;
+ fy += dy/d*f;