From 4610d2cdacddd2bfc4582c9778a838590457e85c Mon Sep 17 00:00:00 2001
From: Bastien Gorissen <bastien.gorissen@cenaero.be>
Date: Tue, 5 Jan 2010 11:07:08 +0000
Subject: [PATCH] Removes a bug occuring when matched edges aren't parametrized
 in the same direction as the original geometrical edge.

---
 Geo/GEdge.cpp           | 2 +-
 Geo/GModel.cpp          | 5 ++++-
 Geo/GeomMeshMatcher.cpp | 8 ++++++++
 Mesh/HighOrder.cpp      | 5 -----
 4 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/Geo/GEdge.cpp b/Geo/GEdge.cpp
index d693619f3d..55c356f17f 100644
--- a/Geo/GEdge.cpp
+++ b/Geo/GEdge.cpp
@@ -297,7 +297,7 @@ bool GEdge::XYZToU(const double X, const double Y, const double Z,
   double uMin = uu.low();
   double uMax = uu.high();
 
-  printf("dans GEdge uMin=%g, uMax=%g \n", uMin, uMax);
+  // printf("dans GEdge uMin=%g, uMax=%g \n", uMin, uMax);
 
   SVector3 Q(X, Y, Z), P;
   
diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp
index db55455256..012d00644b 100644
--- a/Geo/GModel.cpp
+++ b/Geo/GModel.cpp
@@ -795,7 +795,10 @@ void GModel::_storeElementsInEntities(std::map<int, std::vector<MElement*> > &ma
           v = new discreteVertex(this, it->first);
           add(v);
         }
-        if(!v->points.empty()) v->points.clear();  // CAD points already have one by default
+        if(!v->points.empty()) {
+	  v->points.clear();
+	  v->mesh_vertices.clear();
+	}  // CAD points already have one by default
 	  _addElements(v->points, it->second);
       }
       break;
diff --git a/Geo/GeomMeshMatcher.cpp b/Geo/GeomMeshMatcher.cpp
index e77e44f3d0..9a32a9daaf 100644
--- a/Geo/GeomMeshMatcher.cpp
+++ b/Geo/GeomMeshMatcher.cpp
@@ -210,6 +210,14 @@ GeomMeshMatcher::matchEdges(GModel* m1, GModel* m2,
     coresp_e->push_back(Pair<GEdge*,GEdge*>((GEdge*) *entity1 ,
                                              choice));
     choice->setTag(((GEdge*) *entity1)->tag());
+
+    // This reverses the edge if it's not parametrized in the right direction
+    if (choice->getBeginVertex() == findMatching<GVertex*>(*coresp_v,v2) &&
+	choice->getEndVertex() == findMatching<GVertex*>(*coresp_v,v1)) {
+      Msg::Info("Wrong parametrization direction, reversing.");
+      choice->reverse();
+    }
+
     num_matched_edges++;
   }
 
diff --git a/Mesh/HighOrder.cpp b/Mesh/HighOrder.cpp
index a666efa23d..b36767ecd9 100644
--- a/Mesh/HighOrder.cpp
+++ b/Mesh/HighOrder.cpp
@@ -258,11 +258,6 @@ static void getEdgeVertices(GEdge *ge, MElement *ele, std::vector<MVertex*> &ve,
         else
           reparamOK &= reparamMeshVertexOnEdge(v1, ge, u1);
         if(reparamOK){
-	  if (u1 < u0) {
-	    ge->reverse();
-	    edge = ele->getEdge(i);
-	    double tmp = u0; u0 = u1; u1 = tmp;
-	  }
           double relax = 1.;
           while (1){
             if(computeEquidistantParameters(ge, u0, u1, nPts + 2, US, relax)) 
-- 
GitLab