diff --git a/torchvision/transforms/v2/functional/_geometry.py b/torchvision/transforms/v2/functional/_geometry.py index 70b4bc8d845..773208816af 100644 --- a/torchvision/transforms/v2/functional/_geometry.py +++ b/torchvision/transforms/v2/functional/_geometry.py @@ -604,14 +604,15 @@ def _compute_affine_output_size_python(matrix: List[float], w: int, h: int) -> T min_val_y = min(new_pts_y) + half_h max_val_y = max(new_pts_y) + half_h - # Truncate precision to 1e-4 to avoid ceil of Xe-15 to 1.0 + # Truncate precision to 1e-4 to avoid ceil of Xe-15 to 1.0 instead of 0.0 + # Adding +1 in int(min_val * inv_tol + 1) to avoid floor of X.9999 to X instead of X+1 tol = 1e-4 inv_tol = 1.0 / tol cmax_x = math.ceil(int(max_val_x * inv_tol) * tol) cmax_y = math.ceil(int(max_val_y * inv_tol) * tol) - cmin_x = math.floor(int(min_val_x * inv_tol) * tol) - cmin_y = math.floor(int(min_val_y * inv_tol) * tol) + cmin_x = math.floor(int(min_val_x * inv_tol + 1) * tol) + cmin_y = math.floor(int(min_val_y * inv_tol + 1) * tol) size_x = cmax_x - cmin_x size_y = cmax_y - cmin_y