| Summary: | Enhancement for Line (getMidPoint) | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Product: | [Tools] GEF | Reporter: | Colin Sharples <ctg> | ||||||||
| Component: | GEF Geometry | Assignee: | Alexander Nyßen <nyssen> | ||||||||
| Status: | RESOLVED WORKSFORME | QA Contact: | |||||||||
| Severity: | normal | ||||||||||
| Priority: | P3 | CC: | nyssen | ||||||||
| Version: | 0.2.0 | ||||||||||
| Target Milestone: | --- | ||||||||||
| Hardware: | PC | ||||||||||
| OS: | Windows NT | ||||||||||
| Whiteboard: | |||||||||||
| Attachments: |
|
||||||||||
Created attachment 260872 [details]
Test case for Line.getMidPoint
Thanks Colin! As Line is a BezierCurve, obtaining the mid-point is already possible by using line.get(0.5). Do you propose the enhancement for reasons of convenience or performance? In the latter case, I would propose to rather overwrite get(double) within Line to perform the respective optimization (based on your algorithm). In the first case we could think of introducing such a method as a shortcut (for get(0.5)). It's a bit of both, really. The center point of a line is a special case, and I have several use cases where you need to access that specific point (e.g. to split a line into two equal halves, to perform a rotation about the center point etc). I see Line.getMidPoint() primarily as an analogy to Rectangle.getCenter() or Polygon.getCentroid(). Given that a straight line is a degenerate case of a BezierCurve, there is certainly a case to be made for optimizing the internals, but I really see that as a separate issue. Note that the implementation I have provided is not (yet) fully optimized, as it is still going to create the line end points. If you prefer to replace the implementation with get(0.5), that's okay with me. That would have the advantage that only the get() method needs to be optimized for performance. Created attachment 260940 [details]
Re-implemented using get(0.5)
Replaced implementation using get(0.5), allowing for future performance enhancements to re-implement Line.get(double) in a more efficient manner.
This patch conforms to the Eclipse Foundation Certificate of Origin.
The test case previously submitted is still valid and works with the new implementation.
I re-implemented get(double) within Line to it is more performant then the generic BezierCurve#get(double) method (as it does not longer fall back to it. As get() covers the requested functionality and as it is now even locally re-implemented, I think an additional alias (getMidPoint()) is not really required (and would again cause a performance-overhead for clients). Resolving thus as WORKSFORME. |
Created attachment 260834 [details] Patch to add getMidPoint method to Line I would like to propose a minor enhancement to org.eclipse.gef4.geometry.planar.Line. One new method: Point getMidPoint() returns the center point of the line. This is essentially a synonym for Line.getBounds().getCenter(), but is more efficient as it avoids the creation of a Rectangle and two Points. This contribution complies to the Eclipse Foundation Certificate of Origin.