Microsoft.Maui.Graphics icon indicating copy to clipboard operation
Microsoft.Maui.Graphics copied to clipboard

ScalingCanvas - Path is scaled only with ScaleX

Open mgierlasinski opened this issue 3 years ago • 2 comments

Path operations: DrawPath, FillPath, ClipPath are only using Scale X for transformation, Scale Y is ignored:

var scaledPath = path.AsScaledPath(_scaleX);

Method AsScaledPath is creating transform as uniform scale:

var transform = Matrix3x2.CreateScale(scale);
scaledPath.Transform(transform);

mgierlasinski avatar Feb 05 '22 15:02 mgierlasinski

Hi @mgierlasinski, thanks for noting this! I think I resolved this issue in #305 and I'm looking forward to feedback over there.

Adding details to this issue, the problem is that ScalingCanvas methods DrawPath, FillPath, and ClipPath only use the X scale, and that calling AsScaledPath() with a single value results in that scale being applied in both X and Y directions

https://github.com/dotnet/Microsoft.Maui.Graphics/blob/8b0dbfcb0e6a3b80f025e33412911aa5e2a53bc7/src/Microsoft.Maui.Graphics/ScalingCanvas.cs#L176-L180

https://github.com/dotnet/Microsoft.Maui.Graphics/blob/8b0dbfcb0e6a3b80f025e33412911aa5e2a53bc7/src/Microsoft.Maui.Graphics/ScalingCanvas.cs#L182-L186

https://github.com/dotnet/Microsoft.Maui.Graphics/blob/8b0dbfcb0e6a3b80f025e33412911aa5e2a53bc7/src/Microsoft.Maui.Graphics/ScalingCanvas.cs#L188-L192

The reason for this limitation is because AsScaledPath() only accepts a single number and scales both X and Y by that value:

https://github.com/dotnet/Microsoft.Maui.Graphics/blob/5410757e44e4c6a40c18691dc3c6b1e15a6897a9/src/Microsoft.Maui.Graphics/PathExtensions.cs#L66-L74

https://docs.microsoft.com/en-us/dotnet/api/system.numerics.matrix3x2.createscale

I resolve this in #305 by adding an overload that accepts distinct X and Y scales, then updating all the methods above to use it.

swharden avatar Feb 05 '22 17:02 swharden

Hi @swharden, that was blazing fast :astonished: Thanks for that, that's exactly what I needed :blush:

mgierlasinski avatar Feb 05 '22 18:02 mgierlasinski