Index: trunk/test/data/orthogonalize.osm
===================================================================
--- trunk/test/data/orthogonalize.osm	(revision 9924)
+++ trunk/test/data/orthogonalize.osm	(revision 9925)
@@ -1,53 +1,95 @@
 <?xml version='1.0' encoding='UTF-8'?>
-<osm version='0.6' upload='true' generator='JOSM'>
-  <node id='-444' action='modify' visible='true' lat='8.53882631502' lon='55.72982273659' />
-  <node id='-446' action='modify' visible='true' lat='8.53692765033' lon='55.73148512506' />
-  <node id='-448' action='modify' visible='true' lat='8.53901816563' lon='55.7313279173' />
-  <node id='-450' action='modify' visible='true' lat='8.53673579867' lon='55.72997994436' />
-  <node id='-452' action='modify' visible='true' lat='8.53609408724' lon='55.73073587955' />
-  <node id='-454' action='modify' visible='true' lat='8.5381846071' lon='55.73057867179' />
-  <node id='-456' action='modify' visible='true' lat='8.534711427' lon='55.73000670312'>
+<osm version='0.6' upload='false' generator='JOSM'>
+  <node id='-164' action='modify' visible='true' lat='8.53882631502' lon='55.72982273659' />
+  <node id='-166' action='modify' visible='true' lat='8.53692765033' lon='55.73148512506' />
+  <node id='-168' action='modify' visible='true' lat='8.53901816563' lon='55.7313279173' />
+  <node id='-170' action='modify' visible='true' lat='8.53673579867' lon='55.72997994436' />
+  <node id='-172' action='modify' visible='true' lat='8.53609408724' lon='55.73073587955' />
+  <node id='-174' action='modify' visible='true' lat='8.5381846071' lon='55.73057867179' />
+  <node id='-176' action='modify' visible='true' lat='8.534711427' lon='55.73000670312'>
     <tag k='entrance' v='yes' />
     <tag k='name' v='ClosedWayWithReferenceNodes' />
   </node>
-  <node id='-458' action='modify' visible='true' lat='8.53545899034' lon='55.7305284991' />
-  <node id='-460' action='modify' visible='true' lat='8.5395738703' lon='55.73034453257' />
-  <node id='-462' action='modify' visible='true' lat='8.53490327967' lon='55.73151188383' />
-  <node id='-464' action='modify' visible='true' lat='8.53748335805' lon='55.73050174033' />
-  <node id='-466' action='modify' visible='true' lat='8.53406971216' lon='55.73076263832'>
+  <node id='-178' action='modify' visible='true' lat='8.53545899034' lon='55.7305284991' />
+  <node id='-180' action='modify' visible='true' lat='8.5395738703' lon='55.73034453257' />
+  <node id='-182' action='modify' visible='true' lat='8.53490327967' lon='55.73151188383' />
+  <node id='-184' action='modify' visible='true' lat='8.53748335805' lon='55.73050174033' />
+  <node id='-186' action='modify' visible='true' lat='8.53406971216' lon='55.73076263832'>
     <tag k='entrance' v='yes' />
     <tag k='name' v='ClosedWayWithReferenceNodes' />
   </node>
-  <way id='-468' action='modify' visible='true'>
-    <nd ref='-444' />
-    <nd ref='-460' />
-    <nd ref='-448' />
-    <nd ref='-454' />
-    <nd ref='-444' />
+  <node id='-188' action='modify' visible='true' lat='8.53273196095' lon='55.72987441027'>
+    <tag k='entrance' v='yes' />
+    <tag k='name' v='NodeToRectify-01' />
+  </node>
+  <node id='-190' action='modify' visible='true' lat='8.53347952816' lon='55.73039620625'>
+    <tag k='entrance' v='yes' />
+    <tag k='name' v='NodeToRectify-02' />
+  </node>
+  <node id='-192' action='modify' visible='true' lat='8.53292381462' lon='55.73137959098'>
+    <tag k='entrance' v='yes' />
+    <tag k='name' v='NodeToRectify-03' />
+  </node>
+  <node id='-194' action='modify' visible='true' lat='8.53209024278' lon='55.73063034547'>
+    <tag k='entrance' v='yes' />
+    <tag k='name' v='NodeToRectify-04' />
+  </node>
+  <node id='-196' action='modify' visible='true' lat='8.53332193268' lon='55.73067508568' />
+  <node id='-198' action='modify' visible='true' lat='8.53308888534' lon='55.73108748376' />
+  <node id='-200' action='modify' visible='true' lat='8.53317579063' lon='55.73111687863' />
+  <node id='-202' action='modify' visible='true' lat='8.53326720503' lon='55.73111040645' />
+  <node id='-204' action='modify' visible='true' lat='8.53334921153' lon='55.73106905258' />
+  <node id='-206' action='modify' visible='true' lat='8.5334093254' lon='55.73099911274' />
+  <node id='-208' action='modify' visible='true' lat='8.53343839484' lon='55.73091123466' />
+  <node id='-210' action='modify' visible='true' lat='8.53343199432' lon='55.73081879697' />
+  <node id='-212' action='modify' visible='true' lat='8.53339109825' lon='55.73073587248' />
+  <way id='-214' action='modify' visible='true'>
+    <nd ref='-164' />
+    <nd ref='-180' />
+    <nd ref='-168' />
+    <nd ref='-174' />
+    <nd ref='-164' />
     <tag k='building' v='yes' />
     <tag k='name' v='ClosedWay' />
   </way>
-  <way id='-470' action='modify' visible='true'>
-    <nd ref='-450' />
-    <nd ref='-464' />
-    <nd ref='-446' />
+  <way id='-216' action='modify' visible='true'>
+    <nd ref='-170' />
+    <nd ref='-184' />
+    <nd ref='-166' />
     <tag k='building' v='yes' />
     <tag k='name' v='TwoWaysFormingClosedWay' />
   </way>
-  <way id='-472' action='modify' visible='true'>
-    <nd ref='-456' />
-    <nd ref='-458' />
-    <nd ref='-462' />
-    <nd ref='-466' />
-    <nd ref='-456' />
+  <way id='-218' action='modify' visible='true'>
+    <nd ref='-176' />
+    <nd ref='-178' />
+    <nd ref='-182' />
+    <nd ref='-186' />
+    <nd ref='-176' />
     <tag k='building' v='yes' />
     <tag k='name' v='ClosedWayWithReferenceNodes' />
   </way>
-  <way id='-474' action='modify' visible='true'>
-    <nd ref='-446' />
-    <nd ref='-452' />
-    <nd ref='-450' />
+  <way id='-220' action='modify' visible='true'>
+    <nd ref='-166' />
+    <nd ref='-172' />
+    <nd ref='-170' />
     <tag k='building' v='yes' />
     <tag k='name' v='TwoWaysFormingClosedWay' />
   </way>
+  <way id='-222' action='modify' visible='true'>
+    <nd ref='-188' />
+    <nd ref='-190' />
+    <nd ref='-196' />
+    <nd ref='-212' />
+    <nd ref='-210' />
+    <nd ref='-208' />
+    <nd ref='-206' />
+    <nd ref='-204' />
+    <nd ref='-202' />
+    <nd ref='-200' />
+    <nd ref='-198' />
+    <nd ref='-192' />
+    <nd ref='-194' />
+    <nd ref='-188' />
+    <tag k='building' v='yes' />
+  </way>
 </osm>
Index: trunk/test/unit/org/openstreetmap/josm/actions/OrthogonalizeActionTest.java
===================================================================
--- trunk/test/unit/org/openstreetmap/josm/actions/OrthogonalizeActionTest.java	(revision 9924)
+++ trunk/test/unit/org/openstreetmap/josm/actions/OrthogonalizeActionTest.java	(revision 9925)
@@ -5,4 +5,6 @@
 
 import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.junit.BeforeClass;
@@ -13,4 +15,5 @@
 import org.openstreetmap.josm.data.coor.LatLon;
 import org.openstreetmap.josm.data.osm.DataSet;
+import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
@@ -69,8 +72,21 @@
     }
 
-    DataSet performTest(String search) throws Exception {
+    @Test
+    public void testFourNodes() throws Exception {
+        final DataSet ds = performTest(
+                "name=NodeToRectify-01", "name=NodeToRectify-02", "name=NodeToRectify-03", "name=NodeToRectify-04");
+        final List<Node> nodes = new ArrayList<>(ds.getSelectedNodes());
+        assertEquals(new LatLon(8.532735415272217, 55.72986948949525), nodes.get(0).getCoor());
+        assertEquals(new LatLon(8.533520827858515, 55.73043325105434), nodes.get(1).getCoor());
+        assertEquals(new LatLon(8.532914283300173, 55.73129729115582), nodes.get(2).getCoor());
+        assertEquals(new LatLon(8.532055019939826, 55.73068052126457), nodes.get(3).getCoor());
+    }
+
+    DataSet performTest(String... search) throws Exception {
         try (FileInputStream in = new FileInputStream(TestUtils.getTestDataRoot() + "orthogonalize.osm")) {
             final DataSet ds = OsmReader.parseDataSet(in, null);
-            ds.setSelected(Utils.filter(ds.allPrimitives(), SearchCompiler.compile(search)));
+            for (String s : search) {
+                ds.addSelected(Utils.filter(ds.allPrimitives(), SearchCompiler.compile(s)));
+            }
             OrthogonalizeAction.orthogonalize(ds.getSelected()).executeCommand();
             return ds;
