[#547] Fix Connection Point of Edges and Nodes in State Diagrams #548
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
Edges in state diagrams connecting to the corner SW and SE points of rounded rectangles are positioned incorrectly. This can happen at either endpoints of the edge, as shown below.
Location of Error
The error was in
GeomUtils#intersectRectangle
, which is called byGeomUtils#intersectRoundedRectangle
to calculate the precise connection point on the rounded portions of the rounded rectangle.What was Wrong
The problem occurs when the edge is positioned on the exact corner point in the SW and SE direction.
The if conditions in
intersectRectangle
uses theifBetween(start, end)
method to check whether a direction is between start and end. The start and end value themselves are exclusive. For instance, 60° would not be between 60° (start) and 90° (end). (The documentation, which says that the starting direction is inclusive, may have been the reason for the oversight which led to this miscalculation).So, by the logic of the if/else-if/else branch in
intersectRectangle
, if a user positions two nodes such that the edge is pointing in the exact direction ofdiagonalSE
, the flow of execution would be delegated to theelse
branch, despite the fact that it should be handled by one of the appropriateif/else if
branch, which in this case could beelse if( pDirection.isBetween(diagonalNE, diagonalSE) )
. Interestingly, this did not impact the NW and NE corners because these two cases can be handled appropriately by theelse
branch in any case.Fix
By incrementing the range of the end values by 1 to include corner directions, we can ensure that the calculation is handled by the correct branch of if statements, and thus compute the offset for the connection points between node and edge correctly. To continue the example above, to fix the connection point for the SE corner, we can include the SE corner direction with the following code:
else if( pDirection.isBetween(diagonalNE, diagonalSE.rotatedBy(1)) )