Salome HOME
Some factorization before integration of ParaMEDMEM into medcoupling python module
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingMemArray.cxx
index 91bef50389f19b4805a8f2d441ed511c2dd2aa22..1c20ae77a9f198dd182c98c20607c6e5faa5e5a2 100644 (file)
 #include "InterpKernelAutoPtr.hxx"
 #include "InterpKernelExprParser.hxx"
 
+#include "InterpKernelAutoPtr.hxx"
+#include "InterpKernelGeo2DEdgeArcCircle.hxx"
+#include "InterpKernelAutoPtr.hxx"
+#include "InterpKernelGeo2DNode.hxx"
+#include "InterpKernelGeo2DEdgeLin.hxx"
+
 #include <set>
 #include <cmath>
 #include <limits>
@@ -631,7 +637,7 @@ void DataArray::CheckValueInRange(int ref, int value, const std::string& msg)
 
 /*!
  * This method checks that [\b start, \b end) is compliant with ref length \b value.
- * typicaly start in [0,\b value) and end in [0,\b value). If value==start and start==end, it is supported.
+ * typically start in [0,\b value) and end in [0,\b value). If value==start and start==end, it is supported.
  */
 void DataArray::CheckValueInRangeEx(int value, int start, int end, const std::string& msg)
 {
@@ -1611,7 +1617,7 @@ double DataArrayDouble::norm2() const
 
 /*!
  * Returns the maximum norm of the vector defined by \a this array.
- * This method works even if the number of components is diferent from one.
+ * This method works even if the number of components is different from one.
  * If the number of elements in \a this is 0, -1. is returned.
  *  \return double - the value of the maximum norm, i.e.
  *          the maximal absolute value among values of \a this array (whatever its number of components).
@@ -1634,7 +1640,7 @@ double DataArrayDouble::normMax() const
 
 /*!
  * Returns the minimum norm (absolute value) of the vector defined by \a this array.
- * This method works even if the number of components is diferent from one.
+ * This method works even if the number of components is different from one.
  * If the number of elements in \a this is 0, std::numeric_limits<double>::max() is returned.
  *  \return double - the value of the minimum norm, i.e.
  *          the minimal absolute value among values of \a this array (whatever its number of components).
@@ -2489,6 +2495,38 @@ DataArrayDouble *DataArrayDouble::buildEuclidianDistanceDenseMatrixWith(const Da
   return ret.retn();
 }
 
+/*!
+ * This method expects that \a this stores 3 tuples containing 2 components each.
+ * Each of this tuples represent a point into 2D space.
+ * This method tries to find an arc of circle starting from first point (tuple) to 2nd and middle point (tuple) along 3nd and last point (tuple).
+ * If such arc of circle exists, the corresponding center, radius of circle is returned. And additionnaly the length of arc expressed with an \a ang output variable in ]0,2*pi[.
+ *  
+ *  \throw If \a this is not allocated.
+ *  \throw If \a this has not 3 tuples of 2 components
+ *  \throw If tuples/points in \a this are aligned
+ */
+void DataArrayDouble::asArcOfCircle(double center[2], double& radius, double& ang) const
+{
+  checkAllocated();
+  INTERP_KERNEL::QuadraticPlanarArcDetectionPrecision arcPrec(1e-14);
+  if(getNumberOfTuples()!=3 && getNumberOfComponents()!=2)
+    throw INTERP_KERNEL::Exception("DataArrayDouble::asArcCircle : this method expects");
+  const double *pt(begin());
+  MCAuto<INTERP_KERNEL::Node> n0(new INTERP_KERNEL::Node(pt[0],pt[1])),n1(new INTERP_KERNEL::Node(pt[2],pt[3])),n2(new INTERP_KERNEL::Node(pt[4],pt[5]));
+  {
+    INTERP_KERNEL::AutoCppPtr<INTERP_KERNEL::EdgeLin> e1(new INTERP_KERNEL::EdgeLin(n0,n2)),e2(new INTERP_KERNEL::EdgeLin(n2,n1));
+    INTERP_KERNEL::SegSegIntersector inters(*e1,*e2);
+    bool colinearity(inters.areColinears());
+    if(colinearity)
+      throw INTERP_KERNEL::Exception("DataArrayDouble::asArcOfCircle : 3 points in this have been detected as colinear !");
+  }
+  INTERP_KERNEL::AutoCppPtr<INTERP_KERNEL::EdgeArcCircle> ret(new INTERP_KERNEL::EdgeArcCircle(n0,n2,n1));
+  const double *c(ret->getCenter());
+  center[0]=c[0]; center[1]=c[1];
+  radius=ret->getRadius();
+  ang=ret->getAngle();
+}
+
 /*!
  * Sorts value within every tuple of \a this array.
  *  \param [in] asc - if \a true, the values are sorted in ascending order, else,
@@ -4212,7 +4250,7 @@ DataArrayInt *DataArrayInt::checkAndPreparePermutation() const
 }
 
 /*!
- * This method tries to find the permutation to apply to the first input \a ids1 to obtain the same array (without considering strings informations) the second
+ * This method tries to find the permutation to apply to the first input \a ids1 to obtain the same array (without considering strings information) the second
  * input array \a ids2.
  * \a ids1 and \a ids2 are expected to be both a list of ids (both with number of components equal to one) not sorted and with values that can be negative.
  * This method will throw an exception is no such permutation array can be obtained. It is typically the case if there is some ids in \a ids1 not in \a ids2 or
@@ -5567,7 +5605,7 @@ DataArrayInt *DataArrayInt::BuildListOfSwitchedOff(const std::vector<bool>& v)
 }
 
 /*!
- * This method allows to put a vector of vector of integer into a more compact data stucture (skyline). 
+ * This method allows to put a vector of vector of integer into a more compact data structure (skyline). 
  * This method is not available into python because no available optimized data structure available to map std::vector< std::vector<int> >.
  *
  * \param [in] v the input data structure to be translate into skyline format.
@@ -5791,7 +5829,7 @@ DataArrayInt *DataArrayInt::buildUniqueNotSorted() const
  * "MEDCouplingUMesh::buildDescendingConnectivity" and
  * \ref MEDCoupling::MEDCouplingUMesh::getNodalConnectivityIndex
  * "MEDCouplingUMesh::getNodalConnectivityIndex" etc.
- * This method preforms the reverse operation of DataArrayInt::computeOffsetsFull.
+ * This method performs the reverse operation of DataArrayInt::computeOffsetsFull.
  *  \return DataArrayInt * - a new instance of DataArrayInt, whose number of tuples
  *          equals to \a this->getNumberOfComponents() - 1, and number of components is 1.
  *          The caller is to delete this array using decrRef() as it is no more needed. 
@@ -5867,7 +5905,7 @@ void DataArrayInt::computeOffsets()
  * components remains the same and number of tuples is inceamented by one.<br>
  * This method is useful for allToAllV in MPI with contiguous policy. This method
  * differs from computeOffsets() in that the number of tuples is changed by this one.
- * This method preforms the reverse operation of DataArrayInt::deltaShiftIndex.
+ * This method performs the reverse operation of DataArrayInt::deltaShiftIndex.
  *  \throw If \a this is not allocated.
  *  \throw If \a this->getNumberOfComponents() != 1.
  *