Index: src/org/openstreetmap/josm/actions/AlignInCircleAction.java
===================================================================
--- src/org/openstreetmap/josm/actions/AlignInCircleAction.java	(révision 6876)
+++ src/org/openstreetmap/josm/actions/AlignInCircleAction.java	(copie de travail)
@@ -112,9 +112,7 @@
 
         // special case if no single nodes are selected and exactly one way is:
         // then use the way's nodes
-        if ((nodes.size() <= 2) && (ways.size() == 1)) {
-            Way way = ways.get(0);
-
+        if ((nodes.size() <= 2) && checkWaysArePolygon(ways)) {
             // some more special combinations:
             // When is selected node that is part of the way, then make a regular polygon, selected
             // node doesn't move.
@@ -123,23 +121,38 @@
             // When one way and one node is selected, set center to position of that node.
             // When one more node, part of the way, is selected, set the radius equal to the
             // distance between two nodes.
-            if (nodes.size() > 0) {
-                if (nodes.size() == 1 && way.containsNode(nodes.get(0)) && allowRegularPolygon(way.getNodes())) {
-                    regular = true;
-                } else if (nodes.size() >= 2) {
-                    center = nodes.get(way.containsNode(nodes.get(0)) ? 1 : 0).getEastNorth();
-                    if (nodes.size() == 2) {
-                        radius = distance(nodes.get(0).getEastNorth(), nodes.get(1).getEastNorth());
-                    }
-                }
-                nodes.clear();
+        	if (nodes.size() == 1 && ways.size() == 1) {
+        		// Regular polygons are allowed only if there is just one way
+            	Way way = ways.get(0);
+                if (nodes.size() == 1 && way.containsNode(nodes.get(0)) && allowRegularPolygon(way.getNodes()))
+                	regular = true;
             }
+        	if (nodes.size() >= 1) {
+        		// First node not contained in any way will be center
+        		for (Node node: nodes) {
+        			boolean isContained = false;
+        			for (Way way: ways)
+        				if (way.containsNode(node)) {
+        					isContained = true;
+        					break;
+        				}
+        			if (!isContained) {
+        				center = node.getEastNorth();
+        				break;
+        			}
+        		}
+        	}
+        	if (nodes.size() == 2) {
+        		radius = distance(nodes.get(0).getEastNorth(), nodes.get(1).getEastNorth());
+        	}
+        	nodes.clear();
 
-            for (Node n : way.getNodes()) {
-                if (!nodes.contains(n)) {
-                    nodes.add(n);
-                }
-            }
+    		for(Way way: ways)
+    			for (Node n : way.getNodes()) {
+    				if (!nodes.contains(n)) {
+    					nodes.add(n);
+    				}
+    			}
         }
 
         if (nodes.size() < 4) {
@@ -261,4 +274,53 @@
         }
         return true;
     }
+
+    /**
+     * Determines if ways can be joined into a polygon.
+     * @param ways The ways collection to check
+     * @return true if all ways can be joined into a regular polygon
+     */
+    protected static boolean checkWaysArePolygon(Collection<Way> ways) {
+    	// For each way, nodes strictly between first and last should't be reference by an other way
+    	for(Way way: ways) {
+    		for(Node node: way.getNodes()) {
+    			if(node == way.firstNode() || node == way.lastNode()) continue;
+    			for(Way wayOther: ways) {
+    				if(way == wayOther) continue;
+    				if(node.getReferrers().contains(wayOther)) return false;
+    			}
+    		}
+    	}
+    	// Test if ways can be joined
+       	Way currentWay = null;
+    	Node startNode = null, endNode = null;
+    	int used = 0;
+    	while(true) {
+    		Way nextWay = null;
+    		for(Way w: ways) {
+    			if(w.firstNode() == w.lastNode()) return ways.size() == 1;
+    			if(w == currentWay) continue;
+        		if(currentWay == null) {
+        			nextWay = w;
+        			startNode = w.firstNode();
+        			endNode = w.lastNode();
+        			break;
+        		}
+    			if(w.firstNode() == endNode) {
+    				nextWay = w;
+    				endNode = w.lastNode();
+    				break;
+    			}
+    			if(w.lastNode() == endNode) {
+    				nextWay = w;
+    				endNode = w.firstNode();
+    				break;
+    			}
+    		}
+    		if(nextWay == null) return false;
+    		used += 1;
+    		currentWay = nextWay;
+    		if(endNode == startNode) return used == ways.size();
+    	}
+    }
 }
