Salome HOME
Copyright update 2022
[tools/medcoupling.git] / src / INTERP_KERNEL / Geometric2D / InterpKernelGeo2DNode.cxx
index e345cccf70b37c8e3a8f207705b4babd6a896a75..47ec4e8887dd0ac856753f9b21285046fb081480 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2022  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -93,7 +93,7 @@ double Node::distanceWithSq(const Node& other) const
 
 /*!
  * WARNING different from 'computeAngle' method ! The returned value are not in the same interval !
- * Here in -Pi/2; Pi/2. Typically this method returns the same value by exchanging pt1 and pt2.
+ * Here in [0; Pi). Typically this method returns the same value by exchanging pt1 and pt2.
  * Use in process of detection of a point in or not in polygon.
  */
 double Node::computeSlope(const double *pt1, const double *pt2)
@@ -148,19 +148,19 @@ void Node::unApplySimilarity(double xBary, double yBary, double dimChar)
 /*!
  * Called by QuadraticPolygon::splitAbs method.
  */
-void Node::fillGlobalInfoAbs(const std::map<INTERP_KERNEL::Node *,int>& mapThis, const std::map<INTERP_KERNEL::Node *,int>& mapOther, int offset1, int offset2, double fact, double baryX, double baryY,
-                             std::vector<double>& addCoo, std::map<INTERP_KERNEL::Node *,int>& mapAddCoo, int *nodeId) const
+void Node::fillGlobalInfoAbs(const std::map<INTERP_KERNEL::Node *,mcIdType>& mapThis, const std::map<INTERP_KERNEL::Node *,mcIdType>& mapOther, mcIdType offset1, mcIdType offset2, double fact, double baryX, double baryY,
+                             std::vector<double>& addCoo, std::map<INTERP_KERNEL::Node *,mcIdType>& mapAddCoo, mcIdType *nodeId) const
 {
-  std::map<INTERP_KERNEL::Node *,int>::const_iterator it=mapThis.find(const_cast<Node *>(this));
-  if(it!=mapThis.end())
+  std::map<INTERP_KERNEL::Node *,mcIdType>::const_iterator it=mapOther.find(const_cast<Node *>(this));
+  if(it!=mapOther.end())     // order matters, try in mapOther first.
     {
-      *nodeId=(*it).second;
+      *nodeId=(*it).second+offset1;
       return;
     }
-  it=mapOther.find(const_cast<Node *>(this));
-  if(it!=mapOther.end())
+  it=mapThis.find(const_cast<Node *>(this));
+  if(it!=mapThis.end())
     {
-      *nodeId=(*it).second+offset1;
+      *nodeId=(*it).second;
       return;
     }
   it=mapAddCoo.find(const_cast<Node *>(this));
@@ -179,20 +179,21 @@ void Node::fillGlobalInfoAbs(const std::map<INTERP_KERNEL::Node *,int>& mapThis,
 /*!
  * Called by QuadraticPolygon::splitAbs method.
  */
-void Node::fillGlobalInfoAbs2(const std::map<INTERP_KERNEL::Node *,int>& mapThis, const std::map<INTERP_KERNEL::Node *,int>& mapOther, int offset1, int offset2, double fact, double baryX, double baryY,
-                              std::vector<double>& addCoo, std::map<INTERP_KERNEL::Node *,int>& mapAddCoo, std::vector<int>& pointsOther) const
+void Node::fillGlobalInfoAbs2(const std::map<INTERP_KERNEL::Node *,mcIdType>& mapThis, const std::map<INTERP_KERNEL::Node *,mcIdType>& mapOther, mcIdType offset1, mcIdType offset2, double fact, double baryX, double baryY,
+                              std::vector<double>& addCoo, std::map<INTERP_KERNEL::Node *,mcIdType>& mapAddCoo, std::vector<mcIdType>& pointsOther) const
 {
-  int tmp;
+  mcIdType tmp;
   std::size_t sz1=addCoo.size();
   fillGlobalInfoAbs(mapThis,mapOther,offset1,offset2,fact,baryX,baryY,addCoo,mapAddCoo,&tmp);
-  if(sz1!=addCoo.size())
+  if(sz1!=addCoo.size()     // newly created point
+      || (tmp >= offset2    // or previously created point merged with a neighbour
+          && (pointsOther.size() == 0 || pointsOther.back() != tmp)))
     {
       pointsOther.push_back(tmp);
       return ;
     }
-  std::vector<int>::const_iterator it=std::find(pointsOther.begin(),pointsOther.end(),tmp);
+  std::vector<mcIdType>::const_iterator it=std::find(pointsOther.begin(),pointsOther.end(),tmp);
   if(it!=pointsOther.end())
     return ;
-  if(tmp<offset1)
-    pointsOther.push_back(tmp);
+  pointsOther.push_back(tmp);
 }