Skip to content
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

Edge case in Rect.Intersect #15075

Open
grokys opened this issue Mar 21, 2024 · 1 comment
Open

Edge case in Rect.Intersect #15075

grokys opened this issue Mar 21, 2024 · 1 comment
Labels

Comments

@grokys
Copy link
Member

grokys commented Mar 21, 2024

Describe the bug

Calling Rect.Intersect with a rect that has a width or height (but not both) of 0 erroneously results in an empty rect.

To Reproduce

[Fact]
public void Intersect_Should_Handle_Height_0()
{
    var r1 = new Rect(0, 0, 100, 0);
    var r2 = new Rect(0, 0, 50, 0);
    var result = r1.Intersect(r2);

    Assert.Equal(new Rect(0, 0, 50, 0), result);
}

[Fact]
public void Intersect_Should_Handle_Width_0()
{
    var r1 = new Rect(0, 0, 0, 100);
    var r2 = new Rect(0, 0, 0, 50);
    var result = r1.Intersect(r2);

    Assert.Equal(new Rect(0, 0, 0, 50), result);
}

Both fail because Intersect returns an empty rect.

Expected behavior

Should return a Rect with the intersection of the 0 width/height rect. Tested with WPF and this works correctly.

Avalonia version

all

OS

No response

Additional context

The code for Rect.Intersect was taken from SharpDX which also has this bug:

https://github.com/sharpdx/SharpDX/blob/master/Source/SharpDX.Mathematics/RectangleF.cs#L364-L378

Looks like the condition should use >= instead of >

@grokys grokys added the bug label Mar 21, 2024
@kekekeks
Copy link
Member

Note that unlike Avalonia WPF treats zero-sized rects as non-empty. We should probably be doing the same.

I've been slowly replacing Rect with Rect? in relevant places of the rendering code to express Rect.Empty semantics from WPF.

grokys added a commit to AvaloniaUI/Avalonia.Controls.TreeDataGrid that referenced this issue Mar 22, 2024
AvaloniaUI/Avalonia#15075 breaks a test I'm currently writing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants