Index: applications/editors/josm/plugins/utilsplugin2/build.xml
===================================================================
--- applications/editors/josm/plugins/utilsplugin2/build.xml	(revision 28179)
+++ applications/editors/josm/plugins/utilsplugin2/build.xml	(revision 28222)
@@ -30,5 +30,5 @@
 <project name="utilsplugin2" default="dist" basedir=".">
     <!-- enter the SVN commit message -->
-    <property name="commit.message" value="Utilsplugin2: search speed-up, added adjacent and connected keywords (search for ways only)"/>
+    <property name="commit.message" value="Utilsplugin2: all inside multipolygon selection - fixed"/>
     <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
     <property name="plugin.main.version" value="4980"/>
Index: applications/editors/josm/plugins/utilsplugin2/images_nodist/icons.copyright
===================================================================
--- applications/editors/josm/plugins/utilsplugin2/images_nodist/icons.copyright	(revision 28222)
+++ applications/editors/josm/plugins/utilsplugin2/images_nodist/icons.copyright	(revision 28222)
@@ -0,0 +1,5 @@
+Preferences/utils.png:
+
+http://ca.wikipedia.org/wiki/Fitxer:Icon_tools.png
+http://www.icon-king.com/projects/nuvola/
+Autor	David Vignoni 
Index: applications/editors/josm/plugins/utilsplugin2/nbproject/project.xml
===================================================================
--- applications/editors/josm/plugins/utilsplugin2/nbproject/project.xml	(revision 28179)
+++ applications/editors/josm/plugins/utilsplugin2/nbproject/project.xml	(revision 28222)
@@ -22,7 +22,4 @@
                     <encoding>UTF-8</encoding>
                 </source-folder>
-                <build-file>
-                    <location>../../dist/utilsplugin2.jar</location>
-                </build-file>
             </folders>
             <ide-actions>
@@ -45,9 +42,4 @@
                 </action>
             </ide-actions>
-            <export>
-                <type>jar</type>
-                <location>../../dist/utilsplugin2.jar</location>
-                <build-target>dist</build-target>
-            </export>
             <view>
                 <items>
@@ -74,5 +66,4 @@
                 <package-root>src</package-root>
                 <classpath mode="compile">../../core/src</classpath>
-                <built-to>../../dist/utilsplugin2.jar</built-to>
                 <source-level>1.6</source-level>
             </compilation-unit>
Index: applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/NodeWayUtils.java
===================================================================
--- applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/NodeWayUtils.java	(revision 28179)
+++ applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/NodeWayUtils.java	(revision 28222)
@@ -359,5 +359,6 @@
             List<Node> polyNodes = way.getNodes();
             // converts all points to EastNorth
-            for (Node n: polyNodes) polyPoints.add(n.getEastNorth());  
+            for (Node n: polyNodes) polyPoints.add(n.getEastNorth());
+            polyPoints.add(null); // next segment indicator
         }
         
@@ -368,5 +369,5 @@
         for (Node n : searchNodes) {
             //if (Geometry.nodeInsidePolygon(n, polyNodes)) {
-            if (NodeWayUtils.isPointInsidePolygon(n.getEastNorth(), polyPoints)>0) {
+            if (NodeWayUtils.isPointInsidePolygon(n.getEastNorth(), polyPoints)) {
                 newestNodes.add(n);
             }
@@ -392,5 +393,5 @@
         BBox box = way.getBBox();
         List<Node> polyNodes = way.getNodes();
-        List<EastNorth> polyPoints = new ArrayList<EastNorth>(polyNodes.size());
+        List<EastNorth> polyPoints = new ArrayList<EastNorth>(polyNodes.size()+5);
         
         // converts all points to EastNorth
@@ -402,5 +403,5 @@
         for (Node n : searchNodes) {
             //if (Geometry.nodeInsidePolygon(n, polyNodes)) {
-            if (NodeWayUtils.isPointInsidePolygon(n.getEastNorth(), polyPoints)>0) {
+            if (NodeWayUtils.isPointInsidePolygon(n.getEastNorth(), polyPoints)) {
                 newestNodes.add(n);
             }
@@ -422,19 +423,31 @@
     }
     
+    public static boolean isPointInsidePolygon(EastNorth point, List<EastNorth> polygonPoints) {
+        int n = getRayIntersectionsCount(point, polygonPoints);
+        if (n<0) return true; // we are near node or near edge
+        return (n%2==1);
+    }
+    
     /**
      * @return 0 =  not inside polygon, 1 = strictly inside, 2 = near edge, 3 = near vertex
      */
-    public static int isPointInsidePolygon(EastNorth point, List<EastNorth> polygonPoints) {
+    public static int getRayIntersectionsCount(EastNorth point, List<EastNorth> polygonPoints) {
         int n=polygonPoints.size();
-        EastNorth oldPoint = polygonPoints.get(n-1);
+        if (point==null) return 0;
+        EastNorth oldPoint = null;
+                //polygonPoints.get(n-1);
         double n1,n2,n3,e1,e2,e3,d;
         int interCount=0;
         
         for (EastNorth curPoint : polygonPoints) {
+            if (oldPoint==null || curPoint==null) {
+                oldPoint = curPoint;
+                continue;
+            }
             n1 = curPoint.north(); n2 = oldPoint.north();  n3 =  point.north();
             e1 = curPoint.east(); e2 = oldPoint.east();  e3 =  point.east();
             
-            if (Math.abs(n1-n3)<1e-5 && Math.abs(e1-e3)<1e-5) return 3; // vertex
-            if (Math.abs(n2-n3)<1e-5 && Math.abs(e2-e3)<1e-5) return 3; // vertex
+            if (Math.abs(n1-n3)<1e-5 && Math.abs(e1-e3)<1e-5) return -3; // vertex
+            if (Math.abs(n2-n3)<1e-5 && Math.abs(e2-e3)<1e-5) return -3; // vertex
             
             // looking at oldPoint-curPoint segment
@@ -445,10 +458,10 @@
                     if (d<-1e-5) {
                         interCount++; // there is OX intersecthion at e = (e1n2-e2n1)/(n2-n1) >=0
-                    } else if (d<=1e-5) return 2; // boundary detected
+                    } else if (d<=1e-5) return -2; // boundary detected
                 }
             } else if (n1 == n2) {
                 if (n1 == n3) {
                     e1-=e3; e2-=e3;
-                    if ((e1 <=0 && e2 >= 0) || (e1 >=0 && e2 <= 0)) return 2;// boundary detected
+                    if ((e1 <=0 && e2 >= 0) || (e1 >=0 && e2 <= 0)) return -2;// boundary detected
                 }
             } else {
@@ -458,11 +471,11 @@
                     if (d>1e-5) {
                         interCount++; // there is OX intersecthion at e = (e1n2-e2n1)/(n2-n1) >=0
-                    } else if (d>=-1e-5) return 2; // boundary detected
+                    } else if (d>=-1e-5) return -2; // boundary detected
                 }
             }
             oldPoint = curPoint;
         }
-       // System.out.printf("Intersected intercount %d %s\n",interCount, point.toString());
-        if (interCount%2 == 1) return 1; else return 0;
+        // System.out.printf("Intersected intercount %d %s\n",interCount, point.toString());
+        return interCount;
     }
     
