Skip to content

Rotation of AffineTransform with TransformSpace.Coordinate is off by 1 pixel #3000

@Socolin

Description

@Socolin

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

ImageSharp version

4.0 alpha 46

Other ImageSharp packages and versions

none

Environment (Operating system, version and so on)

Ubuntu 24.04

.NET Framework version

.NET 9

Description

Hello,

Following #2753 I finally found some time to do more test and I found some issues are still present. (Sorry for not testing this sooner)

It's also possible I misunderstood something, let me know if I missed something

Steps to Reproduce

For the following example, I'm starting with an image of a square 4x4 and the repro: Program.cs

Image

✔️ So rotating it 90 degree around the position (3,3) in pixel space, is rotation the square around the center of the pixel (3,3) and it seems to work as expected

img.Mutate(c => c
	.Transform(new AffineTransformBuilder(TransformSpace.Pixel).AppendRotationDegrees(90, new Vector2(3, 3)))
);
Image

✔️ So now if I want to rotate around bottom right corner of the pixel (3, 3), I can achieve this with a rotation in PixelSpace arround (3.5, 3.5) and this works well too now

img.Mutate(c => c
	.Transform(new AffineTransformBuilder(TransformSpace.Pixel).AppendRotationDegrees(90, new Vector2(3, 3)))
);
Image

🔴 And if I want to achieve the same as the first example, using the Coordinate space, I need to rotate around the coordinate (3.5, 3.5).
But it does not get me the expected result

img.Mutate(c => c
	.Transform(new AffineTransformBuilder(TransformSpace.Coordinate).AppendRotationDegrees(90, new Vector2(3.5f, 3.5f)))
);
Image

🔴 And to reproduce the 2nd example, I expect to do the rotation around the coordinate (4, 4)
But this time the pixel are shifted 1 pixel off, but the size of the image is as expected

img.Mutate(c => c
	.Transform(new AffineTransformBuilder(TransformSpace.Coordinate).AppendRotationDegrees(90, new Vector2(4, 4)))
);
Image

So, all seems good with the TransformSpace.Pixel but it seems pixel are not where expected with TransformSpace.Coordinate but the size of the image is as expected in both case

Images

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions