Revision 22962
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/primitive/GeneralPathX.java | ||
---|---|---|
59 | 59 |
import java.awt.geom.Point2D; |
60 | 60 |
import java.awt.geom.Rectangle2D; |
61 | 61 |
import java.io.Serializable; |
62 |
import java.util.ArrayList; |
|
62 | 63 |
|
63 | 64 |
import org.cresques.cts.ICoordTrans; |
64 | 65 |
import org.gvsig.fmap.geom.util.Converter; |
... | ... | |
66 | 67 |
import sun.awt.geom.Crossings; |
67 | 68 |
import sun.awt.geom.Curve; |
68 | 69 |
|
70 |
import com.vividsolutions.jts.algorithm.CGAlgorithms; |
|
71 |
import com.vividsolutions.jts.geom.Coordinate; |
|
72 |
import com.vividsolutions.jts.geom.CoordinateList; |
|
73 |
import com.vividsolutions.jts.geom.CoordinateSequences; |
|
74 |
import com.vividsolutions.jts.geom.impl.CoordinateArraySequence; |
|
75 |
|
|
69 | 76 |
/** |
70 | 77 |
* The <code>GeneralPathX</code> class represents a geometric path |
71 | 78 |
* constructed from straight lines, and quadratic and cubic |
... | ... | |
805 | 812 |
public double[] getPointCoords() { |
806 | 813 |
return pointCoords; |
807 | 814 |
} |
815 |
/** |
|
816 |
* Convertimos el path a puntos y luego le damos la vuelta. |
|
817 |
*/ |
|
818 |
public void flip() |
|
819 |
{ |
|
820 |
PathIterator theIterator = getPathIterator(null, Converter.FLATNESS); //polyLine.getPathIterator(null, flatness); |
|
821 |
double[] theData = new double[6]; |
|
822 |
Coordinate first = null; |
|
823 |
CoordinateList coordList = new CoordinateList(); |
|
824 |
Coordinate c1; |
|
825 |
GeneralPathX newGp = new GeneralPathX(); |
|
826 |
ArrayList listOfParts = new ArrayList(); |
|
827 |
while (!theIterator.isDone()) { |
|
828 |
//while not done |
|
829 |
int type = theIterator.currentSegment(theData); |
|
830 |
switch (type) |
|
831 |
{ |
|
832 |
case SEG_MOVETO: |
|
833 |
coordList = new CoordinateList(); |
|
834 |
listOfParts.add(coordList); |
|
835 |
c1= new Coordinate(theData[0], theData[1]); |
|
836 |
coordList.add(c1, true); |
|
837 |
break; |
|
838 |
case SEG_LINETO: |
|
839 |
c1= new Coordinate(theData[0], theData[1]); |
|
840 |
coordList.add(c1, true); |
|
841 |
break; |
|
808 | 842 |
|
843 |
case SEG_CLOSE: |
|
844 |
coordList.add(coordList.getCoordinate(0)); |
|
845 |
break; |
|
846 |
|
|
847 |
} |
|
848 |
theIterator.next(); |
|
849 |
} |
|
850 |
|
|
851 |
for (int i=listOfParts.size()-1; i>=0; i--) |
|
852 |
{ |
|
853 |
coordList = (CoordinateList) listOfParts.get(i); |
|
854 |
Coordinate[] coords = coordList.toCoordinateArray(); |
|
855 |
CoordinateArraySequence seq = new CoordinateArraySequence(coords); |
|
856 |
CoordinateSequences.reverse(seq); |
|
857 |
coords = seq.toCoordinateArray(); |
|
858 |
newGp.moveTo(coords[0].x, coords[0].y); |
|
859 |
for (int j=1; j < coords.length; j++) |
|
860 |
{ |
|
861 |
newGp.lineTo(coords[j].x, coords[j].y); |
|
862 |
} |
|
863 |
} |
|
864 |
reset(); |
|
865 |
append(newGp, false); |
|
866 |
} |
|
867 |
/** |
|
868 |
* Check if the first part is CCW. |
|
869 |
* @return |
|
870 |
*/ |
|
871 |
public boolean isCCW() |
|
872 |
{ |
|
873 |
int i; |
|
874 |
|
|
875 |
PathIterator theIterator = getPathIterator(null, Converter.FLATNESS); //polyLine.getPathIterator(null, flatness); |
|
876 |
double[] theData = new double[6]; |
|
877 |
Coordinate first = null; |
|
878 |
CoordinateList coordList = new CoordinateList(); |
|
879 |
Coordinate c1; |
|
880 |
boolean bFirst = true; |
|
881 |
while (!theIterator.isDone()) { |
|
882 |
//while not done |
|
883 |
int type = theIterator.currentSegment(theData); |
|
884 |
switch (type) |
|
885 |
{ |
|
886 |
case SEG_MOVETO: |
|
887 |
c1= new Coordinate(theData[0], theData[1]); |
|
888 |
if (bFirst == false) // Ya tenemos la primera parte. |
|
889 |
break; |
|
890 |
if (bFirst) |
|
891 |
{ |
|
892 |
bFirst=false; |
|
893 |
first = c1; |
|
894 |
} |
|
895 |
coordList.add(c1, true); |
|
896 |
break; |
|
897 |
case SEG_LINETO: |
|
898 |
c1= new Coordinate(theData[0], theData[1]); |
|
899 |
coordList.add(c1, true); |
|
900 |
break; |
|
901 |
|
|
902 |
} |
|
903 |
theIterator.next(); |
|
904 |
} |
|
905 |
coordList.add(first, true); |
|
906 |
return CGAlgorithms.isCCW(coordList.toCoordinateArray()); |
|
907 |
|
|
908 |
} |
|
809 | 909 |
} |
Also available in: Unified diff