Optimized code for positioning the discrete cubes.