fix the code please: if (scaley0 > 0)
{
    if (y1 > SH) return;
    if (y1 + rect0.height * scaley0 < 0) return;
    if (x1 > SW) return;
    if (x1 + rect0.width * scalex0 < 0) return;
}
else
{
    if (y1 + rect0.height * scaley0 > SH) return;
    if (y1 < 0) return;
    if (x1 + rect0.width * scalex0 > SW) return;
    if (x1 < 0) return;
}