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

Bug 488354

Summary: Add support for computing the nearest point on an ICurve with respect to a given reference point.
Product: [Tools] GEF Reporter: Alexander Nyßen <nyssen>
Component: GEF GeometryAssignee: gef-inbox <gef-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: matthias.wienand
Version: 0.2.0   
Target Milestone: 4.0.0 (Neon) M6   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 488353    

Description Alexander Nyßen CLA 2016-02-24 02:10:45 EST
ICurve should support computation of its nearest contained point w.r.t. a given reference point. 

This is e.g. needed for an improved anchor position computation strategy within ChopBoxAnchor (see bug #488353).
Comment 1 Alexander Nyßen CLA 2016-02-24 06:05:13 EST
As all ICurves can be broken down into BezierCurves, this basically boils down to computing a point projection on a BezierCurve.
Comment 2 Matthias Wienand CLA 2016-03-01 06:58:56 EST
I pushed the following to changes to master:

 - Added and implemented ICurve#getProjection(Point) that returns a point on the ICurve with minimal distance to the given reference point.
 - Added tests for the point projection onto Bézier curves.

However, for a complete implementations, the following cases have to be taken into consideration as well:

 - A point can be projected onto multiple points with the same, minimal distance, for example, when the start and end point of a parabola are closest to the reference point.
 - A point can be projected onto infinite points with the same, minimal distance, for example, when the curve is circular (Arc, Ellipse) and the reference point is the center of the corresponding circle.

Therefore, I would suggest to remove the ICurve#getProjection(Point):Point method, and provide the following set of methods instead:

 - ICurve#isInfiniteProjection(Point):boolean returns true if the given point can be projected onto an infinte number of points on the curve.
 - ICurve#getInfiniteProjection(Point):List<ICurve> returns the individual curves that describe all possible projections.
 - ICurve#getProjections(Point):List<Point> returns the points on the curve with the same, minimal distance to the given reference point.
Comment 3 Matthias Wienand CLA 2016-03-01 12:06:04 EST
The implemented functionality is sufficient for the anchor computation, therefore, I resolve this as fixed for 4.0.0 M6. The functionality that is outlined in comment #2 can be added at a later point if needed.