let mod_squared_distance modulus x y = let diff = mod_float (x -. y +. modulus) modulus in let diff2 = modulus -. diff in min (diff *. diff) (diff2 *. diff2)