added static_cast to remove compiler warning on float to int conversion