optimize union rect code