Skip to content

Commit

Permalink
[443954] Fix routers do not properly respect coordinate systems.
Browse files Browse the repository at this point in the history
- Fixed StraightRouter and OrthogonalRouter did not properly compute AnchoredReferencePoint
within the coordinate system of the anchored, which is the Connection's
curve node.
  • Loading branch information
nyssen committed May 18, 2016
1 parent 0e3929f commit 7c7241f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ private IGeometry getAnchorageGeometry(Connection connection, int index) {
* @param index
* The index specifying the anchor for which to provide a
* reference point.
* @return The reference point for the anchor at the given index.
* @return The reference point for the anchor at the given index in the
* local coordinate system of the anchored, which is the
* connection's curve.
*/
@Override
protected Point getAnchoredReferencePoint(Connection connection,
Expand All @@ -322,13 +324,15 @@ protected Point getAnchoredReferencePoint(Connection connection,
if (index == 0) {
Point startPointHint = connection.getStartPointHint();
if (startPointHint != null) {
return startPointHint;
return NodeUtils.parentToLocal(connection.getCurve(),
startPointHint);
}
} else if (index == connection.getPointsUnmodifiable().size()
- 1) {
Point endPointHint = connection.getEndPointHint();
if (endPointHint != null) {
return endPointHint;
return NodeUtils.parentToLocal(connection.getCurve(),
endPointHint);
}
}

Expand All @@ -344,32 +348,41 @@ protected Point getAnchoredReferencePoint(Connection connection,
refBounds.getX() + refBounds.getWidth());
if (x1 <= x2) {
// horizontal overlap => return vertically stable position
return new Point(x1 + (x2 - x1) / 2,
refBounds.getY() > bounds.getY()
+ bounds.getHeight() ? refBounds.getY()
: refBounds.getY()
+ refBounds.getHeight());
return NodeUtils.parentToLocal(connection.getCurve(),
new Point(x1 + (x2 - x1) / 2,
refBounds.getY() > bounds.getY()
+ bounds.getHeight()
? refBounds.getY()
: refBounds.getY()
+ refBounds
.getHeight()));
}

double y1 = Math.max(bounds.getY(), refBounds.getY());
double y2 = Math.min(bounds.getY() + bounds.getHeight(),
refBounds.getY() + refBounds.getHeight());
if (y1 <= y2) {
// vertical overlap => return horizontally stable position
return new Point(
refBounds.getX() > bounds.getX() + bounds.getWidth()
? refBounds.getX()
: refBounds.getX() + refBounds.getWidth(),
y1 + (y2 - y1) / 2);
return NodeUtils
.parentToLocal(connection.getCurve(),
new Point(refBounds.getX() > bounds.getX()
+ bounds.getWidth()
? refBounds.getX()
: refBounds.getX()
+ refBounds
.getWidth(),
y1 + (y2 - y1) / 2));
}
// fallback to nearest bounds projection
// TODO: revise handling of this case -> we could optimize this
// by providing a desired direction
return getNearestBoundsProjection(referenceGeometry,
geometry.getBounds().getCenter());
return NodeUtils.parentToLocal(connection.getCurve(),
getNearestBoundsProjection(referenceGeometry,
geometry.getBounds().getCenter()));
}
}
return connection.getPoint(referenceIndex);
return NodeUtils.parentToLocal(connection.getCurve(),
connection.getPoint(referenceIndex));
}

private Point getNearestBoundsProjection(IGeometry g, Point p) {
Expand Down Expand Up @@ -811,11 +824,12 @@ protected void updateComputationParameters(Connection connection,
Point neighborPoint = connection
.getPoint(index == 0 ? index + 1 : index - 1);
Point delta = neighborPoint
.getDifference(
((DynamicAnchor) anchor)
.getComputationParameter(anchorKey,
AnchoredReferencePoint.class)
.get());
.getDifference(NodeUtils.sceneToLocal(connection,
NodeUtils.localToScene(anchorKey.getAnchored(),
((DynamicAnchor) anchor)
.getComputationParameter(anchorKey,
AnchoredReferencePoint.class)
.get())));
Orientation hint = null;
if (Math.abs(delta.x) < 5
&& Math.abs(delta.x) < Math.abs(delta.y)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public class StraightRouter extends AbstractRouter {
* @param index
* The index specifying the anchor for which to provide a
* reference point.
* @return The reference point for the anchor at the given index.
* @return The reference point for the anchor at the given index within the
* local coordinate system of the anchored, which is the
* Connection's curve.
*/
@Override
protected Point getAnchoredReferencePoint(Connection connection,
Expand Down Expand Up @@ -79,8 +81,9 @@ protected Point getAnchoredReferencePoint(Connection connection,
// TODO: move to utility && replace with safe algorithm
private Point getCenter(Connection connection, Node anchorageNode) {
Point center = FX2Geometry
.toRectangle(connection.sceneToLocal(anchorageNode
.localToScene(anchorageNode.getLayoutBounds())))
.toRectangle(connection.getCurve()
.sceneToLocal(anchorageNode
.localToScene(anchorageNode.getLayoutBounds())))
.getCenter();
if (Double.isNaN(center.x) || Double.isNaN(center.y)) {
return null;
Expand Down Expand Up @@ -116,8 +119,8 @@ private Point getNeighbor(Connection connection, int anchorIndex,
throw new IllegalStateException(
"connection inconsistent (null position)");
}
Point2D local = anchorage.sceneToLocal(
connection.localToScene(position.x, position.y));
Point2D local = anchorage.sceneToLocal(anchorKey.getAnchored()
.localToScene(position.x, position.y));
// TODO: NPE maybe local is null?
if (!anchorage.contains(local)) {
return position;
Expand Down Expand Up @@ -145,11 +148,6 @@ private Point getSucc(Connection connection, int anchorIndex) {
return getNeighbor(connection, anchorIndex, 1);
}

@Override
public boolean wasInserted(IAnchor anchor) {
return false;
}

@Override
public void route(Connection connection) {
if (connection.getPointsUnmodifiable().size() < 2) {
Expand All @@ -166,4 +164,9 @@ public void route(Connection connection) {
}
}

@Override
public boolean wasInserted(IAnchor anchor) {
return false;
}

}

0 comments on commit 7c7241f

Please sign in to comment.