Mantis - Squeak
Viewing Issue Advanced Details
2126 Graphics minor always 10-25-05 20:46 02-16-06 10:01
BGaertner  
andreas  
normal  
closed 3.9  
fixed  
none    
none 3.9  
0002126: Rectangle>>areasOutside: has a bug
The instance method areasOutside: of Rectangle has a subtle bug that can cause a result with lots of rectangles of height zero. To see the problem, you can evaluate this piece of code:

| frame rects visibleBackground cnt |

cnt := 0.
visibleBackground := [:f :rc | | visibleAreas |
  visibleAreas := Array with: f.
  rc do: [:rect | | remnants |
      remnants := OrderedCollection new.
      visibleAreas do: [:a | remnants addAll: (a areasOutside: rect)].
      visibleAreas := remnants.
       cnt := cnt + 1.
      Transcript show: cnt printString; show: ' '; show: visibleAreas size
printString; cr.
  ].
  visibleAreas
 ].

frame := 0@0 extent: 300@300. /> rects := OrderedCollection new: 80.
0 to: 9 do: [:i |
  0 to: 7 do: [:j |
        rects add: (i@j * 20 extent: 10@10)
]].

( visibleBackground value: frame value: rects) size

-----------------
Here we have a large rectangle (frame) and 80 small rectangles
that are placed on the large rectangle. The block is a piece
of code that computes the part of the large rectangle that is
not covered by small rects.

replace the last statement of the code above with

(( visibleBackground value: frame value: rects)
   reject: [:r | r area = 0]
) size

to see that most of the rectangles have no area.

The many useless rectangles of height zero are created becaue areasOutside: uses a wrong test for intersection. The test ignores the fact that the bottom line and the right border line of a rectangle are not part of the rectangle.

Attached you find
1. a proposed fix (Rect-areasOutside-bg.1.cs)
2. some additional tests for class Rectangle. (RectangleAdditionalTests.2.cs)
The bug is also present in earlier versions of Squeak.
 Rect-areasOutside-bg.1.cs [^] (1,326 bytes) 10-25-05 20:47
 RectangleAdditionalTests.2.cs [^] (3,013 bytes) 10-25-05 20:48

Notes
(0002978)
BGaertner   
10-25-05 20:50   
For some reason, the description text is displayed in a very ugly form. I am sorry about that, but I cannot change it.
(0002980)
andreas   
10-26-05 02:30   
Now integrated. Thanks for reporting.
(0003880)
MarcusDenker   
02-16-06 10:01   
integrated