Use element transform when doing pick check 45/4245/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Wed, 20 May 2020 13:47:51 +0000 (16:47 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 20 May 2020 14:07:31 +0000 (14:07 +0000)
gitlab #537

Change-Id: I5fc0d21ce99daca3aa0db210f86382db74fba155
(cherry picked from commit 995f91f4eb4feac37fbee766fb2b16f8d919c5e3)

bundles/org.simantics.g2d/src/org/simantics/g2d/element/handler/impl/ShapePick.java

index a1d31acf0e03f9990ef11583fa8c1f4409eeb1b9..3766a751b6816dbc6a4d12be5f59a4fcd7160bb7 100644 (file)
@@ -39,6 +39,8 @@ public class ShapePick implements Pick {
             pickRect = s.getBounds2D();
 
         Shape es = ElementUtils.getElementShapeOrBounds(e);
+        // getElementShapeOrBounds returns shape or bounds in local coords!
+        es = ElementUtils.getTransform(e).createTransformedShape(es);
         PathIterator iter = es.getPathIterator(null);
         Collection<double[]> segments = new ArrayList<double[]>();
         PathUtils.toLineSegments(iter, segments);
@@ -55,7 +57,12 @@ public class ShapePick implements Pick {
                 for (double[] seg : segments) {
                     if (pickRect.intersectsLine(seg[0], seg[1], seg[2], seg[3]))
                         return true;
+                    if (pickRect.contains(seg[0], seg[1]))
+                       return true;
+                    if (pickRect.contains(seg[2], seg[3]))
+                       return true;
                 }
+                
                 return false;
         }