All geometry calculations should be done relative to the viewport (_$viewport) not the "window" object.