Quantcast

Rectangle and Polygon classes' bugs?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Rectangle and Polygon classes' bugs?

Andreas Sunardi
Pharo 5.0

It seems like a bug to me, but perhaps I misunderstand something.

1) Comment in Rectangle class >> origin:corner: method shows 'origin' should be top left and 'corner' should be bottom right. This method calls Rectangle >> setPoint:point:. But this method calculates 'origin' to be bottom left corner and 'corner' to be top right. Now all the edge and corner methods are wrong.

r := Rectangle origin: 0@0 corner: 10@10.
r topLeft.  => (0@0)   "should be 0@10"
r bottomRight.  => (10@10)  "should be 10@0"
r top.  => 0  "should be 10"
r bottom.  => 10  " should be 0"


2) Why Polygon >> bounds (which is PathShape >> bounds) returns a rectangle with a corner 1 point larger than the actual boundary?

p1 := Polygon vertices: {0@0 . 0@10 . 10@10 . 10@0}.
p1 bounds.  => (0@0) corner: (11@11).  "should be 0@0 and 10@10"

This seems to be a fix to Rectangle >> containsPoint: strange behavior. By strange behavior, I mean:

r := Rectangle point: 0@0 point: 10@10.
r containsPoint: 0@0.  => true
r containsPoint: 10@10.  => false  "should be true"
{ r topLeft . r topRight . r bottomLeft . r bottomRight } allSatisfy [ :corner | r containsPoint: corner ].  => false  "should be true"


I want to fix this in my image, but Rectangle is used all over the place and I'm worry I'll break a lot of things. I wonder if I just misunderstood how these are supposed to be used. Can anybody help me understand if this is intentional or a bug?

PS: I looked at RectangleTest and I'm not sure I understand why they are testing what they are testing.

--
Andreas Sunardi
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rectangle and Polygon classes' bugs?

Ben Coman


On Sat, May 20, 2017 at 12:23 AM, Andreas Sunardi <[hidden email]> wrote:
Pharo 5.0

It seems like a bug to me, but perhaps I misunderstand something.

1) Comment in Rectangle class >> origin:corner: method shows 'origin' should be top left and 'corner' should be bottom right. This method calls Rectangle >> setPoint:point:. But this method calculates 'origin' to be bottom left corner and 'corner' to be top right. Now all the edge and corner methods are wrong.

r := Rectangle origin: 0@0 corner: 10@10.
r topLeft.  => (0@0)   "should be 0@10"
r bottomRight.  => (10@10)  "should be 10@0"
r top.  => 0  "should be 10"
r bottom.  => 10  " should be 0"

Would this depend on where you consider 0@0 to be on the screen?
  (em := EllipseMorph new) openInWorld. 
  em bounds "==> (0@0) corner: (50@40)"
 
 
2) Why Polygon >> bounds (which is PathShape >> bounds) returns a rectangle with a corner 1 point larger than the actual boundary?

p1 := Polygon vertices: {0@0 . 0@10 . 10@10 . 10@0}.
p1 bounds.  => (0@0) corner: (11@11).  "should be 0@0 and 10@10"

This seems to be a fix to Rectangle >> containsPoint: strange behavior. By strange behavior, I mean:

r := Rectangle point: 0@0 point: 10@10.
r containsPoint: 0@0.  => true
r containsPoint: 10@10.  => false  "should be true"
{ r topLeft . r topRight . r bottomLeft . r bottomRight } allSatisfy [ :corner | r containsPoint: corner ].  => false  "should be true"


I want to fix this in my image, but Rectangle is used all over the place and I'm worry I'll break a lot of things. I wonder if I just misunderstood how these are supposed to be used. Can anybody help me understand if this is intentional or a bug?

Sorry, I don't know about this.  
cheers -ben
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Rectangle and Polygon classes' bugs?

Andreas Sunardi
Ah, I see, so Rectangle is in the context of display geometry not Cartesian coordinate (I don't know if I'm using the right words here, but I hope you get what I mean). You're right, the package is 'Graphics-Shapes'. For some reason, I thought it said 'Geometry'

I'm building something for layout geometry and these would be the wrong classes to use then. Question #2 would be a moot point.

Thanks for the answer. You've saved me from going to the wrong path.

--
Andreas Sunardi

On Fri, May 19, 2017 at 9:53 AM, Ben Coman <[hidden email]> wrote:


On Sat, May 20, 2017 at 12:23 AM, Andreas Sunardi <[hidden email]> wrote:
Pharo 5.0

It seems like a bug to me, but perhaps I misunderstand something.

1) Comment in Rectangle class >> origin:corner: method shows 'origin' should be top left and 'corner' should be bottom right. This method calls Rectangle >> setPoint:point:. But this method calculates 'origin' to be bottom left corner and 'corner' to be top right. Now all the edge and corner methods are wrong.

r := Rectangle origin: 0@0 corner: 10@10.
r topLeft.  => (0@0)   "should be 0@10"
r bottomRight.  => (10@10)  "should be 10@0"
r top.  => 0  "should be 10"
r bottom.  => 10  " should be 0"

Would this depend on where you consider 0@0 to be on the screen?
  (em := EllipseMorph new) openInWorld. 
  em bounds "==> (0@0) corner: (50@40)"
 
 
2) Why Polygon >> bounds (which is PathShape >> bounds) returns a rectangle with a corner 1 point larger than the actual boundary?

p1 := Polygon vertices: {0@0 . 0@10 . 10@10 . 10@0}.
p1 bounds.  => (0@0) corner: (11@11).  "should be 0@0 and 10@10"

This seems to be a fix to Rectangle >> containsPoint: strange behavior. By strange behavior, I mean:

r := Rectangle point: 0@0 point: 10@10.
r containsPoint: 0@0.  => true
r containsPoint: 10@10.  => false  "should be true"
{ r topLeft . r topRight . r bottomLeft . r bottomRight } allSatisfy [ :corner | r containsPoint: corner ].  => false  "should be true"


I want to fix this in my image, but Rectangle is used all over the place and I'm worry I'll break a lot of things. I wonder if I just misunderstood how these are supposed to be used. Can anybody help me understand if this is intentional or a bug?

Sorry, I don't know about this.  
cheers -ben

Loading...