add generic polygonal algorithm and function