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

Bug 460569

Summary: Comparator in Point.eliminateDuplicates() violates contract of Comparator
Product: [Tools] GEF Reporter: Colin Sharples <ctg>
Component: GEF GeometryAssignee: Alexander Nyßen <nyssen>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: nyssen
Version: unspecifiedFlags: nyssen: iplog+
nyssen: mars+
Target Milestone: 3.10.0 (Mars) M6   
Hardware: PC   
OS: Windows NT   
Whiteboard:
Attachments:
Description Flags
test case with points that cause the exception nyssen: iplog+

Description Colin Sharples CLA 2015-02-23 03:38:06 EST
Created attachment 251009 [details]
test case with points that cause the exception

For certain sets of points, the Point.getConvexHull() method will throw an IllegalArgumentException due to a comparator in method Point.eliminateDuplicates() that violates the Comparator contract. The comparator used only returns -1 or 1, but the Comparator contract states that 0 must be returned if the two objects are exactly identical. If I add the following lines before the final return, then everything works fine:

    if (p1.x == p2.x && p1.y == p2.y) {
        return 0;
    }

I came across this when getting the outline of several shapes that had a lot of common elements, so there was a high number of duplicates to be discarded - 131 of the 168 points get discarded by the eliminateDuplicates() method (with the fix), so I guess this is a bit of an edge case, but it is best to stick to contracts.

I have attached a test case with the points that generate the exception.
Comment 1 Alexander Nyßen CLA 2015-02-23 04:00:50 EST
Thanks Colin. I will take a look. Could you please sign the Eclipse Contributor License Agreement (https://www.eclipse.org/legal/CLA.php), then we could directly adopt the test case to our code base as well.
Comment 2 Colin Sharples CLA 2015-02-23 04:06:29 EST
I have signed the CLA.
Comment 3 Alexander Nyßen CLA 2015-02-23 04:11:21 EST
(In reply to Colin Sharples from comment #2)
> I have signed the CLA.

Hmm, something does not seem to be appropriate. In the comment header, your CLA-state is indicated as not accepted.
Comment 4 Colin Sharples CLA 2015-02-23 04:18:28 EST
Perhaps it takes some time for the CLA status to synch through?
Comment 5 Alexander Nyßen CLA 2015-02-23 08:00:25 EST
Seems to be synched by now. Could you please confirm compliance with the Eclipse Certificate of Origin: http://www.eclipse.org/legal/CoO.php? I will then turn your test data into an appropriate test case and commit it to our repo.
Comment 6 Colin Sharples CLA 2015-02-23 12:42:28 EST
I confirm compliance with the CoO.

(I can't see a form for the CoO, so I presume this comment is enough?)
Comment 7 Alexander Nyßen CLA 2015-02-23 13:18:42 EST
Thanks Colin. I added your fix to Point, as well as a test case (with your test-data) to PointTests. Committed changes to origin/master (signed-off by you, with me as additional author). Resolving as fixed in 3.10.0M6.