3 Replies Latest reply on Oct 29, 2008 2:10 PM by fazstp

# Union method not working with 0 area rects?

I need a fast method for deriving the rect defined by two points. I’ve done this before using min/max comparisons for each side but I thought the following would be an incredibly simple one-liner to produce the same result, problem is it always returns rect(0,0,0,0). Is there a bug in the union method or am I overlooking something?

pointA = some point
pointB = some point

myRect = rect(pointA.locH,pointA.locV,pointA.locH,pointA.locV).union(rect(pointB.locH,pointB.locV, pointB.locH,pointB.locV))
• ###### 1. Re: Union method not working with 0 area rects?
Applied CD wrote:
> I need a fast method for deriving the rect defined by two points.
> I?ve done this before using min/max comparisons for each side but I
> thought the following would be an incredibly simple one-liner to
> produce the same result, problem is it always returns rect(0,0,0,0).
> Is there a bug in the union method or am I overlooking something?
>
> pointA = some point
> pointB = some point
>
> myRect =
> rect(pointA.locH,pointA.locV,pointA.locH,pointA.locV).union(rect(pointB.locH,poi
> ntB.locV,pointB.locH,pointB.locV))

Union: "returns the smallest rectangle that encloses the two *rectangles*
rect1 and rect2."

Go with your min/max method: it will take next-to-no-time. Assuming that
what you need the rect for actually requires the rect to be "right-way-up".

Andrew

• ###### 2. Re: Union method not working with 0 area rects?
Thanks Andrew, I did end up using a four line min/max solution, works fast enough.
• ###### 3. Re: Union method not working with 0 area rects?
You could still make it one line;

myRect = rect( [pointA[1], pointB[1]].min(), [pointA[2], pointB[2]].min(), [pointA[1], pointB[1]].max(), [pointA[2], pointB[2]].max() )