Skip to content

fix: Rectangle.Intersect - #751

Merged
flibitijibibo merged 1 commit into
FNA-XNA:masterfrom
7aGiven:Rectengle
Sep 8, 2026
Merged

fix: Rectangle.Intersect#751
flibitijibibo merged 1 commit into
FNA-XNA:masterfrom
7aGiven:Rectengle

Conversation

@7aGiven

@7aGiven 7aGiven commented Sep 8, 2026

Copy link
Copy Markdown
Contributor
  • I confirm that I am the author of this code and release it to the FNA project under the Ms-PL license. This contribution does not contain code from other sources, including code generated by a Large Language Model ("AI").

Test Case:

using Microsoft.Xna.Framework;
using System;

namespace RenderTargetTest
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var r1 = new Rectangle(0, 831, -2, 514);
            var r2 = new Rectangle(-5, 831, 1497, 2520);

            Rectangle r;
            Rectangle.Intersect(ref r1, ref r2, out r);

            Console.WriteLine(r);
        }
    }
}

XNA output:

{X:0 Y:0 Width:0 Height:0}

FNA output:

{X:0 Y:831 Width:-2 Height:514}

@7aGiven

7aGiven commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

link #680

@7aGiven

7aGiven commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

For ensure all is inline

.NET 8.0.30 (8.0.30, 8.0.3026.36720), X64 RyuJIT x86-64-v3 (Job: DefaultJob)

; Microsoft.Xna.Framework.Rectangle.Intersect1(Microsoft.Xna.Framework.Rectangle ByRef, Microsoft.Xna.Framework.Rectangle ByRef, Microsoft.Xna.Framework.Rectangle ByRef)
       push      rsi
       push      rbx
       vzeroupper
       mov       eax,[rcx]
       mov       r10d,eax
       add       r10d,[rcx+8]
       mov       r9d,[rdx]
       mov       r11d,r9d
       add       r11d,[rdx+8]
       cmp       r10d,r11d
       cmovg     r10d,r11d
       mov       r11d,[rcx+4]
       mov       ebx,r11d
       add       ebx,[rcx+0C]
       mov       ecx,[rdx+4]
       mov       esi,ecx
       add       esi,[rdx+0C]
       cmp       ebx,esi
       cmovg     ebx,esi
       cmp       eax,r9d
       cmovl     eax,r9d
       cmp       r11d,ecx
       cmovl     r11d,ecx
       cmp       eax,r10d
       jge       short M01_L00
       cmp       r11d,ebx
       jge       short M01_L00
       sub       r10d,eax
       sub       ebx,r11d
       mov       [r8],eax
       mov       [r8+4],r11d
       mov       [r8+8],r10d
       mov       [r8+0C],ebx
       pop       rbx
       pop       rsi
       ret
M01_L00:
       vxorps    xmm0,xmm0,xmm0
       vmovdqu   xmmword ptr [r8],xmm0
       pop       rbx
       pop       rsi
       ret
; Total bytes of code 114

@flibitijibibo
flibitijibibo merged commit 8a6285d into FNA-XNA:master Sep 8, 2026
1 check passed
@7aGiven
7aGiven deleted the Rectengle branch September 8, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants