Friday, May 12, 2017

Vertex hashing

Sometimes its desirable to encode a vertex as a single hash.
Using the seeded rands function in a wrapper.


 my_hash=vertex_hash([x,y,z]);

 function  vertex_hash(v) =
 let (
   xseed = round(rnd(1e8, -1e8, round(v.x * 1e6))),
   yseed = round(rnd(1e8, -1e8, xseed + round(v.y * 1e6))),
   zseed = round(rnd(1e8, -1e8, yseed + round(v.z * 1e6))),
   hash  = round(rnd(1e8, -1e8, zseed)))
 hash;

 function rnd(a = 1, b = 0, s = []) = 
  s == [] ? 
   (rands(min(a, b), max(   a, b), 1)[0]) 
  : 
   (rands(min(a, b), max(a, b), 1, s)[0])
  ;