Skip to content

PathF.Bounds returns too big boxes #15151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
RawScape opened this issue May 18, 2023 · 4 comments · May be fixed by #29583
Open

PathF.Bounds returns too big boxes #15151

RawScape opened this issue May 18, 2023 · 4 comments · May be fixed by #29583
Assignees
Labels
area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing platform/windows s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@RawScape
Copy link

Description

Creating an oval using PathF and then requesting a Bounding Box for it leads to a far too big box.

See "Steps to Reproduce" for details.

Steps to Reproduce

The following code shows the problem.

The result of running it is:
{X=-1.783905 Y=-1.783905 Width=201.77824 Height=201.7839}
{X=0.0015447102 Y=0.0049879625 Width=1089.3208 Height=1205.8179}
{X=-381.5282 Y=-575.8281 Width=1470.8506 Height=1781.651}

the first one is a bit off but still acceptable while I would expect the last 2 to be in the limits:
{X=0 Y=0 Width=444 Height=648}

Downgrading to 7.0.86 or 6.0.501 doesn't change the outcome.

using Microsoft.Maui.Graphics;

namespace PathFBug;

internal static class Program
{
    private static void Main()
    {
        float n = (float)(4 * (Math.Sqrt(2) - 1) / 3);
        var path1 = GetOval(100, 100, 100, 100, n * 100, n * 100, 0);
        var path2 = GetOval(222, 324, 222, 324, 167, 146, 0);
        var path3 = GetOval(222, 324, 222, 324, 167, 146, 1);

        Console.WriteLine(path1.Bounds);
        Console.WriteLine(path2.Bounds);
        Console.WriteLine(path3.Bounds);
    }
    
    private static PathF GetOval(float x, float y, float radiusX, float radiusY, float cDx, float cDy, float deviation)
    {
        PathF path = new PathF();
        
        float x1 = 0;
        float xm = radiusX;
        float x2 = radiusX * 2;
        
        float y1 = 0;
        float ym = radiusY;
        float y2 = radiusY * 2;

        x -= radiusX;
        y -= radiusY;

        float cX1 = xm - cDx;
        float cX2 = xm + cDx;
        
        float cY1 = ym - cDy;
        float cY2 = ym + cDy;

        path.MoveTo(x + xm, y + y2);
        path.CurveTo(x + cX1 + deviation * 2, y + y2, x + x1, y + cY2, x + x1, y + ym);
        path.CurveTo(x + x1, y + cY1, x + cX1 - deviation, y + y1, x + xm, y + y1);
        path.CurveTo(x + cX2, y + y1, x + x2, y + cY1, x + x2, y + ym);
        path.CurveTo(x + x2, y + cY2, x + cX2, y + y2, x + xm, y + y2);
        path.Close();

        return path;
    }
}

Drawing the PathF for the parameters of path3 looks like this:
Oval

Link to public reproduction project repository

https://github.com/RawScape/PathFBug

Version with bug

7.0.49

Last version that worked well

6.0

Affected platforms

Windows

Affected platform versions

Windows 11 Pro 22H2 22621.1702 / net7.0

Did you find any workaround?

No

Relevant log output

-
@RawScape RawScape added the t/bug Something isn't working label May 18, 2023
@Eilon Eilon added the area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing label May 18, 2023
@mattleibow
Copy link
Member

I wonder if the bounds calculation is including the control points for the curves. I saw this before in skia and they added a tight bounds. (the skia observation is unrelated but may ring bells)

@mattleibow mattleibow added this to the Backlog milestone May 19, 2023
@ghost
Copy link

ghost commented May 19, 2023

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

@RawScape
Copy link
Author

RawScape commented May 19, 2023

Sorry about the wrong version information. The fields seem to have been reset before the submit.
This bug is observed in the latest preview (8.0.0-preview.4.8.333) and exists in all previous versions.

@mattleibow : Well all the control points themselves are in the bounds created by the regular points and they don't affect the path in a way that would increase the bounds.

@jaosnz-rep
Copy link

Verified this issue with Visual Studio Enterprise 17.9.0 Preview 3. Can repro on windows platforms with sample project.
https://github.com/RawScape/PathFBug

@jaosnz-rep jaosnz-rep added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jan 23, 2024
@Copilot Copilot AI linked a pull request May 19, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing platform/windows s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants