Index: applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/WronglyOrderedWays.java
===================================================================
--- applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/WronglyOrderedWays.java	(revision 8816)
+++ applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/WronglyOrderedWays.java	(revision 8904)
@@ -16,17 +16,15 @@
 /**
  * Check cyclic ways for errors
- * 
+ *
  * @author jrreid
  */
 public class WronglyOrderedWays extends Test  {
-    /** All ways, grouped by cells */
-    Map<Point2D,List<Way>> _cellWays;
-    /** The already detected errors */
-    Bag<Way, Way> _errorWays;
+	/** The already detected errors */
+	Bag<Way, Way> _errorWays;
 
 	/**
 	 * Constructor
 	 */
-	public WronglyOrderedWays() 
+	public WronglyOrderedWays()
 	{
 		super(tr("Wrongly Ordered Ways."),
@@ -34,88 +32,66 @@
 	}
 
-    @Override
-    public void startTest() 
-    {
-        _cellWays = new HashMap<Point2D,List<Way>>(1000);
-        _errorWays = new Bag<Way, Way>();
-    }
+	@Override
+	public void startTest()
+	{
+		_errorWays = new Bag<Way, Way>();
+	}
 
-    @Override
-    public void endTest() 
-    {
-        _cellWays = null;
-        _errorWays = null;
-    }
-    
 	@Override
-	public void visit(Way w) 
+	public void endTest()
+	{
+		_errorWays = null;
+	}
+	
+	@Override
+	public void visit(Way w)
 	{
 		String errortype = "";
 		
-        if( w.deleted || w.incomplete )
-            return;
-        
-        String natural = w.get("natural");
-        if( natural == null)
-            return;
-        
-        if(!natural.equals("coastline") ){
-        	errortype = "Clockwise coastline";
-        }else if(!natural.equals("water") ){
-        	errortype = "Clockwise water";
-        }else if(!natural.equals("land") ){
-        	errortype = "Clockwise land";
-        } else {
-        	return;
-        }
-        
-        /**
-         * Test the directionality of the way
-         * 
-         * Checks if the node following the northern-most node is further 
-         * west then the node previous
-         * 
-         * Only tests ways that the first and last node is the same currently
-         * 
-         */
-        
-        if(w.nodes.get(0) == w.nodes.get(w.nodes.size()-1)){
-	        int maxnode = -1;
-	        double maxlat = -90; 
-	        
-	        for (int node = 0; node < w.nodes.size(); node++){
-	        	double lat = w.nodes.get(node).coor.lat();
-	        	if(lat > maxlat){
-	        		maxnode = node;
-	        		maxlat = lat;
-	        	}
-	        }	        
-	        
-        	int nextnode;
-        	int prevnode;
-        	
-        	// Determine the previous and next nodes in the loop
-        	if(maxnode==0){
-        		nextnode = 1;
-    			prevnode = w.nodes.size()-1;
-        	}else if(maxnode == w.nodes.size()-1){
-        		nextnode = 0;
-    			prevnode = maxnode - 1;
-        	} else {
-        		nextnode = maxnode + 1;
-        		prevnode = maxnode - 1;
-        	}
-        	
-        	double prevlon = w.nodes.get(prevnode).coor.lon();
-        	double nextlon = w.nodes.get(nextnode).coor.lon();
-        	
-        	if(((natural.equals("coastline") || natural.equals("land")) && prevlon < nextlon) 
-        			|| (natural.equals("water") && prevlon > nextlon)){	        
-	        	List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>();
-	        	primitives.add(w);
-	        	errors.add( new TestError(this, Severity.WARNING, tr(errortype), primitives) );
-	        	_errorWays.add(w,w);		
-        	}        
-        }
+		if( w.deleted || w.incomplete )
+			return;
+		
+		String natural = w.get("natural");
+		if( natural == null)
+			return;
+		
+		if( natural.equals("coastline") )
+			errortype = tr("Reversed coastline: land not on left side");
+		else if(natural.equals("water") )
+			errortype = tr("Reversed water: land not on left side");
+		else if( natural.equals("land") )
+			errortype = tr("Reversed land: land not on left side");
+		else
+			return;
+
+
+		/**
+		 * Test the directionality of the way
+		 *
+		 * Assuming a closed non-looping way, compute twice the area
+		 * of the polygon using the formula 2*a = sum (Xn * Yn+1 - Xn+1 * Yn)
+		 * If the area is negative the way is ordered in a clockwise direction
+		 *
+		 */
+
+		if(w.nodes.get(0) == w.nodes.get(w.nodes.size()-1))
+		{
+			double area2 = 0;
+
+			for (int node = 1; node < w.nodes.size(); node++)
+			{
+				area2 += (w.nodes.get(node-1).coor.lon() * w.nodes.get(node).coor.lat()
+				- w.nodes.get(node).coor.lon() * w.nodes.get(node-1).coor.lat());
+			}
+
+			if(((natural.equals("coastline") || natural.equals("land")) && area2 < 0.)
+			|| (natural.equals("water") && area2 > 0.))
+			{
+				List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>();
+				primitives.add(w);
+				errors.add( new TestError(this, Severity.WARNING, errortype, primitives) );
+				_errorWays.add(w,w);
+			}
+		}
 	}
 }
