fixed minmax, added calc of edge directions