Repository: workcraft/workcraft
Issue: Position implicit place token in the middle of the polyline segment

If the transitions connected by an arc (with implicit place) have significantly different name length, then a token on that arc would appear closer to the transition with the longer name. This happens because the connection start and end point are considered as the the centres of the adjacent nodes. Instead the intersection with their bounding boxes should be taken as the start and end points. 


Changed files:
WorkcraftCore/src/org/workcraft/dom/visual/connections/Polyline.java, STGPlugin/src/org/workcraft/plugins/stg/VisualImplicitPlaceArc.java, WorkcraftCore/src/org/workcraft/dom/visual/connections/VisualConnection.java

diff --git a/STGPlugin/src/org/workcraft/plugins/stg/VisualImplicitPlaceArc.java b/STGPlugin/src/org/workcraft/plugins/stg/VisualImplicitPlaceArc.java
index c8393fa56..3ed21ea4f 100644
--- a/STGPlugin/src/org/workcraft/plugins/stg/VisualImplicitPlaceArc.java
+++ b/STGPlugin/src/org/workcraft/plugins/stg/VisualImplicitPlaceArc.java
@@ -121,7 +121,7 @@ public class VisualImplicitPlaceArc extends VisualConnection {
     public void draw(DrawRequest r) {
         super.draw(r);
         int tokens = implicitPlace.getTokens();
-        Point2D p = getPointOnConnection(0.5);
+        Point2D p = getMiddleSegmentCenterPoint();
         Graphics2D g = r.getGraphics();
         g.translate(p.getX(), p.getY());
         VisualPlace.drawTokens(r, tokens, singleTokenSize, multipleTokenSeparation, tokenSpaceSize, 0, tokenColor);
diff --git a/WorkcraftCore/src/org/workcraft/dom/visual/connections/Polyline.java b/WorkcraftCore/src/org/workcraft/dom/visual/connections/Polyline.java
index 12567e18f..07d4bf767 100644
--- a/WorkcraftCore/src/org/workcraft/dom/visual/connections/Polyline.java
+++ b/WorkcraftCore/src/org/workcraft/dom/visual/connections/Polyline.java
@@ -106,13 +106,13 @@ public class Polyline implements ConnectionGraphic, Container, StateObserver,
         g.draw(connectionPath);
 
         if (connectionInfo.hasArrow()) {
-            DrawHelper.drawArrowHead(g, curveInfo.headPosition,    curveInfo.headOrientation,
+            DrawHelper.drawArrowHead(g, curveInfo.headPosition, curveInfo.headOrientation,
                     connectionInfo.getArrowLength(), connectionInfo.getArrowWidth(), color);
         }
 
         if (connectionInfo.hasBubble()) {
             DrawHelper.drawBubbleHead(g, curveInfo.headPosition, curveInfo.headOrientation,
-                    connectionInfo.getBubbleSize(),    color, connectionInfo.getStroke());
+                    connectionInfo.getBubbleSize(), color, connectionInfo.getStroke());
         }
     }
 
diff --git a/WorkcraftCore/src/org/workcraft/dom/visual/connections/VisualConnection.java b/WorkcraftCore/src/org/workcraft/dom/visual/connections/VisualConnection.java
index 3417400d1..1d3714c3a 100644
--- a/WorkcraftCore/src/org/workcraft/dom/visual/connections/VisualConnection.java
+++ b/WorkcraftCore/src/org/workcraft/dom/visual/connections/VisualConnection.java
@@ -429,7 +429,19 @@ public class VisualConnection extends VisualNode implements Node, Drawable, Shap
 
     @NoAutoSerialisation
     public Point2D getSplitPoint() {
-        return (splitPoint == null) ? getPointOnConnection(0.5) : splitPoint;
+        return (splitPoint == null) ? getMiddleSegmentCenterPoint() : splitPoint;
+    }
+
+    public Point2D getMiddleSegmentCenterPoint() {
+        double k = 0.5;
+        ConnectionGraphic graphic = getGraphic();
+        boolean isSingleSegmentPolyline = (graphic instanceof Polyline)
+                && (((Polyline) graphic).getSegmentCount() == 1);
+        if ((graphic instanceof Bezier) || isSingleSegmentPolyline) {
+            PartialCurveInfo curveInfo = graphic.getCurveInfo();
+            k = 0.5 * (curveInfo.tStart + curveInfo.tEnd);
+        }
+        return getPointOnConnection(k);
     }
 
     public Point2D getPointOnConnection(double t) {