Summary: | [Geometry] Rectangle width and height are interpreted inconsistently | ||||||
---|---|---|---|---|---|---|---|
Product: | [Tools] GEF | Reporter: | fictivy | ||||
Component: | GEF-Legacy Draw2d | Assignee: | gef-inbox <gef-inbox> | ||||
Status: | NEW --- | QA Contact: | |||||
Severity: | normal | ||||||
Priority: | P3 | CC: | a.bradley, nyssen | ||||
Version: | unspecified | ||||||
Target Milestone: | --- | ||||||
Hardware: | All | ||||||
OS: | All | ||||||
Whiteboard: | |||||||
Bug Depends on: | 292164 | ||||||
Bug Blocks: | |||||||
Attachments: |
|
Description
fictivy
2007-02-22 13:42:30 EST
Created attachment 59595 [details]
Code example
The inconsistency w.r.t. to drawRectangle() and fillRectangle() is indeed caused by SWT (the Draw2d graphics just forwards to the SWT GC) and has (at least concerning drawRectangle() method) been addressed by bug #292164. There are related oddities in the way Rectangle handles a rectangle's bottom and right boundaries; this can be seen by comparing the Rectangle(Point, Point) constructor and the getBottomRight(), etc. methods, or the contains(Rectangle) and contains(Point) methods. As can be seen from the JUnit code snippet below, Rectangle currently has the following mathematically puzzling properties: (1) A Rectangle is not equal to the smallest Rectangle containing its top left and bottom right corners. (2) A Rectangle contains itself, but does not contain its own bottom right corner. Perhaps, at minimum, the Javadoc for Rectangle(Point, Point) should be updated to make (1) clear? Snippet follows: Rectangle r1 = new Rectangle(20, 30, 44, 62); Rectangle r2 = new Rectangle(r1.getTopLeft(), r1.getBottomRight()); assertEquals(r1, r2); // fails assertTrue(r1.contains(r1)); // succeeds assertTrue(r1.contains(r1.getBottomRight())); // fails (In reply to comment #3) > There are related oddities in the way Rectangle handles a rectangle's bottom > and right boundaries; this can be seen by comparing the Rectangle(Point, Point) > constructor and the getBottomRight(), etc. methods, or the contains(Rectangle) > and contains(Point) methods. As can be seen from the JUnit code snippet below, > Rectangle currently has the following mathematically puzzling properties: > > (1) A Rectangle is not equal to the smallest Rectangle containing its top left > and bottom right corners. > (2) A Rectangle contains itself, but does not contain its own bottom right > corner. > > Perhaps, at minimum, the Javadoc for Rectangle(Point, Point) should be updated > to make (1) clear? > > Snippet follows: > > Rectangle r1 = new Rectangle(20, 30, 44, 62); > Rectangle r2 = new Rectangle(r1.getTopLeft(), r1.getBottomRight()); > assertEquals(r1, r2); // fails > assertTrue(r1.contains(r1)); // succeeds > assertTrue(r1.contains(r1.getBottomRight())); // fails Yes, that's quite another one. IMHO the Draw2d geometry classes are all kind of a mess and - being bound to API compatibility - there's actually not much we can do against it. I have tried to clean things up as far as API compatibility allowed in the 3.6 release train, and now I think we should simply leave it as it is and focus on the new Geometry API we have started to work on in terms of GEF4 (see bug # 355997 for details). GEF4's Geometry API is completely double-based (no separation between integer and double precision) and deals with above mentioned inconsistency by regarding the bottom and right corner of a rectangle to be part of it (as any other polygon does). We have not yet provided a first release (we are currently working on the last large contribution to provide implementations for Regions and Rings) but will do so for Juno and will then port the Draw2d/GEF (MVC) code base to it as a starting point for GEF4. |