Fixed two problems in connecting picking 35/3435/1
authorJussi Koskela <jussi.koskela@semantum.fi>
Thu, 31 Oct 2019 13:52:35 +0000 (15:52 +0200)
committerJussi Koskela <jussi.koskela@semantum.fi>
Thu, 31 Oct 2019 13:52:35 +0000 (15:52 +0200)
Tolerance was incorrectly subtracted instead of added in RouteLine
picking. RouteGraphConnectionClass did not take selection stroke width
into account when doing coarse picking based on bounding box.

gitlab #396

Change-Id: I6dabe7297eb553f0894c4299c393bb5369b45866

bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RouteLine.java
bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/RouteGraphConnectionClass.java

index 8a73ead7aec28b406bf3acd0a5ec9786d17f61ec..91a53d85429fa0ac5a2cb0492deb53ea8573ac10 100644 (file)
@@ -97,10 +97,10 @@ public class RouteLine implements RouteNode, Serializable {
     public boolean isNear(double x2, double y2, double tolerance) {
         return isHorizontal 
                 ? Math.abs(y2-position) <= tolerance 
-                    && points.get(0).x <= x2 - tolerance
+                    && points.get(0).x - tolerance <= x2
                     && x2 <= points.get(points.size()-1).x + tolerance
                 : Math.abs(x2-position) <= tolerance 
-                    && points.get(0).y <= y2 - tolerance
+                    && points.get(0).y - tolerance <= y2
                     && y2 <= points.get(points.size()-1).y + tolerance;
     }
 
index bf4577b51e1666378a10b3b6a46e4412b54dab99..5aa435920a3ee2c0ca5ac4e54b4eff8b825fe575 100644 (file)
@@ -198,11 +198,11 @@ public class RouteGraphConnectionClass {
 
         @Override
         public Rectangle2D getBounds(IElement e, Rectangle2D size) {
-            RouteGraph rg = getRouteGraph(e);
-            if (rg != null) {
+            RouteGraphNode rgn = e.getHint(KEY_RG_NODE);
+            if (rgn != null) {
                 if (size == null)
                     size = new Rectangle2D.Double();
-                rg.getBounds(size);
+                size.setRect(rgn.getBoundsInLocal());
             }
             return size;
         }