Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 310397

Summary: Draw2D Euclidean Geometry (Ray, Straight) should support double precision.
Product: [Tools] GEF Reporter: Alexander Nyßen <nyssen>
Component: GEF-Legacy Draw2dAssignee: Alexander Nyßen <nyssen>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: ahunter.eclipse
Version: 3.6   
Target Milestone: 3.6.0 (Helios) RC1   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Patch demonstrating a possible refactoring of Ray/Straight
none
Patch to restore 1.4 backwards compatibility
none
Revised patch to restore 1.4 backwards compatiblity. none

Description Alexander Nyßen CLA 2010-04-25 18:16:05 EDT
Up to now, implementation of Ray is based on integer precision. As straight depends on Ray, it is thereby limited to integer precision as well. Here, integer precision may lead to very strange effects due to rounding problems. 

Just an example: Computation of an intersection point of the straights (0,0) -> (5,5) and (0,5) -> (5,0) leads to a result of (2,2) with the current implementation of Straight.getIntersection(). Thus, if the result of getIntersection() is used to test, whether any of the two lines actually contains the returned intersection point, this will actually lead to a failure.

A proper Euclidean geometry should therefore rely on double precision. Clients may round where appropriate.
Comment 1 Alexander Nyßen CLA 2010-04-26 03:17:57 EDT
Created attachment 166050 [details]
Patch demonstrating a possible refactoring of Ray/Straight

As some new operations were introduced to Ray in 3.6 and as the whole Straight class was newly introduced as well, I think it would be best to address this issue before this gets cemented into API (although we are already past M6).

