some speed improvement with vectorization of distance function, but rectangle does not work :(