#areasOutside:

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

#areasOutside:

Rusty-24
Hi.
I've noticed that the result of evaluating #areasOutside: in dolphin
differs from other smalltalks.
For instance, evaluating:
( Rectangle origin: ( 0 @ 200 ) extent: ( 800 @ 600 ) ) areasOutside: (
Rectangle origin: ( 0 @ 0 ) extent: ( 267 @ 200 ) )

returns:
an OrderedCollection(0@200 corner: 800@800 267@200 corner: 800@200)

when in other flavours of smalltalk returns an oc with only one
rectangle.
Is this normal ?
Wasn't it supposed to return an oc with the receiver or I am missing
something.

Thanx.


Reply | Threaded
Open this post in threaded view
|

Re: #areasOutside:

Ian Bartholomew-21
Rusty,

> Is this normal ?
> Wasn't it supposed to return an oc with the receiver or I am missing
> something.

It does look a bit strange.  It works correctly for rectangles that do
intersect ..

((100@100) corner: (200@200)) areasOutside:  ((0@0) corner: (180@180))
((100@100) corner: (200@200)) areasOutside:  ((120@0) corner: (180@180))
((100@100) corner: (200@200)) areasOutside: ((120@120)  corner: (180@180))

.. which answer 2, 3 or 4 rectangles, and for rectangles that don't
intersect at all ..

((100@100) corner: (200@200)) areasOutside: ((300@300)  corner: (400@400))

.. which answers the receiver.  It seems to get a bit confused with
rectangles that touch ..

((100@100) corner: (200@200)) areasOutside: ((200@200)  corner: (400@400))
((100@100) corner: (200@200)) areasOutside: ((120@200)  corner: (180@400))

I'm not sure if two rectangles that only touch should be considered as
intersecting?  For the first of the two examples above should the method
answer self (no areas intersecting) or the rectangle (200@200) corner:
(200@200)

--
Ian

Use the Reply-To address to contact me (limited validity).
Mail sent to the From address is ignored.


Reply | Threaded
Open this post in threaded view
|

Re: #areasOutside:

Chris Uppal-3
Ian, Rusty,

>  It seems to get a bit confused with
> rectangles that touch ..
>
> ((100@100) corner: (200@200)) areasOutside: ((200@200)  corner: (400@400))

I think that's a bug.  It should answer the receiver since the two Rectangles
don't overlap (Rectangles -- unlike Intervals -- don't include their bottom or
left boundaries).  For example:

    ((100@100) corner: (200@200)) containsPoint: (200@200)

answers false, as does:

    ((100@100) corner: (200@200)) intersects: ((200@200)  corner: (400@400))


FWIW, Squeak gets this wrong in the same way, although VW and VA both get it
right.

I really loath this kind of code, or I'd try to suggest a fix for
Rectangle>>areasOutside:...

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: #areasOutside:

Chris Uppal-3
I wrote:

> I really loath this kind of code, or I'd try to suggest a fix for
> Rectangle>>areasOutside:...

It appears that simply changing the initial test in Rectangle>>areasOutside: to
read:

     (self intersects: aRectangle) ifFalse: [^Array with: self].

will fix it.  Not heavily tested, but logically it /should/ be correct...

(I've made the change in my image and nothing has broken yet -- mind you there
are only two uses of it anywhere, and neither is in Dolphin code ;-)

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: #areasOutside:

Ian Bartholomew-21
In reply to this post by Chris Uppal-3
Chris,

>    ((100@100) corner: (200@200)) containsPoint: (200@200)
>
> answers false, as does:

..  ((200@200) corner: (200@200)) containsPoint: (200@200)  That never seems
right to me. :-)

> I really loath this kind of code, or I'd try to suggest a fix for
> Rectangle>>areasOutside:...

I thought about trying to fix it as well, I guessed the equality test was
screwing up the calculation, but like you I've been there too often.  You
spend some time sorting out all the comparisons and, as a final test, you
try *just one* more arrangement.  It *always* fails and so you have to go
back and start again from scratch!

I agree that your suggestion of using #intersects seems to work though.
I'll give it *just one* more try in a minute  :-)

--
Ian

Use the Reply-To address to contact me (limited validity).
Mail sent to the From address is ignored.


Reply | Threaded
Open this post in threaded view
|

Re: #areasOutside:

Rusty-24
The #intersects seems to work fine, at least it returns what the rest
of sts does.
But in my example:

( Rectangle origin: ( 0 @ 200 ) extent: ( 800 @ 600 ) ) areasOutside: (
Rectangle origin: ( 0 @ 0 ) extent: ( 267 @ 200 ) )

It returns:

#(0@200 corner: 800@800)

Which is not the receiver, since the corner point is extended in 200
pixels.


Reply | Threaded
Open this post in threaded view
|

Re: #areasOutside:

Ian Bartholomew-21
Rusty,

> ( Rectangle origin: ( 0 @ 200 ) extent: ( 800 @ 600 ) ) areasOutside: (
> Rectangle origin: ( 0 @ 0 ) extent: ( 267 @ 200 ) )
>
> It returns:
>
> #(0@200 corner: 800@800)
>
> Which is not the receiver, since the corner point is extended in 200
> pixels.

It is the receiver but using the #corner definition rather than #extent.
Inspect

 Rectangle origin: ( 0 @ 200 ) extent: ( 800 @ 600 )

and it answers, correctly,

 0@200 corner: 800@800

The x edge position is 0 + 800 and the y edge position is 200 + 600 so the
bottom right corner is 800@800

--
Ian

Use the Reply-To address to contact me (limited validity).
Mail sent to the From address is ignored.


Reply | Threaded
Open this post in threaded view
|

Re: #areasOutside:

Rusty-24
Ohh, that's it.
Thanx a lot.