Changeset 28222 in osm for applications/editors/josm
- Timestamp:
- 2012-04-08T09:29:08+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin2
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/build.xml
r28028 r28222 30 30 <project name="utilsplugin2" default="dist" basedir="."> 31 31 <!-- enter the SVN commit message --> 32 <property name="commit.message" value="Utilsplugin2: search speed-up, added adjacent and connected keywords (search for ways only)"/>32 <property name="commit.message" value="Utilsplugin2: all inside multipolygon selection - fixed"/> 33 33 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 34 34 <property name="plugin.main.version" value="4980"/> -
applications/editors/josm/plugins/utilsplugin2/nbproject/project.xml
r27417 r28222 22 22 <encoding>UTF-8</encoding> 23 23 </source-folder> 24 <build-file>25 <location>../../dist/utilsplugin2.jar</location>26 </build-file>27 24 </folders> 28 25 <ide-actions> … … 45 42 </action> 46 43 </ide-actions> 47 <export>48 <type>jar</type>49 <location>../../dist/utilsplugin2.jar</location>50 <build-target>dist</build-target>51 </export>52 44 <view> 53 45 <items> … … 74 66 <package-root>src</package-root> 75 67 <classpath mode="compile">../../core/src</classpath> 76 <built-to>../../dist/utilsplugin2.jar</built-to>77 68 <source-level>1.6</source-level> 78 69 </compilation-unit> -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/NodeWayUtils.java
r28028 r28222 359 359 List<Node> polyNodes = way.getNodes(); 360 360 // converts all points to EastNorth 361 for (Node n: polyNodes) polyPoints.add(n.getEastNorth()); 361 for (Node n: polyNodes) polyPoints.add(n.getEastNorth()); 362 polyPoints.add(null); // next segment indicator 362 363 } 363 364 … … 368 369 for (Node n : searchNodes) { 369 370 //if (Geometry.nodeInsidePolygon(n, polyNodes)) { 370 if (NodeWayUtils.isPointInsidePolygon(n.getEastNorth(), polyPoints) >0) {371 if (NodeWayUtils.isPointInsidePolygon(n.getEastNorth(), polyPoints)) { 371 372 newestNodes.add(n); 372 373 } … … 392 393 BBox box = way.getBBox(); 393 394 List<Node> polyNodes = way.getNodes(); 394 List<EastNorth> polyPoints = new ArrayList<EastNorth>(polyNodes.size() );395 List<EastNorth> polyPoints = new ArrayList<EastNorth>(polyNodes.size()+5); 395 396 396 397 // converts all points to EastNorth … … 402 403 for (Node n : searchNodes) { 403 404 //if (Geometry.nodeInsidePolygon(n, polyNodes)) { 404 if (NodeWayUtils.isPointInsidePolygon(n.getEastNorth(), polyPoints) >0) {405 if (NodeWayUtils.isPointInsidePolygon(n.getEastNorth(), polyPoints)) { 405 406 newestNodes.add(n); 406 407 } … … 422 423 } 423 424 425 public static boolean isPointInsidePolygon(EastNorth point, List<EastNorth> polygonPoints) { 426 int n = getRayIntersectionsCount(point, polygonPoints); 427 if (n<0) return true; // we are near node or near edge 428 return (n%2==1); 429 } 430 424 431 /** 425 432 * @return 0 = not inside polygon, 1 = strictly inside, 2 = near edge, 3 = near vertex 426 433 */ 427 public static int isPointInsidePolygon(EastNorth point, List<EastNorth> polygonPoints) {434 public static int getRayIntersectionsCount(EastNorth point, List<EastNorth> polygonPoints) { 428 435 int n=polygonPoints.size(); 429 EastNorth oldPoint = polygonPoints.get(n-1); 436 if (point==null) return 0; 437 EastNorth oldPoint = null; 438 //polygonPoints.get(n-1); 430 439 double n1,n2,n3,e1,e2,e3,d; 431 440 int interCount=0; 432 441 433 442 for (EastNorth curPoint : polygonPoints) { 443 if (oldPoint==null || curPoint==null) { 444 oldPoint = curPoint; 445 continue; 446 } 434 447 n1 = curPoint.north(); n2 = oldPoint.north(); n3 = point.north(); 435 448 e1 = curPoint.east(); e2 = oldPoint.east(); e3 = point.east(); 436 449 437 if (Math.abs(n1-n3)<1e-5 && Math.abs(e1-e3)<1e-5) return 3; // vertex438 if (Math.abs(n2-n3)<1e-5 && Math.abs(e2-e3)<1e-5) return 3; // vertex450 if (Math.abs(n1-n3)<1e-5 && Math.abs(e1-e3)<1e-5) return -3; // vertex 451 if (Math.abs(n2-n3)<1e-5 && Math.abs(e2-e3)<1e-5) return -3; // vertex 439 452 440 453 // looking at oldPoint-curPoint segment … … 445 458 if (d<-1e-5) { 446 459 interCount++; // there is OX intersecthion at e = (e1n2-e2n1)/(n2-n1) >=0 447 } else if (d<=1e-5) return 2; // boundary detected460 } else if (d<=1e-5) return -2; // boundary detected 448 461 } 449 462 } else if (n1 == n2) { 450 463 if (n1 == n3) { 451 464 e1-=e3; e2-=e3; 452 if ((e1 <=0 && e2 >= 0) || (e1 >=0 && e2 <= 0)) return 2;// boundary detected465 if ((e1 <=0 && e2 >= 0) || (e1 >=0 && e2 <= 0)) return -2;// boundary detected 453 466 } 454 467 } else { … … 458 471 if (d>1e-5) { 459 472 interCount++; // there is OX intersecthion at e = (e1n2-e2n1)/(n2-n1) >=0 460 } else if (d>=-1e-5) return 2; // boundary detected473 } else if (d>=-1e-5) return -2; // boundary detected 461 474 } 462 475 } 463 476 oldPoint = curPoint; 464 477 } 465 // System.out.printf("Intersected intercount %d %s\n",interCount, point.toString());466 if (interCount%2 == 1) return 1; else return 0;478 // System.out.printf("Intersected intercount %d %s\n",interCount, point.toString()); 479 return interCount; 467 480 } 468 481
Note:
See TracChangeset
for help on using the changeset viewer.