From: <emm...@us...> - 2008-12-17 17:44:56
|
Revision: 4305 http://fudaa.svn.sourceforge.net/fudaa/?rev=4305&view=rev Author: emmanuel_martin Date: 2008-12-17 17:44:49 +0000 (Wed, 17 Dec 2008) Log Message: ----------- modeleur1d : tous les points d'un profil sont d?\195?\169pla?\195?\167ables. Test unitaire couvrant DataGeometryAdapter. quelques autres modifications mineures. Modified Paths: -------------- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/Controller1d.java branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/DataGeometry.java branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/DataGeometryAdapter.java branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/VueCourbe.java branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/VueTableau.java Added Paths: ----------- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/DataGeometryException.java branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/test/testModeleur1d/ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/test/testModeleur1d/TestDataGeometryAdapter.java Modified: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/Controller1d.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/Controller1d.java 2008-12-15 16:28:55 UTC (rev 4304) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/Controller1d.java 2008-12-17 17:44:49 UTC (rev 4305) @@ -69,20 +69,27 @@ private EbliFormatterInterface formater_=new EbliFormatter(); public Controller1d(MdlImplementation _appli, MdlFille1d _frame1d){ + if(_appli==null||_frame1d==null) + throw new IllegalArgumentException("Les param\xE8tres ne doivent pas \xEAtre null."); appli_=_appli; frame1d_=_frame1d; frame1d_.addInternalFrameListener(this); vueBief_=new VueBief(appli_, this); vueBief_.getScene().addSelectionListener(this); treeModel_=vueBief_.getArbreCalqueModel(); - dataGeomAdapter_=new DataGeometryAdapter(this, null, -1); + try { + dataGeomAdapter_=new DataGeometryAdapter(null, -1); + } + catch (DataGeometryException _exc) { + _exc.printStackTrace(); + } vueTableau_=new VueTableau(this, dataGeomAdapter_); vueTableau_.addSelectionListener(this); vueCourbe_=new VueCourbe(this, dataGeomAdapter_); vueCourbe_.addSelectionListener(this); vueError_=new BuLabel(); vueError_.setForeground(Color.RED); - vueError_.setText(""); + clearError(); } public VueBief getVueBief(){ @@ -105,11 +112,13 @@ // Gestion de l'affichage des erreurs. \\ public void showError(String _message){ + if(_message==null||_message.length()==0) + clearError(); vueError_.setText(_message); } public void clearError(){ - vueError_.setText(null); + vueError_.setText(" "); } // Gestion de l'arbre \\ @@ -184,8 +193,8 @@ int sceneIdSelected=scene.getSelectionHelper().getUniqueSelectedIdx(); boolean ok=true; // Indique si tout s'est bien pass\xE9. if (sceneIdSelected==-1) - // Aucune selection - dataGeomAdapter_.setData(null, -1); + try {dataGeomAdapter_.setData(null, -1);} + catch (DataGeometryException _exc) {_exc.printStackTrace();} else { int idSelected=scene.sceneId2LayerId(sceneIdSelected); // Extraction des diff\xE9rentes informations n\xE9c\xE9ssaires au changement de @@ -198,8 +207,8 @@ try { dataGeomAdapter_.setData(zone, idSelected); } - catch (IllegalArgumentException _exp) { - showError(_exp.getMessage()); + catch (DataGeometryException _exc) { + showError(_exc.getMessage()); } } else Modified: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/DataGeometry.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/DataGeometry.java 2008-12-15 16:28:55 UTC (rev 4304) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/DataGeometry.java 2008-12-17 17:44:49 UTC (rev 4305) @@ -12,7 +12,7 @@ * widgets tableau et courbe. * * @author Emmanuel MARTIN - * @version $Id:$ + * @version $Id$ */ public interface DataGeometry { @@ -43,15 +43,24 @@ /** Retourne la valeur minimal de z. */ public double getZMin(); - /** Enregistre l'abcisse curviligne du point indiqu\xE9 en param\xE8tre. */ - public void setCurv(int _idxPoint, double _value); + /** + * Enregistre l'abcisse curviligne du point indiqu\xE9 en param\xE8tre. + * Ce changement d'abscisse curviligne fonctionne sur tout les points. + * Si un points extr\xE9mit\xE9 est chang\xE9, le point 2D est d\xE9plac\xE9 sur son axe, + * la longueur globale n'est pas concerv\xE9e dans l'op\xE9ration. + * Si c'est un point de rupture le point 2D est d\xE9plac\xE9 de telle mani\xE8re + * que la longueur globale soit concerv\xE9e. + * Pour les autres points, le point 2D est d\xE9plac\xE9 sur son axe en concervant + * la longeur globale. + */ + public void setCurv(int _idxPoint, double _value) throws DataGeometryException; /** Enregistre la valeur de z du point indiqu\xE9 en param\xE8tre. */ public void setZ(int _idxPoint, double _value); /** Enregistre l'abcisse curviligne et la valeur de z du point indiqu\xE9 en param\xE8tre. */ - public void setValues(int _idxPoint, double _valueCurv, double _valueZ); + public void setValues(int _idxPoint, double _valueCurv, double _valueZ) throws DataGeometryException; /** Supprime le point indiqu\xE9 en param\xE8tre. */ - public void remove(int _idxPoint); + public void remove(int _idxPoint) throws DataGeometryException; } Modified: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/DataGeometryAdapter.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/DataGeometryAdapter.java 2008-12-15 16:28:55 UTC (rev 4304) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/DataGeometryAdapter.java 2008-12-17 17:44:49 UTC (rev 4305) @@ -10,15 +10,18 @@ import java.util.ArrayList; import java.util.List; +import org.fudaa.ctulu.CtuluListSelection; import org.fudaa.ctulu.collection.CtuluCollection; import org.fudaa.ctulu.gis.GISCoordinateSequenceContainerInterface; import org.fudaa.ctulu.gis.GISGeometryFactory; +import org.fudaa.ctulu.gis.GISPolyligne; import org.fudaa.ctulu.gis.GISZoneCollection; import org.fudaa.ctulu.gis.GISZoneCollectionLigneBrisee; import org.fudaa.fudaa.commun.FudaaLib; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.CoordinateSequence; +import com.vividsolutions.jts.geom.Geometry; /** * Cette classe permet d'adapter une GISZoneCollection en un model manipulable @@ -28,9 +31,8 @@ * @author Emmanuel MARTIN * @version $Id$ */ -class DataGeometryAdapter implements DataGeometry { - /** Le controller, pour afficher des messages d'erreur. */ - private Controller1d controller_; +public class DataGeometryAdapter implements DataGeometry { + private GISZoneCollectionLigneBrisee zone_; private int idxGeom_; private CtuluCollection z_; @@ -43,10 +45,7 @@ int idxRupture1_; int idxRupture2_; - public DataGeometryAdapter(Controller1d _controller, GISZoneCollectionLigneBrisee _zone, int _idxGeom) throws IllegalArgumentException { - if(_controller==null) - throw new IllegalArgumentException("Controller1d ne doit pas \xEAtre null."); - controller_=_controller; + public DataGeometryAdapter(GISZoneCollectionLigneBrisee _zone, int _idxGeom) throws IllegalArgumentException, DataGeometryException { setData(_zone, _idxGeom); } @@ -58,8 +57,9 @@ * * @param _zone la zone contenant la g\xE9om\xE9trie * @param _idxGeom l'indice de la g\xE9om\xE9trie dans _zone + * @throws DataGeometryException */ - public void setData(GISZoneCollectionLigneBrisee _zone, int _idxGeom) throws IllegalArgumentException { + public void setData(GISZoneCollectionLigneBrisee _zone, int _idxGeom) throws IllegalArgumentException, DataGeometryException { if (_zone==null&&_idxGeom==-1) { zone_=null; idxGeom_=-1; @@ -75,11 +75,11 @@ CoordinateSequence seq=((GISCoordinateSequenceContainerInterface)zone_.getGeometry(idxGeom_)).getCoordinateSequence(); // Verifie qu'on a bien au minimum deux points. \\ if (seq.size()<2) - throw new IllegalArgumentException(FudaaLib.getS("Le profil doit avoir au minimum deux points.")); + throw new DataGeometryException(FudaaLib.getS("Le profil doit avoir au minimum deux points.")); // Verifie que deux points cons\xE9cutifs ne sont pas confondus. \\ for (int i=1; i<seq.size(); i++) if (seq.getX(i-1)==seq.getX(i)&&seq.getY(i-1)==seq.getY(i)) - throw new IllegalArgumentException(FudaaLib.getS("Au moins deux points dans le profil sont confondus.")); + throw new DataGeometryException(FudaaLib.getS("Au moins deux points dans le profil sont confondus.")); // Calcul des acbscisses curvilignes => hypoth\xE8se d'ordonnancement // correcte des points \\ double curvPre=0; @@ -99,6 +99,23 @@ else if (val<(Double)z_.getObjectValueAt(idxZMin_)) idxZMin_=i; } + + // Verifie que le profil donn\xE9 ne poss\xE8de pas des axes qui se coupent entre eux \\ + for(int i=1;i<seq.size();i++){ + Geometry mainAxe=GISGeometryFactory.INSTANCE.createLineString(new Coordinate[]{seq.getCoordinate(i-1), seq.getCoordinate(i)}); + boolean ok=true; + // Un seul point d'intersection avec l'axe qui suit + if(i+1<seq.size()&&mainAxe.intersection(GISGeometryFactory.INSTANCE.createLineString(new Coordinate[]{seq.getCoordinate(i), seq.getCoordinate(i+1)})).getNumPoints()>1) + ok=false; + // Aucun point d'intersectin avec les axes qui suivent + int j=i; + while(ok&&++j+1<seq.size()) + ok=!mainAxe.intersects(GISGeometryFactory.INSTANCE.createLineString(new Coordinate[]{seq.getCoordinate(j), seq.getCoordinate(j+1)})); + // Traitement d'une \xE9ventuelle intersection + if(!ok) + throw new DataGeometryException(FudaaLib.getS("Le profil se coupe lui m\xEAme. Il n'est donc pas valide.")); + } + // / D\xE9termination des points de ruptures et verification qu'il y en a // au maximun deux. \\\ idxRupture1_=-1; @@ -144,14 +161,14 @@ else if (idxRupture2_==-1) idxRupture2_=idx-1; else - throw new IllegalArgumentException(FudaaLib.getS("Il y a plus que deux ruptures dans le profil.")); + throw new DataGeometryException(FudaaLib.getS("Il y a plus que deux ruptures dans le profil.")); } // Pr\xE9paration de l'it\xE9ration suivante coefDirecteur=newCoefDirecteur; coefDirX=newCoefDirX; } } - catch(IllegalArgumentException _exp) { + catch(DataGeometryException _exp) { // Remise dans un \xE9tat coh\xE9rent zone_=null; idxGeom_=-1; @@ -184,105 +201,293 @@ } public double getCurv(int _idxPoint) { - if(curv_==null) - return 0; - else - return curv_.get(_idxPoint); + if(curv_==null||_idxPoint<0||_idxPoint>=curv_.size()) + throw new IllegalArgumentException("Cet index n'existe pas."); + return curv_.get(_idxPoint); } public double getZ(int _idxPoint) { - if (z_==null) - return 0; - else - return ((Double)z_.getObjectValueAt(_idxPoint)).doubleValue(); + if (z_==null||_idxPoint<0||_idxPoint>=z_.getSize()) + throw new IllegalArgumentException("Cet index n'existe pas."); + return ((Double)z_.getObjectValueAt(_idxPoint)).doubleValue(); } - - public void setCurv(int _idxPoint, double _value) { - controller_.clearError(); - if(curv_==null) - return; + + public void setCurv(int _idxPoint, double _value) throws DataGeometryException { + if(curv_==null||_idxPoint<0||_idxPoint>=curv_.size()) // Si curv_!=null alors z et index_ ont des valeurs coh\xE9rentes + throw new IllegalArgumentException("Cet index n'existe pas."); + // Extraction des coordonn\xE9es de la g\xE9om\xE9trie pour pouvoir les modifier par la suite CoordinateSequence seq=((GISCoordinateSequenceContainerInterface)zone_.getGeometry(idxGeom_)).getCoordinateSequence(); Coordinate[] coords=seq.toCoordinateArray(); - if(_idxPoint==0||_idxPoint==seq.size()-1){ - controller_.showError(FudaaLib.getS("Le changement d'abscisse curviligne des extr\xE9mit\xE9s n'est pas g\xE9r\xE9 pour l'instant.")); - return; + // Les nouvelles valeurs du points \xE0 d\xE9placer + double newX; + double newY; + // Delta pour savoir si des doubles sont \xE9gaux + double tolerance=0.000001; + + // Verifie que le point reste encadr\xE9 par le(s) m\xEAme(s) point(s) + if((_idxPoint==0&&_value>=curv_.get(1))||(_idxPoint==seq.size()-1&&_value<=curv_.get(seq.size()-2))||(_idxPoint!=0&&_idxPoint!=seq.size()-1&&(_value<=curv_.get(_idxPoint-1)||_value>=curv_.get(_idxPoint+1)))) + throw new DataGeometryException(FudaaLib.getS("Il est interdit de d\xE9placer un point au dela des points l'encadrant.")); + + // Cas o\xF9 l'index n'est pas sur un point de rupture \\ + if (_idxPoint!=idxRupture1_&&_idxPoint!=idxRupture2_) { + // Le point reste encadr\xE9 par les deux m\xEAme points => le signe de xa-xb et + // de ya-yb ne change pas + // D\xE9termination des deux index \xE0 utiliser + int idx1; + int idx2; + double valCurv; + if (_idxPoint>0) { // Le premier point n'est pas selectionn\xE9 + idx1=_idxPoint-1; + idx2=_idxPoint; + valCurv=_value-curv_.get(idx1); + } + else { + idx1=_idxPoint+1; + idx2=_idxPoint; + valCurv=Math.abs(_value-curv_.get(idx1)); + } + // Calcul des nouvelles coordonn\xE9es + if (Math.abs(seq.getX(idx2)-seq.getX(idx1))>tolerance) { + // Extraction du signe de xa-xb + double sign=Math.signum(seq.getX(idx2)-seq.getX(idx1)); + double coefDirecteur=(seq.getY(idx2)-seq.getY(idx1))/(seq.getX(idx2)-seq.getX(idx1)); + newX=seq.getX(idx1)+sign*valCurv/Math.sqrt(1+coefDirecteur*coefDirecteur); + newY=seq.getY(idx1)+coefDirecteur*(newX-seq.getX(idx1)); + } + else { // Cas du bout de profil vertical + // Extraction du signe de ya-yb + double sign=Math.signum(seq.getY(idx2)-seq.getY(idx1)); + newX=seq.getX(idx1); + newY=seq.getY(idx1)+sign*valCurv; + } + coords[_idxPoint].x=newX; + coords[_idxPoint].y=newY; + // Mise a jour de la table des valeurs curvilignes + if (_idxPoint==0) + for (int i=1; i<curv_.size(); i++) + curv_.set(i, curv_.get(i)-_value); + else + curv_.set(_idxPoint, _value); } - if(_value<0) - return; - // Cas o\xF9 l'index n'est pas sur un point de rupture \\ - if(_idxPoint!=idxRupture1_&&_idxPoint!=idxRupture2_){ - // Cas o\xF9 le point reste encadr\xE9 par les deux m\xEAme points (noralement toujours le cas) => le signe de xa-xb et de ya-yb ne change pas - if((_idxPoint==0||_value>curv_.get(_idxPoint-1))&&(_idxPoint==curv_.size()-1||_value<curv_.get(_idxPoint+1))){ - // D\xE9termination des deux index \xE0 utiliser - int idx1; - int idx2; - double valCurv; - if(_idxPoint>0){ // On a pas selectionn\xE9 le premier point - idx1=_idxPoint-1; - idx2=_idxPoint; - valCurv=_value-curv_.get(idx1); + + // Cas complexe : l'index est sur un point de rupture \\ + else { + /* + * Abstract : + * Pour trouver le point restectant la concervation de labcisse curviligne, est + * utilis\xE9 par la suite une m\xE9thode d'intersection de deux cercles. + * - Soient A, B, C, trois points non confondus. Soit la polyligne A, C, B. + * On veut construire C' tq cruv(C')=c et que curv(B) reste constant. + * Donc : + * dist(AC)+dist(CB)=dist(AC')+dist(C'B) + * Ce probl\xE8me peut se r\xE9duire \xE0 la recherche de l'intersection de deux cercles : + * C1=cercle(centre=A, rayon=c-curv(A)) avec C2=cercle(centre=B, rayon=curv(B)-c) + * + * Cas 1 : ya-yb != 0: + * La r\xE9solution de ce probl\xE8me donne l'\xE9quation : + * x\xB2[M\xB2+1] + x[2yaM-2NM-2xa] + xa\xB2+ya\xB2+N\xB2-rayonC1\xB2-2yaN=0 + * avec N=(rayonC2\xB2-rayonC1\xB2-xb\xB2+xa\xB2-yb\xB2+ya\xB2)/(2(ya-yb)) + * et M=(xa-xb)/(ya-yb) + * C'est une \xE9quation du second degr\xE9. + * Pour la r\xE9solution de l'\xE9quation, nous nommerons : + * equA=[M\xB2+1] + * equB=[2yaM-2NM-2xa] + * equC=xa\xB2+ya\xB2+N\xB2-rayonC1\xB2-2yaN + * La r\xE9solution de l'\xE9quation r\xE9sultante donne deux solutions (c1' et c2'). + * Pour trouver celle qui nous interesse (si elle existe) la contrainte suivante doit \xEAtre v\xE9rifi\xE9e : + * vecteurNorm\xE9(C, Proj(C, AB)) = vecteurNorm\xE9(CX', Proj(CX', AB)) + * A noter que Proj(C1', AB)=Proj(C2', AB) de plus pour simplifier cette r\xE9solution sera faite sur z=0. + * + * Cas 2 : ya-yb = 0 et xa-xb != 0: + * La r\xE9solution de ce prol\xE8me donne l'\xE9quation : + * y\xB2-2yay+xa+K\xB2-2xaK-rayonC1\xB2=0 + * avec K=(rayonC2\xB2-rayonC1\xB2-xb\xB2+xa\xB2)/(2*(xa-xb)) + * # k est \xE9galement la valeur de x des deux solutions potentielles + * C'est un \xE9quation du second degr\xE9. + * Pour la r\xE9solution de l'aquation, nous nommerons : + * equA=1 + * equB=2ya + * equC=K\xB2-2xaK-rayonC1\xB2 + * La r\xE9solution de l'\xE9quation r\xE9sultante donne deux solutions (c1' et c2'). + * Pour trouver celle qui nous interesse (si elle existe) la contrainte suivante doit \xEAtre v\xE9rifi\xE9e : + * vecteurNorm\xE9(C, Proj(C, AB)) = vecteurNorm\xE9(CX', Proj(CX', AB)) + * A noter que Proj(C1', AB)=Proj(C2', AB) de plus pour simplifier cette r\xE9solution sera faite sur z=0. + * + * Cas 3 : ya-yb = 0 et xa-xb=0: + * quel qu'en soit le r\xE9sultat, c'est incoh\xE9rent pour notre contexte. + * + * De plus on verifie que le r\xE9sultat ne provoque pas de croisement avec les autres axes + * du profil. + * + * Une fois ce point trouv\xE9, on va \xE9galement d\xE9placer tous les points des deux axes adjacents, + * pour que le profil concerve sa forme g\xE9n\xE9rale. Ce r\xE9aligement se faire en concervant les + * abscisses curvilignes de chacun des points. + * Pour y parvenir le nouveau coefficient directeur des axes est calcul\xE9 et appliqu\xE9 au rapport de + * l'abcisse curviligne avec l'abscisse du point extr\xE9mit\xE9 de l'axe. + */ + + // Application de la m\xE9thode d\xE9crite ci dessus \\ + + // Valuation des variables d'entr\xE9es n\xE9c\xE9ssaires + final int idxPtdeb=_idxPoint==idxRupture1_?0:idxRupture1_; + final int idxPtFin=_idxPoint==idxRupture2_||idxRupture2_==-1?seq.size()-1:idxRupture2_; + final Coordinate a=seq.getCoordinate(idxPtdeb); + final Coordinate b=seq.getCoordinate(idxPtFin); + final Coordinate c=seq.getCoordinate(_idxPoint); + final double rayonC1=_value-curv_.get(idxPtdeb); + final double rayonC2=curv_.get(idxPtFin)-_value; + // Solutions + double x1; + double y1; + double x2; + double y2; + // Cas 1 + if(Math.abs(a.y-b.y)>tolerance){ + // Variables interm\xE9diaires + double n=(rayonC2*rayonC2-rayonC1*rayonC1-b.x*b.x+a.x*a.x-b.y*b.y+a.y*a.y)/(2*(a.y-b.y)); + double m=(a.x-b.x)/(a.y-b.y); + double equA=m*m+1; + double equB=2*(a.y*m-n*m-a.x); + double equC=a.x*a.x+a.y*a.y+n*n-rayonC1*rayonC1-2*a.y*n; + // Variables de r\xE9solution + double deltaTmp=equB*equB-4*equA*equC; + if(deltaTmp<0) + throw new DataGeometryException(FudaaLib.getS("Ce d\xE9placement n'est pas possible sans violer la contrainte de constance de la longueur du profil.")); + double delta=Math.sqrt(equB*equB-4*equA*equC); + x1=(-equB+delta)/(2*equA); + y1=n-x1*m; + x2=(-equB-delta)/(2*equA); + y2=n-x2*m; + } + // Cas 2 + else if(Math.abs(a.x-b.x)>tolerance){ + // Variables interm\xE9diaires + double k=(rayonC2*rayonC2-rayonC1*rayonC1-b.x*b.x+a.x*a.x)/(2*(a.x-b.x)); + double equA=1; + double equB=2*a.y; + double equC=k*k-2*a.x*k-rayonC1*rayonC1; + // Variables de r\xE9solution + double deltaTmp=equB*equB-4*equA*equC; + if(deltaTmp<0) + throw new DataGeometryException(FudaaLib.getS("Ce d\xE9placement n'est pas possible sans violer la contrainte de constance de la longueur du profil.")); + double delta=Math.sqrt(equB*equB-4*equA*equC); + y1=(-equB+delta)/(2*equA); + x1=k; + y2=(-equB-delta)/(2*equA); + x2=k; + } + // Cas 3 + else + throw new DataGeometryException(FudaaLib.getS("Ce d\xE9placement n'est pas valide. Ce cas ne devrait jamais arriver. CSI_1")); + // Recherche du r\xE9sultat nous interessant dans ce cas ci + Coordinate aZ0=new Coordinate(a.x, a.y, 0); + Coordinate bZ0=new Coordinate(b.x, b.y, 0); + Coordinate cZ0=new Coordinate(c.x, c.y, 0); + Coordinate vecReference=vec(cZ0, proj(cZ0, aZ0, bZ0)); + Coordinate cProj=proj(new Coordinate(x1, y1, 0), aZ0, bZ0); + assert(egal(cProj, proj(new Coordinate(x2, y2, 0), aZ0, bZ0), 0.0001, false)); + if(egal(vecReference, vec(new Coordinate(x1, y1, 0), cProj), 0.0001, true)){ + newX=x1; + newY=y1; + } + else if(egal(vecReference, vec(new Coordinate(x2, y2, 0), cProj), 0.0001, true)) { + newX=x2; + newY=y2; + } + else + throw new DataGeometryException(FudaaLib.getS("Ce d\xE9placement n'est pas valide. Ce cas ne devrait jamais arriver. CSI_2")); + + // Verifie que le point trouv\xE9 ne coupe pas un autre axe du profil \\ + boolean noCut=true; + Coordinate newP=new Coordinate(newX, newY); + GISPolyligne axe1=GISGeometryFactory.INSTANCE.createLineString(new Coordinate[]{a, newP}); + GISPolyligne axe2=GISGeometryFactory.INSTANCE.createLineString(new Coordinate[]{newP, b}); + if(idxPtdeb>0) { + /* + * Test de croisement entre les deux axes modifi\xE9s et l'axe avant. l'axe + * a, newP a normalement un point d'intersectino (a). + */ + GISPolyligne axeTest=GISGeometryFactory.INSTANCE.createLineString(new Coordinate[]{coords[0], coords[idxPtdeb]}); + noCut=axe1.intersection(axeTest).getNumPoints()==1; + noCut=noCut&&!axe2.intersects(axeTest); + } + if(idxPtFin<seq.size()-1) { + /* + * Test de croisement entre les deux axes modifi\xE9s et l'axe avant. l'axe + * newP, b a normalement un point d'intersectino (b). + */ + GISPolyligne axeTest=GISGeometryFactory.INSTANCE.createLineString(new Coordinate[]{coords[idxPtFin], coords[coords.length-1]}); + noCut=noCut&&axe2.intersection(axeTest).getNumPoints()==1; + noCut=noCut&&!axe1.intersects(axeTest); + } + // Traitement de l'\xE9ventuelle d\xE9tection d'un croisement + if(!noCut) + throw new DataGeometryException(FudaaLib.getS("Ce d\xE9placement est impossible sans obtenir un profil dont des axes se coupent.")); + // Enregistrement du nouveau point C' et de la nouvelle valeur curviligne + coords[_idxPoint].x=newX; + coords[_idxPoint].y=newY; + // Mise a jour de la table des valeurs curvilignes + curv_.set(_idxPoint, _value); + + // R\xE9alignement des points des axes adjacents \\ + for(int inc=0;inc<2;inc++){ + // D\xE9termination des points de d\xE9but et de fin d'axe + int idxDeb; + int idxFin; + if(inc==0) { // premi\xE8re it\xE9ration, axe : debut, C' + idxDeb=_idxPoint==idxRupture1_?0:idxRupture1_; + idxFin=_idxPoint; } - else { - idx1=_idxPoint+1; - idx2=_idxPoint; - valCurv=Math.abs(_value-curv_.get(idx1)); + else { // seconde it\xE9ration, axe : C', fin + idxDeb=_idxPoint; + idxFin=_idxPoint==idxRupture2_||idxRupture2_==-1 ? seq.size()-1:idxRupture2_; } - // Calcul des nouvelles coordonn\xE9es - if (seq.getX(idx2)!=seq.getX(idx1)) { - // Extraction du signe de xa-xb - double sign=Math.signum(seq.getX(idx2)-seq.getX(idx1)); - double coefDirecteur=(seq.getY(idx2)-seq.getY(idx1))/(seq.getX(idx2)-seq.getX(idx1)); - double newX=seq.getX(idx1)+sign*valCurv/Math.sqrt(1+coefDirecteur*coefDirecteur); - double newY=seq.getY(idx1)+coefDirecteur*(newX-seq.getX(idx1)); - coords[_idxPoint].x=newX; - coords[_idxPoint].y=newY; + // R\xE9alignement sur l'axe + if (Math.abs(coords[idxFin].x-coords[idxDeb].x)>tolerance) { + double sign=Math.signum(coords[idxFin].x-coords[idxDeb].x); + double newCoefDirecteur=(coords[idxFin].y-coords[idxDeb].y)/(coords[idxFin].x-coords[idxDeb].x); + for(int i=idxDeb+1;i<idxFin;i++){ + coords[i].x=coords[idxDeb].x+sign*(curv_.get(i)-curv_.get(idxDeb))/Math.sqrt(1+newCoefDirecteur*newCoefDirecteur); + coords[i].y=coords[idxDeb].y+newCoefDirecteur*(coords[i].x-coords[idxDeb].x); + } } else { // Cas du bout de profil vertical - // Extraction du signe de ya-yb - double sign=Math.signum(seq.getY(idx2)-seq.getY(idx1)); - double newY=seq.getY(idx1)+sign*(valCurv-curv_.get(idx1)); - coords[_idxPoint].y=newY; + double sign=Math.signum(coords[idxFin].y-coords[idxDeb].y); + for(int i=idxDeb+1;i<idxFin;i++){ + coords[i].x=coords[idxDeb].x; + coords[i].y=coords[idxDeb].y+sign*(curv_.get(i)-curv_.get(idxDeb)); + } } - zone_.setCoordinateSequence(idxGeom_, GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create(coords), null); - // Mise a jour de la table des valeurs curvilignes - if (_idxPoint!=0) - curv_.set(_idxPoint, _value); - else - for (int i=1; i<curv_.size(); i++) - curv_.set(i, curv_.get(i)-_value); - fireDataGeometryChanged(); } - // Cas o\xF9 il y a d\xE9pacement d'un autre point => le signe de xa-xb va potentiellement chang\xE9 => cas interdit - else - controller_.showError(FudaaLib.getS("Il est interdit de d\xE9placer un point au dela des points l'encadrant.")); } - else - // Cas complexe : l'index est sur un point de rupture \\ - // TODO : d\xE9placement sur l'\xE9llipse avec verification de non croisement des axes du profil - controller_.showError(FudaaLib.getS("Le changement d'abscisse curviligne des points de ruptures n'est pas g\xE9r\xE9 pour l'instant.")); + + // Enregistrement des nouvelles coordonn\xE9es \\ + zone_.setCoordinateSequence(idxGeom_, GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create(coords), null); + // Notification des changements de valeurs + fireDataGeometryChanged(); } public void setZ(int _idxPoint, double _value) { - if (z_!=null) { - z_.setObject(_idxPoint, _value, null); - // Mise \xE0 jour de idxZMin_ et idxZMax_ - if (_idxPoint==idxZMax_||_idxPoint==idxZMin_) { - idxZMax_=0; - idxZMin_=0; - for (int i=1; i<z_.getSize(); i++) { - double val=(Double)z_.getObjectValueAt(i); - if (val>(Double)z_.getObjectValueAt(idxZMax_)) - idxZMax_=i; - else if (val<(Double)z_.getObjectValueAt(idxZMin_)) - idxZMin_=i; - } + if (z_==null||_idxPoint<0||_idxPoint>=z_.getSize()) + throw new IllegalArgumentException("Cet index n'existe pas."); + z_.setObject(_idxPoint, _value, null); + // Mise \xE0 jour de idxZMin_ et idxZMax_ + if (_idxPoint==idxZMax_||_idxPoint==idxZMin_) { + idxZMax_=0; + idxZMin_=0; + for (int i=1; i<z_.getSize(); i++) { + double val=(Double)z_.getObjectValueAt(i); + if (val>(Double)z_.getObjectValueAt(idxZMax_)) + idxZMax_=i; + else if (val<(Double)z_.getObjectValueAt(idxZMin_)) + idxZMin_=i; } - else if (_value>(Double)z_.getObjectValueAt(idxZMax_)) - idxZMax_=_idxPoint; - else if (_value<(Double)z_.getObjectValueAt(idxZMin_)) - idxZMin_=_idxPoint; - fireDataGeometryChanged(); } + else if (_value>(Double)z_.getObjectValueAt(idxZMax_)) + idxZMax_=_idxPoint; + else if (_value<(Double)z_.getObjectValueAt(idxZMin_)) + idxZMin_=_idxPoint; + fireDataGeometryChanged(); } public double getCurvMax() { @@ -296,7 +501,7 @@ if(curv_==null) return 0; else - return curv_.get(0); + return curv_.get(0); // toujours 0 de toute fa\xE7on } public double getZMax() { @@ -313,57 +518,68 @@ return (Double) z_.getObjectValueAt(idxZMin_); } - public void setValues(int _idxPoint, double _valueCurv, double _valueZ){ + public void setValues(int _idxPoint, double _valueCurv, double _valueZ) throws DataGeometryException{ setZ(_idxPoint, _valueZ); setCurv(_idxPoint, _valueCurv); } - public void remove(int _idxPoint){ - if(zone_==null||z_==null||curv_==null) - return; - if(_idxPoint>=0&&_idxPoint<z_.getSize()){ - // Suppression du point dans la zone + public void remove(int _idxPoint) throws DataGeometryException { + if(zone_==null||z_==null||curv_==null||_idxPoint<0||_idxPoint>=curv_.size()) + throw new IllegalArgumentException("Cet index n'existe pas."); + if(curv_.size()==2) + throw new DataGeometryException("On ne peut pas enlever un point quand il n'en reste que deux."); + // Suppression du point dans la zone + zone_.removeAtomics(idxGeom_, new CtuluListSelection(new int[]{_idxPoint}), null, null); + z_=(CtuluCollection)zone_.getValue(zone_.getIndiceOf(zone_.getAttributeIsZ()), idxGeom_); + // Mise \xE0 jour des informations curvilignes \\ + if (_idxPoint==0) { + // Si _idxPoint est le premier point + curv_.remove(0); + for (int i=curv_.size()-1; i>=0; i--) + curv_.set(i, curv_.get(i)-curv_.get(0)); + } + else if (_idxPoint>0&&_idxPoint<curv_.size()-1) { + // Cas g\xE9n\xE9ral si _idxPoint est entre le premier et le dernier + // Attention curv_ contient toujours _idxPoint contrairement \xE0 seq CoordinateSequence seq=((GISCoordinateSequenceContainerInterface)zone_.getGeometry(idxGeom_)).getCoordinateSequence(); - Coordinate[] points=new Coordinate[seq.size()-1]; - for(int i=0;i<_idxPoint;i++) - points[i]=seq.getCoordinate(i); - for(int i=_idxPoint+1;i<seq.size();i++) - points[i]=seq.getCoordinate(i); - zone_.setGeometry(idxGeom_, GISGeometryFactory.INSTANCE.createGeometry(zone_.getGeometry(idxGeom_).getClass(), - GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create(points)), null); - // Mise \xE0 jour des informations curvilignes \\ - if(_idxPoint==0){ - // Si _idxPoint est le premier point - curv_.remove(0); - for(int i=curv_.size();i>=0;i--) - curv_.set(i, curv_.get(i)-curv_.get(0)); + double delta=curv_.get(_idxPoint-1)-curv_.get(_idxPoint+1) + +Math.sqrt(Math.pow(seq.getCoordinate(_idxPoint-1).x-seq.getCoordinate(_idxPoint).x, 2) + +Math.pow(seq.getCoordinate(_idxPoint-1).y-seq.getCoordinate(_idxPoint).y, 2)); + curv_.remove(_idxPoint); + for (int i=_idxPoint; i<curv_.size(); i++) + curv_.set(i, curv_.get(i)+delta); + } + else + // Si _idxPoint est le dernier + curv_.remove(curv_.size()-1); + // Mise \xE0 jour de idxZMin_ et idxZMax_ + if (_idxPoint==idxZMax_||_idxPoint==idxZMin_) { + idxZMax_=0; + idxZMin_=0; + for (int i=1; i<z_.getSize(); i++) { + double val=(Double)z_.getObjectValueAt(i); + if (val>(Double)z_.getObjectValueAt(idxZMax_)) + idxZMax_=i; + else if (val<(Double)z_.getObjectValueAt(idxZMin_)) + idxZMin_=i; } - else if (_idxPoint>0&&_idxPoint<curv_.size()-1) { - // Cas g\xE9n\xE9ral si _idxPoint est entre le premier et le dernier - // Attention 'curv_' contient encore _idxPoint alors que 'points' ne le - // contient plus - double delta=-curv_.get(_idxPoint)-curv_.get(_idxPoint+1) - +Math.sqrt(Math.pow(points[_idxPoint-1].x-points[_idxPoint].x, 2) - +Math.pow(points[_idxPoint-1].y-points[_idxPoint].y, 2)); - curv_.remove(_idxPoint); - for(int i=_idxPoint;i<curv_.size();i++) - curv_.set(i, curv_.get(i)+delta); - } - else - // Si _idxPoint est le dernier - curv_.remove(curv_.size()-1); } + fireDataGeometryChanged(); } /** List de listener. */ List<DataGeometryListener> listeners_=new ArrayList<DataGeometryListener>(); public void addDataGeometryListener(DataGeometryListener _listener) { + if(_listener==null) + throw new IllegalArgumentException("_listener doit \xEAtre non null"); if(!listeners_.contains(_listener)) listeners_.add(_listener); } public void removeDataGeometryListener(DataGeometryListener _listener) { + if(_listener==null) + throw new IllegalArgumentException("_listener doit \xEAtre non null"); if(listeners_.contains(_listener)) listeners_.remove(_listener); } @@ -377,4 +593,55 @@ for(DataGeometryListener listener:listeners_) listener.dataGeometryNewGeom(); } + + // Quelques fonctions m\xE9th\xE9matiques \\ + + /** + * retourne le vecteur _a, _b sous forme de Coordinate. + */ + private Coordinate vec(Coordinate _a, Coordinate _b){ + return new Coordinate(_b.x-_a.x, _b.y-_a.y, _b.z-_a.z); + } + + /** + * Retourne la projection de _a sur la droite _b_c. + * Attention : Il s'agit bien d'une projection sur une + * droite et non un segment de droite : le r\xE9sultat + * peut \xEAtre en dehors de [_b, _c] + */ + private Coordinate proj(Coordinate _a, Coordinate _b, Coordinate _c){ + Coordinate vBC=vec(_b, _c); + Coordinate vBA=vec(_b, _a); + double normeBC=Math.sqrt(vBC.x*vBC.x+vBC.y*vBC.y+vBC.z*vBC.z); + double produitScalaireBCBA=vBC.x*vBA.x+vBC.y*vBA.y+vBC.z*vBA.z; + double rapportSurBC=produitScalaireBCBA/(normeBC*normeBC); + return new Coordinate(vBC.x*rapportSurBC+_b.x, vBC.y*rapportSurBC+_b.y, vBC.z*rapportSurBC+_b.z); + } + + /** + * Normalise le vecteur pass\xE9 en param\xE8tre. + */ + private Coordinate normalisation(Coordinate _a){ + double normeA=Math.sqrt(_a.x*_a.x+_a.y*_a.y+_a.z*_a.z); + _a.x=_a.x/normeA; + _a.y=_a.y/normeA; + _a.z=_a.z/normeA; + return _a; + } + + /** + * Compars les deux vecteurs avec la tol\xE9rance donn\xE9e. + * Le dernier param\xE8tre indique si un normalisation des + * deux vecteurs doit \xEAtre faite avec la comparaison. + * Les vecteurs ne sont pas modif\xE9s dans l'op\xE9ration. + */ + private boolean egal(Coordinate _a, Coordinate _b, double _tolerance, boolean _normalisation) { + if(_normalisation){ + normalisation(_a); + normalisation(_b); + } + Coordinate diff=vec(_a, _b); + return Math.abs(diff.x)<_tolerance&&Math.abs(diff.y)<_tolerance&&Math.abs(diff.z)<_tolerance; + } + } Added: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/DataGeometryException.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/DataGeometryException.java (rev 0) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/DataGeometryException.java 2008-12-17 17:44:49 UTC (rev 4305) @@ -0,0 +1,23 @@ +/* + * @creation 16 d\xE9c. 2008 + * @modification $Date:$ + * @license GNU General Public License 2 + * @copyright (c)1998-2008 CETMEF 2 bd Gambetta F-60231 Compiegne + * @mail fud...@li... + */ +package org.fudaa.fudaa.modeleur.modeleur1d; + +/** + * Exception lev\xE9e par les classes impl\xE9mentant DataGeometry pour indiqu\xE9 une + * impossibilit\xE9 dans le traitement demand\xE9. Un message d'erreur renseigne sur + * le probl\xE8me. + * + * @author Emmanuel MARTIN + * @version $Id:$ + */ +public class DataGeometryException extends Exception { + + public DataGeometryException(String _message) { + super(_message); + } +} Property changes on: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/DataGeometryException.java ___________________________________________________________________ Added: svn:keywords + Id Added: svn:eol-style + native Modified: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/VueCourbe.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/VueCourbe.java 2008-12-15 16:28:55 UTC (rev 4304) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/VueCourbe.java 2008-12-17 17:44:49 UTC (rev 4305) @@ -139,11 +139,7 @@ return data_.getZMin(); } - /* (non-Javadoc) - * @see org.fudaa.ebli.courbe.EGModel#isDuplicatable() - */ public boolean isDuplicatable() { - // TODO Auto-generated method stub return false; } @@ -172,8 +168,14 @@ } public boolean removeValue(int _i, CtuluCommandContainer _cmd) { - data_.remove(_i); - return true; + try { + data_.remove(_i); + return true; + } + catch (DataGeometryException _exc) { + controller_.showError(_exc.getMessage()); + return false; + } } /* (non-Javadoc) @@ -189,8 +191,15 @@ } public boolean setValue(int _i, double _x, double _y, CtuluCommandContainer _cmd) { - data_.setValues(_i, _x, _y); - return true; + controller_.clearError(); + try { + data_.setValues(_i, _x, _y); + return true; + } + catch (DataGeometryException _exc) { + controller_.showError(_exc.getMessage()); + return false; + } } public boolean setValues(int[] _idx, double[] _x, double[] _y, CtuluCommandContainer _cmd) { Modified: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/VueTableau.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/VueTableau.java 2008-12-15 16:28:55 UTC (rev 4304) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/src/org/fudaa/fudaa/modeleur/modeleur1d/VueTableau.java 2008-12-17 17:44:49 UTC (rev 4305) @@ -82,15 +82,20 @@ } public void setValueAt(Object value, int rowIndex, int columnIndex) { + controller_.clearError(); if(columnIndex==0) - data_.setCurv(rowIndex, (Double) value); + try { + data_.setCurv(rowIndex, (Double) value); + } + catch (DataGeometryException _exc) { + controller_.showError(_exc.getMessage()); + } else data_.setZ(rowIndex, (Double) value); } } /** Le controller de la fen\xEAtre 1d. */ - @SuppressWarnings("unused") private Controller1d controller_; /** La vue du tableau. */ private JTable table_; Added: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/test/testModeleur1d/TestDataGeometryAdapter.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/test/testModeleur1d/TestDataGeometryAdapter.java (rev 0) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/test/testModeleur1d/TestDataGeometryAdapter.java 2008-12-17 17:44:49 UTC (rev 4305) @@ -0,0 +1,914 @@ +/* + * @creation 16 d\xE9c. 2008 + * @modification $Date:$ + * @license GNU General Public License 2 + * @copyright (c)1998-2008 CETMEF 2 bd Gambetta F-60231 Compiegne + * @mail fud...@li... + */ +package testModeleur1d; + +import junit.framework.TestCase; + +import org.fudaa.ctulu.gis.GISAttributeConstants; +import org.fudaa.ctulu.gis.GISAttributeInterface; +import org.fudaa.ctulu.gis.GISGeometryFactory; +import org.fudaa.ctulu.gis.GISPolyligne; +import org.fudaa.ctulu.gis.GISZoneCollectionLigneBrisee; +import org.fudaa.fudaa.modeleur.modeleur1d.DataGeometryAdapter; +import org.fudaa.fudaa.modeleur.modeleur1d.DataGeometryException; +import org.fudaa.fudaa.modeleur.modeleur1d.DataGeometryListener; + +import com.vividsolutions.jts.geom.Coordinate; + +/** + * Test pour DataGeometryAdapter. + * @author Emmanuel MARTIN + * @version $Id:$ + */ +public class TestDataGeometryAdapter extends TestCase { + + /** Tolerance pour les comparaisons de doubles. */ + private double tolerance=0.000001; + private DataGeometryAdapter geomAdapter_; + private GISZoneCollectionLigneBrisee zone0_; + private GISZoneCollectionLigneBrisee zone1_; + private GISZoneCollectionLigneBrisee zone3_; + private GISZoneCollectionLigneBrisee zone4_; + private GISZoneCollectionLigneBrisee zone5_; + private GISZoneCollectionLigneBrisee zone6_; + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + geomAdapter_=new DataGeometryAdapter(null, -1); + // Zone6_ \\ + // Attribut z non d\xE9fini + zone6_=new GISZoneCollectionLigneBrisee(); + zone6_.setAttributes(new GISAttributeInterface[]{GISAttributeConstants.BATHY}, null); + zone6_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(-10, -20, -20), + new Coordinate(50, 10, 10)}), null, null); + // Zone0_ \\ + // Quelconque + zone0_=new GISZoneCollectionLigneBrisee(); + zone0_.setAttributes(new GISAttributeInterface[]{GISAttributeConstants.BATHY}, null); + zone0_.setAttributeIsZ(GISAttributeConstants.BATHY); + zone0_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(-10, -20, -20), + new Coordinate(50, 10, 10)}), null, null); + // Zone1_ \\ + // Quelconque + zone1_=new GISZoneCollectionLigneBrisee(); + zone1_.setAttributes(new GISAttributeInterface[]{GISAttributeConstants.BATHY}, null); + zone1_.setAttributeIsZ(GISAttributeConstants.BATHY); + zone1_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory() + .create( + new Coordinate[]{new Coordinate(8, 6, 0), new Coordinate(5.052590034554651, 6.559262456806686, 0), + new Coordinate(3, 2, 0)}), null, null); + // Zone3_ \\ + // Quelconque + zone3_=new GISZoneCollectionLigneBrisee(); + zone3_.setAttributes(new GISAttributeInterface[]{GISAttributeConstants.BATHY}, null); + zone3_.setAttributeIsZ(GISAttributeConstants.BATHY); + zone3_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(-10, -20, -20), new Coordinate(50, 10, 10), + new Coordinate(30, 5, 5), new Coordinate(10, 0, 0)}), null, null); + zone3_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(5, 0, 0), new Coordinate(-15, -20, -20), new Coordinate(55, 10, 10), + new Coordinate(35, 5, -20), new Coordinate(15, 0, -20)}), null, null); + // zone4_ \\ + zone4_=new GISZoneCollectionLigneBrisee(); + zone4_.setAttributes(new GISAttributeInterface[]{GISAttributeConstants.BATHY}, null); + zone4_.setAttributeIsZ(GISAttributeConstants.BATHY); + // 0 : Points confondus + zone4_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(-10, -20, -20), new Coordinate(-10, -20, -20), + new Coordinate(-20, -40, -40), new Coordinate(-30, -60, -60)}), null, null); + // 1 : nb ruptures > 2 + zone4_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(10, 20, 5), new Coordinate(11, 100, 8), new Coordinate(41, 5, 9), new Coordinate(41, 0, 8)}), null, null); + // 2 : nb ruptures = 1 + zone4_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(11, 100, 8), new Coordinate(12, 101, 10), new Coordinate(13, 102, -5)}), null, null); + // 3 : nb ruptures = 0 + zone4_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(10, 20, 5), new Coordinate(20, 40, 8)}), null, null); + // 4 : nb ruptures = 2 + zone4_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(10, 10, 0), new Coordinate(20, 10, 5), new Coordinate(20, 20, 8), new Coordinate(25, 20, 8), new Coordinate(30, 20, 8)}), null, null); + // 5 : axes crois\xE9s + zone4_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(10, 10, 0), new Coordinate(20, 10, 5), new Coordinate(20, 20, 8), new Coordinate(10, 5, 8)}), null, null); + // Zone5_ \\ + zone5_=new GISZoneCollectionLigneBrisee(); + zone5_.setAttributes(new GISAttributeInterface[]{GISAttributeConstants.BATHY}, null); + zone5_.setAttributeIsZ(GISAttributeConstants.BATHY); + // 0 : 2 points align\xE9s (cas g\xE9n\xE9ral) + zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(10, 5, -4)}), null, null); + // 1 : 2 points align\xE9s parall\xE8le \xE0 l'axe des X + zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(5, 10, 3), new Coordinate(20, 10, -7)}), null, null); + // 2 : 2 points align\xE9s parall\xE8le \xE0 l'axe des Y + zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(5, 0, 0), new Coordinate(5, 10, 88)}), null, null); + // 3 : 3 points align\xE9s (cas g\xE9n\xE9ral) + zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, -2), new Coordinate(11, 5, 7), new Coordinate(16.5, 7.5, 0)}), null, null); + // 4 : 3 points align\xE9s parall\xE8le \xE0 l'axe des X + zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(-5, 10, 3), new Coordinate(20, 10, 6), new Coordinate(20.4, 10, 2)}), null, null); + // 5 : 3 points align\xE9s parall\xE8le \xE0 l'axe des Y + zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(-5, 10, 8), new Coordinate(-5, -2, -2), new Coordinate(-5, -50, 50)}), null, null); + // 6 : 4 points align\xE9s (cas g\xE9n\xE9ral) + zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(1, 1, 0), new Coordinate(2, 1, 3), new Coordinate(8, 5, -9), new Coordinate(40, 25, 99)}), null, null); + // 7 : 4 points align\xE9s parall\xE8le \xE0 l'axe des X + zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(1, 2.56, -2), new Coordinate(10, 2.56, 0), new Coordinate(99, 2.56, 84), new Coordinate(100.5, 2.56, 100)}), null, null); + // 8 : 4 points align\xE9s parall\xE8le \xE0 l'axe des Y + zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(-9.1, 88, 0), new Coordinate(-9.1, 50, 8), new Coordinate(-9.1, 0, -87), new Coordinate(-9.1, -10, -10)}), null, null); + // 9 : 3 points avec un point de rupture + zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(10, 5, 2), new Coordinate(10, -5, 9)}), null, null); + // 10 : 4 points avec un point de rupture (deux points sur le premier axe) + zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, -2), new Coordinate(11, 5, 7), new Coordinate(16.5, 7.5, 0), new Coordinate(50, 60, 70)}), null, null); + // 11 : 5 points avec un point de rupture (deux points sur chaque axe) + zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, -2), new Coordinate(11, 5, 7), new Coordinate(16.5, 7.5, 0), new Coordinate(33, 3.75, 9), new Coordinate(11, 1.25, 9)}), null, null); + // 12 : 4 points avec deux points de ruptures + zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(10, 5, 2), new Coordinate(10, -5, 9), new Coordinate(20, 0, 0)}), null, null); + // 13 : 5 points avec deux points de ruptures (deux points sur le premier axe) + zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(5, 2.5, 88), new Coordinate(10, 5, 2), new Coordinate(10, -5, 9), new Coordinate(20, 0, 0)}), null, null); + // 14 : 6 points avec deux points de ruptures (deux points sur les deux premiers axes) + zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(5, 2.5, 88), new Coordinate(10, 5, 2), new Coordinate(10, 0, 44), new Coordinate(10, -5, 9), new Coordinate(20, 0, 0)}), null, null); + // 15 : 7 points avec deux points de ruptures (deux points sur chacun des axes) + zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(5, 2.5, 88), new Coordinate(10, 5, 2), new Coordinate(10, 0, 44), new Coordinate(10, -5, 9), new Coordinate(15, -2.5, 2), new Coordinate(20, 0, 0)}), null, null); + // 16 : 10 points avec deux points de ruptures (trois points sur chacun des axes) + zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(2.5, 1.25, 44), new Coordinate(5, 2.5, 88), new Coordinate(10, 5, 2), new Coordinate(10, 0, 44), new Coordinate(10, -2, 0), new Coordinate(10, -5, 9), new Coordinate(10/2., -5/2., 2), new Coordinate(10/4., -5/4., 0), new Coordinate(10/8., -5/8., 0)}), null, null); + // 17 : 3 points avec un point de rupture et le premier et le dernier points sont sur le m\xEAme axe des y + zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(5, 5, -9), new Coordinate(10, 10, 0), new Coordinate(5, 20, 0)}), null, null); + // 18 : 3 points avec un point de rupture et le premier et le dernier points sont sur le m\xEAme axe des x + zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(5, 5, -9), new Coordinate(10, 10, 0), new Coordinate(20, 5, 0)}), null, null); + } + + public void testDataGeometryAdapter() throws IllegalArgumentException, DataGeometryException { + // Points confondus + try { + new DataGeometryAdapter(zone4_, 0); + fail(); + } + catch (IllegalArgumentException _exc) { + fail(); + } + catch (DataGeometryException _exc) {} + // nb points > 2 + try { + new DataGeometryAdapter(zone4_, 1); + fail(); + } + catch (IllegalArgumentException _exc) { + fail(); + } + catch (DataGeometryException _exc) {} + // nb ruptures = 1 + try { + new DataGeometryAdapter(zone4_, 2); + } + catch (IllegalArgumentException _exc) { + fail(); + } + catch (DataGeometryException _exc) { + fail(); + } + // nb ruptures = 0 + try { + new DataGeometryAdapter(zone4_, 3); + } + catch (IllegalArgumentException _exc) { + fail(); + } + catch (DataGeometryException _exc) { + fail(); + } + // nb ruptures = 2 + try { + new DataGeometryAdapter(zone4_, 4); + } + catch (IllegalArgumentException _exc) { + fail(); + } + catch (DataGeometryException _exc) { + fail(); + } + // axes crois\xE9s + try { + new DataGeometryAdapter(zone4_, 5); + fail(); + } + catch (IllegalArgumentException _exc) { + fail(); + } + catch (DataGeometryException _exc) { + } + // aguments invalide + geomAdapter_=new DataGeometryAdapter(null, -1); + assertNull(geomAdapter_.getGISZoneCollection()); + assertEquals(-1, geomAdapter_.getIdxGeom()); + // aguments invalide + try { + geomAdapter_=new DataGeometryAdapter(null, 0); + fail(); + } + catch (IllegalArgumentException _exc) { + assertNull(geomAdapter_.getGISZoneCollection()); + assertEquals(-1, geomAdapter_.getIdxGeom()); + } + catch (DataGeometryException _exc) { + fail(); + } + // aguments invalide + try { + geomAdapter_=new DataGeometryAdapter(null, 1); + fail(); + } + catch (IllegalArgumentException _exc) { + assertNull(geomAdapter_.getGISZoneCollection()); + assertEquals(-1, geomAdapter_.getIdxGeom()); + } + catch (DataGeometryException _exc) { + fail(); + } + // aguments invalide + try { + geomAdapter_=new DataGeometryAdapter(zone4_, -1); + fail(); + } + catch (IllegalArgumentException _exc) { + assertNull(geomAdapter_.getGISZoneCollection()); + assertEquals(-1, geomAdapter_.getIdxGeom()); + } + catch (DataGeometryException _exc) { + fail(); + } + // aguments invalide + try { + geomAdapter_=new DataGeometryAdapter(zone4_, -10); + fail(); + } + catch (IllegalArgumentException _exc) { + assertNull(geomAdapter_.getGISZoneCollection()); + assertEquals(-1, geomAdapter_.getIdxGeom()); + } + catch (DataGeometryException _exc) { + fail(); + } + // aguments invalide + try { + geomAdapter_=new DataGeometryAdapter(zone4_, zone4_.getNbGeometries()); + fail(); + } + catch (IllegalArgumentException _exc) { + assertNull(geomAdapter_.getGISZoneCollection()); + assertEquals(-1, geomAdapter_.getIdxGeom()); + } + catch (DataGeometryException _exc) { + fail(); + } + // aguments invalide + try { + geomAdapter_=new DataGeometryAdapter(zone4_, zone4_.getNbGeometries()+1); + fail(); + } + catch (IllegalArgumentException _exc) { + assertNull(geomAdapter_.getGISZoneCollection()); + assertEquals(-1, geomAdapter_.getIdxGeom()); + } + catch (DataGeometryException _exc) { + fail(); + } + // aguments valide + try { + new DataGeometryAdapter(zone3_, zone3_.getNbGeometries()-1); + } + catch (IllegalArgumentException _exc) { + fail(); + } + catch (DataGeometryException _exc) { + fail(); + } + } + + public void testSetData() throws IllegalArgumentException, DataGeometryException { + // Zone sans attribut Z d\xE9fini + try{ + geomAdapter_.setData(zone6_, 0); + } + catch (DataGeometryException _exc) { + fail(); + } + catch(IllegalArgumentException _exc){} + // Points confondus + try { + new DataGeometryAdapter(zone4_, 0); + fail(); + } + catch (IllegalArgumentException _exc) { + fail(); + } + catch (DataGeometryException _exc) {} + // nb points > 2 + try { + new DataGeometryAdapter(zone4_, 1); + fail(); + } + catch (IllegalArgumentException _exc) { + fail(); + } + catch (DataGeometryException _exc) {} + // nb ruptures = 1 + try { + new DataGeometryAdapter(zone4_, 2); + } + catch (IllegalArgumentException _exc) { + fail(); + } + catch (DataGeometryException _exc) { + fail(); + } + // nb ruptures = 0 + try { + new DataGeometryAdapter(zone4_, 3); + } + catch (IllegalArgumentException _exc) { + fail(); + } + catch (DataGeometryException _exc) { + fail(); + } + // nb ruptures = 2 + try { + new DataGeometryAdapter(zone4_, 4); + } + catch (IllegalArgumentException _exc) { + fail(); + } + catch (DataGeometryException _exc) { + fail(); + } + // axes crois\xE9s + try { + new DataGeometryAdapter(zone4_, 5); + fail(); + } + catch (IllegalArgumentException _exc) { + fail(); + } + catch (DataGeometryException _exc) { + } + // aguments invalide + geomAdapter_=new DataGeometryAdapter(null, -1); + assertNull(geomAdapter_.getGISZoneCollection()); + assertEquals(-1, geomAdapter_.getIdxGeom()); + // aguments invalide + try { + geomAdapter_=new DataGeometryAdapter(null, 0); + fail(); + } + catch (IllegalArgumentException _exc) { + assertNull(geomAdapter_.getGISZoneCollection()); + assertEquals(-1, geomAdapter_.getIdxGeom()); + } + catch (DataGeometryException _exc) { + fail(); + } + // aguments invalide + try { + geomAdapter_=new DataGeometryAdapter(null, 1); + fail(); + } + catch (IllegalArgumentException _exc) { + assertNull(geomAdapter_.getGISZoneCollection()); + assertEquals(-1, geomAdapter_.getIdxGeom()); + } + catch (DataGeometryException _exc) { + fail(); + } + // aguments invalide + try { + geomAdapter_=new DataGeometryAdapter(zone4_, -1); + fail(); + } + catch (IllegalArgumentException _exc) { + assertNull(geomAdapter_.getGISZoneCollection()); + assertEquals(-1, geomAdapter_.getIdxGeom()); + } + catch (DataGeometryException _exc) { + fail(); + } + // aguments invalide + try { + geomAdapter_=new DataGeometryAdapter(zone4_, -10); + fail(); + } + catch (IllegalArgumentException _exc) { + assertNull(geomAdapter_.getGISZoneCollection()); + assertEquals(-1, geomAdapter_.getIdxGeom()); + } + catch (DataGeometryException _exc) { + fail(); + } + // aguments invalide + try { + geomAdapter_=new DataGeometryAdapter(zone4_, zone4_.getNbGeometries()); + fail(); + } + catch (IllegalArgumentException _exc) { + assertNull(geomAdapter_.getGISZoneCollection()); + assertEquals(-1, geomAdapter_.getIdxGeom()); + } + catch (DataGeometryException _exc) { + fail(); + } + // aguments invalide + try { + geomAdapter_=new DataGeometryAdapter(zone4_, zone4_.getNbGeometries()+1); + fail(); + } + ... [truncated message content] |