Changeset 9925 in josm
- Timestamp:
- 2016-03-05T10:22:33+01:00 (9 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java
r9923 r9925 180 180 nodeList.add((Node) p); 181 181 } else if (p instanceof Way) { 182 wayDataList.add(new WayData(( Way) p));183 } else 182 wayDataList.add(new WayData(((Way) p).getNodes())); 183 } else { 184 184 throw new InvalidUserInputException(tr("Selection must consist only of ways and nodes.")); 185 } 186 if (wayDataList.isEmpty()) { 185 } 186 } 187 if (wayDataList.isEmpty() && !nodeList.isEmpty()) { 188 final WayData data = new WayData(nodeList); 189 final Collection<Command> commands = orthogonalize(Collections.singletonList(data), Collections.<Node>emptyList()); 190 return new SequenceCommand(tr("Orthogonalize"), commands); 191 } else if (wayDataList.isEmpty()) { 187 192 throw new InvalidUserInputException("usage"); 188 193 } else { … … 235 240 WayData candidate = remaining.get(i); 236 241 if (candidate == null) continue; 237 if (!Collections.disjoint(candidate.way .getNodes(), newGroupMember.way.getNodes())) {242 if (!Collections.disjoint(candidate.wayNodes, newGroupMember.wayNodes)) { 238 243 remaining.set(i, null); 239 244 extendGroupRec(group, candidate, remaining); … … 300 305 final Set<Node> allNodes = new HashSet<>(); 301 306 for (WayData w : wayDataList) { 302 for (Node n : w.way .getNodes()) {307 for (Node n : w.wayNodes) { 303 308 allNodes.add(n); 304 309 } … … 345 350 for (WayData w : wayDataList) { 346 351 for (int i = 0; i < w.nSeg; ++i) { 347 Node n1 = w.way .getNodes().get(i);348 Node n2 = w.way .getNodes().get(i+1);352 Node n1 = w.wayNodes.get(i); 353 Node n2 = w.wayNodes.get(i+1); 349 354 if (Arrays.asList(orientation).contains(w.segDirections[i])) { 350 355 if (cs.contains(n1) && !cs.contains(n2)) { … … 417 422 */ 418 423 private static class WayData { 419 public final Way way; // The assigned way424 public final List<Node> wayNodes; // The assigned way 420 425 public final int nSeg; // Number of Segments of the Way 421 426 public final int nNode; // Number of Nodes of the Way … … 426 431 public double heading; // heading of segSum == approximate heading of the way 427 432 428 WayData( Way pWay) {429 way = pWay;430 nNode = way.getNodes().size();431 nSeg = nNode - 1;433 WayData(List<Node> wayNodes) { 434 this.wayNodes = wayNodes; 435 this.nNode = wayNodes.size(); 436 this.nSeg = nNode - 1; 432 437 } 433 438 … … 441 446 */ 442 447 public void calcDirections(Direction pInitialDirection) throws InvalidUserInputException { 443 final EastNorth[] en = new EastNorth[nNode]; // alias: way .getNodes().get(i).getEastNorth() ---> en[i]448 final EastNorth[] en = new EastNorth[nNode]; // alias: wayNodes.get(i).getEastNorth() ---> en[i] 444 449 for (int i = 0; i < nNode; i++) { 445 en[i] = new EastNorth(way.getNodes().get(i).getEastNorth().east(), way.getNodes().get(i).getEastNorth().north());450 en[i] = wayNodes.get(i).getEastNorth(); 446 451 } 447 452 segDirections = new Direction[nSeg]; -
trunk/test/data/orthogonalize.osm
r9923 r9925 1 1 <?xml version='1.0' encoding='UTF-8'?> 2 <osm version='0.6' upload=' true' generator='JOSM'>3 <node id='- 444' action='modify' visible='true' lat='8.53882631502' lon='55.72982273659' />4 <node id='- 446' action='modify' visible='true' lat='8.53692765033' lon='55.73148512506' />5 <node id='- 448' action='modify' visible='true' lat='8.53901816563' lon='55.7313279173' />6 <node id='- 450' action='modify' visible='true' lat='8.53673579867' lon='55.72997994436' />7 <node id='- 452' action='modify' visible='true' lat='8.53609408724' lon='55.73073587955' />8 <node id='- 454' action='modify' visible='true' lat='8.5381846071' lon='55.73057867179' />9 <node id='- 456' action='modify' visible='true' lat='8.534711427' lon='55.73000670312'>2 <osm version='0.6' upload='false' generator='JOSM'> 3 <node id='-164' action='modify' visible='true' lat='8.53882631502' lon='55.72982273659' /> 4 <node id='-166' action='modify' visible='true' lat='8.53692765033' lon='55.73148512506' /> 5 <node id='-168' action='modify' visible='true' lat='8.53901816563' lon='55.7313279173' /> 6 <node id='-170' action='modify' visible='true' lat='8.53673579867' lon='55.72997994436' /> 7 <node id='-172' action='modify' visible='true' lat='8.53609408724' lon='55.73073587955' /> 8 <node id='-174' action='modify' visible='true' lat='8.5381846071' lon='55.73057867179' /> 9 <node id='-176' action='modify' visible='true' lat='8.534711427' lon='55.73000670312'> 10 10 <tag k='entrance' v='yes' /> 11 11 <tag k='name' v='ClosedWayWithReferenceNodes' /> 12 12 </node> 13 <node id='- 458' action='modify' visible='true' lat='8.53545899034' lon='55.7305284991' />14 <node id='- 460' action='modify' visible='true' lat='8.5395738703' lon='55.73034453257' />15 <node id='- 462' action='modify' visible='true' lat='8.53490327967' lon='55.73151188383' />16 <node id='- 464' action='modify' visible='true' lat='8.53748335805' lon='55.73050174033' />17 <node id='- 466' action='modify' visible='true' lat='8.53406971216' lon='55.73076263832'>13 <node id='-178' action='modify' visible='true' lat='8.53545899034' lon='55.7305284991' /> 14 <node id='-180' action='modify' visible='true' lat='8.5395738703' lon='55.73034453257' /> 15 <node id='-182' action='modify' visible='true' lat='8.53490327967' lon='55.73151188383' /> 16 <node id='-184' action='modify' visible='true' lat='8.53748335805' lon='55.73050174033' /> 17 <node id='-186' action='modify' visible='true' lat='8.53406971216' lon='55.73076263832'> 18 18 <tag k='entrance' v='yes' /> 19 19 <tag k='name' v='ClosedWayWithReferenceNodes' /> 20 20 </node> 21 <way id='-468' action='modify' visible='true'> 22 <nd ref='-444' /> 23 <nd ref='-460' /> 24 <nd ref='-448' /> 25 <nd ref='-454' /> 26 <nd ref='-444' /> 21 <node id='-188' action='modify' visible='true' lat='8.53273196095' lon='55.72987441027'> 22 <tag k='entrance' v='yes' /> 23 <tag k='name' v='NodeToRectify-01' /> 24 </node> 25 <node id='-190' action='modify' visible='true' lat='8.53347952816' lon='55.73039620625'> 26 <tag k='entrance' v='yes' /> 27 <tag k='name' v='NodeToRectify-02' /> 28 </node> 29 <node id='-192' action='modify' visible='true' lat='8.53292381462' lon='55.73137959098'> 30 <tag k='entrance' v='yes' /> 31 <tag k='name' v='NodeToRectify-03' /> 32 </node> 33 <node id='-194' action='modify' visible='true' lat='8.53209024278' lon='55.73063034547'> 34 <tag k='entrance' v='yes' /> 35 <tag k='name' v='NodeToRectify-04' /> 36 </node> 37 <node id='-196' action='modify' visible='true' lat='8.53332193268' lon='55.73067508568' /> 38 <node id='-198' action='modify' visible='true' lat='8.53308888534' lon='55.73108748376' /> 39 <node id='-200' action='modify' visible='true' lat='8.53317579063' lon='55.73111687863' /> 40 <node id='-202' action='modify' visible='true' lat='8.53326720503' lon='55.73111040645' /> 41 <node id='-204' action='modify' visible='true' lat='8.53334921153' lon='55.73106905258' /> 42 <node id='-206' action='modify' visible='true' lat='8.5334093254' lon='55.73099911274' /> 43 <node id='-208' action='modify' visible='true' lat='8.53343839484' lon='55.73091123466' /> 44 <node id='-210' action='modify' visible='true' lat='8.53343199432' lon='55.73081879697' /> 45 <node id='-212' action='modify' visible='true' lat='8.53339109825' lon='55.73073587248' /> 46 <way id='-214' action='modify' visible='true'> 47 <nd ref='-164' /> 48 <nd ref='-180' /> 49 <nd ref='-168' /> 50 <nd ref='-174' /> 51 <nd ref='-164' /> 27 52 <tag k='building' v='yes' /> 28 53 <tag k='name' v='ClosedWay' /> 29 54 </way> 30 <way id='- 470' action='modify' visible='true'>31 <nd ref='- 450' />32 <nd ref='- 464' />33 <nd ref='- 446' />55 <way id='-216' action='modify' visible='true'> 56 <nd ref='-170' /> 57 <nd ref='-184' /> 58 <nd ref='-166' /> 34 59 <tag k='building' v='yes' /> 35 60 <tag k='name' v='TwoWaysFormingClosedWay' /> 36 61 </way> 37 <way id='- 472' action='modify' visible='true'>38 <nd ref='- 456' />39 <nd ref='- 458' />40 <nd ref='- 462' />41 <nd ref='- 466' />42 <nd ref='- 456' />62 <way id='-218' action='modify' visible='true'> 63 <nd ref='-176' /> 64 <nd ref='-178' /> 65 <nd ref='-182' /> 66 <nd ref='-186' /> 67 <nd ref='-176' /> 43 68 <tag k='building' v='yes' /> 44 69 <tag k='name' v='ClosedWayWithReferenceNodes' /> 45 70 </way> 46 <way id='- 474' action='modify' visible='true'>47 <nd ref='- 446' />48 <nd ref='- 452' />49 <nd ref='- 450' />71 <way id='-220' action='modify' visible='true'> 72 <nd ref='-166' /> 73 <nd ref='-172' /> 74 <nd ref='-170' /> 50 75 <tag k='building' v='yes' /> 51 76 <tag k='name' v='TwoWaysFormingClosedWay' /> 52 77 </way> 78 <way id='-222' action='modify' visible='true'> 79 <nd ref='-188' /> 80 <nd ref='-190' /> 81 <nd ref='-196' /> 82 <nd ref='-212' /> 83 <nd ref='-210' /> 84 <nd ref='-208' /> 85 <nd ref='-206' /> 86 <nd ref='-204' /> 87 <nd ref='-202' /> 88 <nd ref='-200' /> 89 <nd ref='-198' /> 90 <nd ref='-192' /> 91 <nd ref='-194' /> 92 <nd ref='-188' /> 93 <tag k='building' v='yes' /> 94 </way> 53 95 </osm> -
trunk/test/unit/org/openstreetmap/josm/actions/OrthogonalizeActionTest.java
r9924 r9925 5 5 6 6 import java.io.FileInputStream; 7 import java.util.ArrayList; 8 import java.util.List; 7 9 8 10 import org.junit.BeforeClass; … … 13 15 import org.openstreetmap.josm.data.coor.LatLon; 14 16 import org.openstreetmap.josm.data.osm.DataSet; 17 import org.openstreetmap.josm.data.osm.Node; 15 18 import org.openstreetmap.josm.data.osm.Way; 16 19 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 69 72 } 70 73 71 DataSet performTest(String search) throws Exception { 74 @Test 75 public void testFourNodes() throws Exception { 76 final DataSet ds = performTest( 77 "name=NodeToRectify-01", "name=NodeToRectify-02", "name=NodeToRectify-03", "name=NodeToRectify-04"); 78 final List<Node> nodes = new ArrayList<>(ds.getSelectedNodes()); 79 assertEquals(new LatLon(8.532735415272217, 55.72986948949525), nodes.get(0).getCoor()); 80 assertEquals(new LatLon(8.533520827858515, 55.73043325105434), nodes.get(1).getCoor()); 81 assertEquals(new LatLon(8.532914283300173, 55.73129729115582), nodes.get(2).getCoor()); 82 assertEquals(new LatLon(8.532055019939826, 55.73068052126457), nodes.get(3).getCoor()); 83 } 84 85 DataSet performTest(String... search) throws Exception { 72 86 try (FileInputStream in = new FileInputStream(TestUtils.getTestDataRoot() + "orthogonalize.osm")) { 73 87 final DataSet ds = OsmReader.parseDataSet(in, null); 74 ds.setSelected(Utils.filter(ds.allPrimitives(), SearchCompiler.compile(search))); 88 for (String s : search) { 89 ds.addSelected(Utils.filter(ds.allPrimitives(), SearchCompiler.compile(s))); 90 } 75 91 OrthogonalizeAction.orthogonalize(ds.getSelected()).executeCommand(); 76 92 return ds;
Note:
See TracChangeset
for help on using the changeset viewer.