Refactor triangle and rectangle to take in an array