[Opencadtools-commits] r160 - trunk/extCAD/src/com/iver/cit/gvsig/gui/cad/tools

fpuga at osor.eu fpuga at osor.eu
Thu Aug 25 23:20:43 CEST 2011


Author: fpuga
Date: 2011-08-25 23:20:42 +0200 (Thu, 25 Aug 2011)
New Revision: 160

Modified:
   trunk/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/CutPolygonCADTool.java
Log:
CutPolygon previously puts the last node of the geometry over the first one,
now it works correctly and closes the pathiterator

Modified: trunk/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/CutPolygonCADTool.java
===================================================================
--- trunk/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/CutPolygonCADTool.java	2011-08-23 16:00:50 UTC (rev 159)
+++ trunk/extCAD/src/com/iver/cit/gvsig/gui/cad/tools/CutPolygonCADTool.java	2011-08-25 21:20:42 UTC (rev 160)
@@ -251,7 +251,7 @@
 //			Painting the line so that user choose the next point
 			if (secondPoint==null) {
 				GeneralPathX gpx=new GeneralPathX();
-				for(int i = 0; i<oldPoints.size(); i++){
+		for (int i = 0; i < oldPoints.size() - 1; i++) {
 					Point2D point = (Point2D) oldPoints.get(i);
 					if (i==0) {
 						gpx.moveTo(point.getX(),point.getY());
@@ -259,6 +259,7 @@
 						gpx.lineTo(point.getX(),point.getY());
 					}
 				}
+		gpx.closePath();
 				IGeometry geom=ShapeFactory.createPolygon2D(gpx);
 				geom.draw((Graphics2D)g,CADExtension.getEditionManager().getMapControl().getViewPort(),DefaultCADTool.drawingSymbol);
 
@@ -597,7 +598,7 @@
 						multiSelected = numberMultiActual;
 						isInside = true;
 					}
-					oldPoints.add(index,new Point2D.Double(first.x, first.y));
+		    oldPoints.add(index, new Point2D.Double(first.x, first.y));
 					from = first;
 					break;
 
@@ -925,9 +926,9 @@
 							// reverse = T y condition = T
 //							We have to cover first the points between the second and the first
 //							index and then the introduced by the user
-							for (int i = oldPoints.size()-1;i>=secondCutIndex;i--) {
+			    for (int i = oldPoints.size() - 2; i >= secondCutIndex; i--) {
 								Point2D point = (Point2D) oldPoints.get(i);
-								if (i==oldPoints.size()-1){
+				if (i == oldPoints.size() - 2) {
 									System.out.println("moveTo: "+ point.getX() + ", " + point.getY());
 									gpx.moveTo(point.getX(),point.getY());
 								} else{
@@ -972,12 +973,13 @@
 							}
 						} else {
 							// [NachoV] reverse = F y condition = T
-							for (int i = secondCutIndex;i<oldPoints.size();i++){
+			    for (int i = secondCutIndex; i < oldPoints.size() - 1; i++) {
 								Point2D point = (Point2D) oldPoints.get(i);
 								System.out.println(point.getX() + ", " + point.getY());
 								gpx.lineTo(point.getX(),point.getY());
 							}
 						}
+			gpx.closePath();
 
 					} else {
 						// condition = F
@@ -1044,9 +1046,11 @@
 		}
 
 //		Checking if the points are well ordered
-		if(gpx.isCCW()){
-			gpx.flip();
-		}
+	// fpuga: This lines should be carefully checked if the nodes seems
+	// unordered
+	// if(gpx.isCCW()){
+	// gpx.flip();
+	// }
 
 		IGeometry geom=ShapeFactory.createPolygon2D(gpx);
 		return geom;




More information about the Opencadtools-commits mailing list