Refactored so that both rect and cube use cube[] parameter