| Summary: | Add getLength() method to Line | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Product: | [Tools] GEF | Reporter: | Colin Sharples <ctg> | ||||||||||
| Component: | GEF Geometry | Assignee: | gef-inbox <gef-inbox> | ||||||||||
| Status: | RESOLVED FIXED | QA Contact: | |||||||||||
| Severity: | enhancement | ||||||||||||
| Priority: | P3 | CC: | matthias.wienand, nyssen | ||||||||||
| Version: | unspecified | ||||||||||||
| Target Milestone: | 3.10.0 (Mars) M6 | ||||||||||||
| Hardware: | PC | ||||||||||||
| OS: | Windows NT | ||||||||||||
| See Also: | https://bugs.eclipse.org/bugs/show_bug.cgi?id=491405 | ||||||||||||
| Whiteboard: | |||||||||||||
| Attachments: |
|
||||||||||||
I have a couple of other minor enhancements for Line and Angle. Do I need to open separate requests for each or can they be added to this one? (In reply to Colin Sharples from comment #1) > I have a couple of other minor enhancements for Line and Angle. Do I need to > open separate requests for each or can they be added to this one? I think the best way is to create a patch for everything that belongs semantically together. You can attach multiple patches to this ticket (and we rename it to indicate what is contributed) or create separate bugzillas, whatever best reflects your contribution. Indeed, a patch is the better way of providing things, as we can simply turn that into a commit (compared to snippets within comments, which I have to turn into commits, adding contributor entry to file comments, etc.). Patches, can also easier be tracked with respect to IP log (if I consume a contribution from a comment, I have to flag the whole Bugzilla as being IP log relevant, whereas in case of patches, I can do that only for the attachment). You can find details in the GEF contributor guide (https://wiki.eclipse.org/GEF/Contributor_Guide) as well as the Eclipse Development Resources (https://wiki.eclipse.org/Development_Resources/Contributing_via_Git). Created attachment 251187 [details]
Added getLength() method to Line
Created attachment 251188 [details] Patch for Line.getLength() method This contribution complies with http://www.eclipse.org/legal/CoO.php Created attachment 251189 [details] Patch for Line.getDirection method Proposed method getDirection():Angle to be added to Line. This returns the angle from the P1 to the P2 points of the line. This contribution complies with http://www.eclipse.org/legal/CoO.php Created attachment 251190 [details] Patch for Angle.getReverse() method Proposed method getReverse():Angle for class Angle. This returns the reverse of the current angle in a full circle, i.e. this angle plus 180 degrees (normalized to a new Angle). This contribution complies with http://www.eclipse.org/legal/CoO.php The three proposed methods described here are essentially convenience methods, but in combination represent a fairly common set of operations that would frequently be used with a Line object. Given that a Line represents a finite portion of an abstract line between two specific points, being able to know the distance between those points, and the angle formed from point 1 to point 2 and vice versa would be very commonly used functions. Having these as part of API also allows for potential performance enhancements in future - Line in particular has a lot of unnecessary new object creation that could be optimized out. Note that my implementation of getDirection() just uses Math.atan2 directly without going through other gef4 Euclidean classes, but that seemed easier and probably quicker than converting to Straight/Vector. Thank you very much for the contribution! I applied the patches (with some minor changes) and published the code on the master branch. Therefore, I resolve this ticket as fixed for 3.10.0M6. (In reply to Colin Sharples from comment #7) > The three proposed methods described here are essentially convenience > methods, but in combination represent a fairly common set of operations that > would frequently be used with a Line object. Given that a Line represents a > finite portion of an abstract line between two specific points, being able > to know the distance between those points, and the angle formed from point 1 > to point 2 and vice versa would be very commonly used functions. Yes, I think it is definitely useful. I split the Line#getDirection() method into Line#getDirectionCW() and Line#getDirectionCCW(), so that the angle between the line and the x axis can be queried clockwise or counter-clockwise, respectively. Additionally, I added some basic tests for these methods. Apart from that, I did not change your suggestions. > Having these as part of API also allows for potential performance > enhancements in future - Line in particular has a lot of unnecessary new > object creation that could be optimized out. Currently, optimization is not priorizized. On the other hand, contributions in this regard are greatly appreciated :-) > Note that my implementation of getDirection() just uses Math.atan2 directly > without going through other gef4 Euclidean classes, but that seemed easier > and probably quicker than converting to Straight/Vector. We should probably do this at a few more places to gain some performance. |
I'd like to add the following method to class org.eclipse.gef4.geometry.planar.Line to get the distance between the line's two points: /** * Calculates the distance between the two {@link Point}s representing the * start and end points of this {@link Line} * * @see Point#getDistance(Point) * @return the distance from P1 to P2 */ public double getLength() { return getP1().getDistance(getP2()); }