IMHO the best possibility to deal with this would be to remove all operations, newly introduced to Ray in 3.6 again, to deprecate it, and to offer a new double-based implementation (let's call it Vector) with includes those newly introduced operations. Straight could in turn be based on the newly introduced Vector instead of Ray. I think it would also be wishful to separate both classes from the planar geometry things within the geometry package, so I would propose to introduce a new package for this. I have attached a patch that demonstrates what I have in mind.
Comment 2 Alexander Nyßen CLA 2010-04-26 03:18:29 EDT
Anthony, do you see a chance we could incorporate this into 3.6M7, as it would not lead to API-incompatible changes?
Comment 3 Anthony Hunter CLA 2010-04-26 15:21:36 EDT
Hi Alex, this is added API and as far as I can tell cannot break any existing clients, so we are good to commit.

Why do we need a new org.eclipse.draw2d.geometry.euclidean package? I suggest we leave these in the existing org.eclipse.draw2d.geometry package.
Comment 4 Alexander Nyßen CLA 2010-04-26 15:29:01 EDT
IMHO there are basically three kinds of classes within the current geometry package, base classes like Point and Dimension (and their precision derivates), Euclidean geometry related classes (Ray/Straight/Vector), and solid geometry related ones (Rectangle, etc). My motivation for the introduction of the euclidean sub-package was simple a better separation of concerns. As there are several issues related to refactoring/enhancing/augmenting the Geometry API, it is likely that additional classes will be added in the post Helios timeframe (e.g. Ellipse or Path) and that we could already start with cleary separating those aspects. Does that make sense?
Comment 5 Alexander Nyßen CLA 2010-04-27 15:00:26 EDT
I have done some polishing to the Vector/Straight code (basically renaming of methods to ensure a common naming schema; also make position and direction vector fields of straight visible so both classes share a common "look and feel") and I think they are ready to be committed. 

Anthony, after I have now stated what my motivation for introducing the package was, may I urge you for a final comment about whether we should leave them in the original package or introduce a new package to separate out Euclidean geometry related API?
Comment 6 Anthony Hunter CLA 2010-04-27 16:04:40 EDT
(In reply to comment #5)
> Anthony, after I have now stated what my motivation for introducing the package
> was, may I urge you for a final comment about whether we should leave them in
> the original package or introduce a new package to separate out Euclidean
> geometry related API?

Lets keep them in the standard geometry package that has been there for the last N releases.
Comment 7 Alexander Nyßen CLA 2010-04-27 16:14:32 EDT
OK. Changes committed to cvs HEAD.
Comment 8 Anthony Hunter CLA 2010-05-11 12:26:50 EDT
Hi Alexander,

GEF works with a Java 1.4 JRE. With the changes to Vector:

import java.math.MathContext;
import java.math.RoundingMode;

Both cannot be found in my Sun JRE 1.4 version 10. Can you confirm?

Our build is supposed to be using a 1.4 JRE, will need to investigate.
Comment 9 Alexander Nyßen CLA 2010-05-11 15:08:47 EDT
Yes, you are right, it seems this has been added in 1.5.0 http://javadiff.sourceforge.net/jdiff/reports/j2se142_j2se150b1/changes.html.

Well, I am using a 1.5 JDK with the j2SE-1.4 compliance settings, so I did not run into any problems. Ensuring strict API-compatibility to the 1.4 JDK framework classes could probably only be achieved by using a strictly 1.4 compatible VM (which is hard to get for MacOSX Snow Leopard, as it is two years past its EOL). I think the build machine is probably also using a 1.5 VM in 1.4 compliance mode and thus does not report any issues in this case either. 

What do you propose? Do I have to re-implement the private precision methods to achieve 1.4. BigDecimal compliance?
Comment 10 Anthony Hunter CLA 2010-05-11 16:17:20 EDT
Yes, we have to support Java 1.4 so we need to make the code compatible.

I tried in the past to force move us to Java 1.5, and got push back from the community. This was Bug 204605 .

It is now three years later and Java 1.4 support is somewhat insane given that I am pretty sure Java 1.4 support has expired. Next year we need to move to 1.5.
Comment 11 Alexander Nyßen CLA 2010-05-11 16:35:45 EDT
OK, I will take a look.
Comment 12 Alexander Nyßen CLA 2010-05-11 17:10:08 EDT
Created attachment 168041 [details]
Patch to restore 1.4 backwards compatibility

As far as I could observe, this patch changes the implementation to only use those methods offered by BigDecimal as of J2SE-1.4. Could you please confirm that your Sun 1.4 VM likes it this way?
Comment 13 Alexander Nyßen CLA 2010-05-11 17:14:26 EDT
(In reply to comment #12)
> Created an attachment (id=168041) [details]
> Patch to restore 1.4 backwards compatibility
> 
> As far as I could observe, this patch changes the implementation to only use
> those methods offered by BigDecimal as of J2SE-1.4. Could you please confirm
> that your Sun 1.4 VM likes it this way?

Not quite right, it now causes two test errors I have overlooked. I will have to reconsider.
Comment 14 Anthony Hunter CLA 2010-05-11 17:15:10 EDT
One last fix:

Description	Resource	Path	Location	Type
The method divide(BigDecimal, int) in the type BigDecimal is not applicable for the arguments (BigDecimal)	Vector.java	/org.eclipse.draw2d/src/org/eclipse/draw2d/geometry	line 344	Java Problem
Comment 15 Alexander Nyßen CLA 2010-05-11 17:18:35 EDT
Created attachment 168047 [details]
Revised patch to restore 1.4 backwards compatiblity.

OK, this one should be working now. Can you give it another try?
Comment 16 Anthony Hunter CLA 2010-05-11 17:22:33 EDT
(In reply to comment #15)
> OK, this one should be working now. Can you give it another try?

Looks good.
Comment 17 Alexander Nyßen CLA 2010-05-11 17:29:26 EDT
(In reply to comment #16)
> (In reply to comment #15)
> > OK, this one should be working now. Can you give it another try?
> 
> Looks good.

Test cases are fine as well. I have committed the changes to HEAD. Closing this one as resolved in 3.6RC1.