Adobe-Runtime-Support icon indicating copy to clipboard operation
Adobe-Runtime-Support copied to clipboard

Rectangle.unionToOutput() inconsistent with Rectangle.union()

Open esidegallery opened this issue 3 years ago • 5 comments

Problem Description

The new Rectangle.unionToOutput() method yields unexpected results inconsistent with an equivalent operation using Rectangle.union(), depending on how rectangles are unified.

This has been confirmed in SDK 33.1.1.889 running on Windows 10.

Steps to Reproduce

The following snippet exhibits the issue:

var topLeft:Rectangle = new Rectangle(0, 0, 1, 1);
var bottomRight:Rectangle = new Rectangle(99, 99, 1, 1);

var unionRect:Rectangle = new Rectangle();
var unionToOutputRect:Rectangle = new Rectangle();

addRect(bottomRight);
addRect(topLeft);

function addRect(rect:Rectangle):void
{
    unionToOutputRect.unionToOutput(rect, unionToOutputRect);
    unionRect = unionRect.union(rect);
    trace("Add", rect, "union:", unionRect, "unionToOutput:", unionToOutputRect, "equal:", unionRect.equals(unionToOutputRect));
}

The resulting output is:

Add (x=99, y=99, w=1, h=1) union: (x=99, y=99, w=1, h=1) unionToOutput: (x=99, y=99, w=1, h=1) equal: true
Add (x=0, y=0, w=1, h=1) union: (x=0, y=0, w=100, h=100) unionToOutput: (x=0, y=0, w=1, h=1) equal: false

With bottomRight & topLeft unified, the resulting rectangle should be (x=0, y=0, w=100, h=100), but unionToOutput() is giving (x=0, y=0, w=1, h=1)

esidegallery avatar Jul 06 '22 14:07 esidegallery

Thanks for spotting this .. it's just caused by the fact that the source and output rectangles are the same, so when we're modifying the output values for x/y, we change what we then look at to make the output width/height values. There is likely a similar problem with the intersection function, but they're easily fixed by using local vars whilst doing the calculations..

thanks

ajwfrost avatar Jul 07 '22 05:07 ajwfrost

I figured that's probably the reason. Thanks Andrew!

esidegallery avatar Jul 07 '22 11:07 esidegallery

I also just encountered this exact same nasty issue.

Fixing it or at least throwing an ArgumentError + documenting it would prevent other developers from tearing their hair out 😅

Adolio avatar Jan 05 '24 22:01 Adolio

Hi @Adolio - this was fixed in 33.1.1.929...

Oh .. okay, so this fix appears to have been overwritten when we had been merging in some updated documentation :-( sorry, that really shouldn't have happened! So, the bug is still there in the latest build. Will get this all sorted out and merged properly.

ajwfrost avatar Jan 08 '24 08:01 ajwfrost

Thanks a lot @ajwfrost!

Happy new year to you & your team 🎉

Adolio avatar Jan 08 '24 09:01 Adolio