Moved polygon helper functions into polygon.js