Salome HOME
Extra deps update
[tools/medcoupling.git] / src / INTERP_KERNEL / VectorUtils.hxx
index 469b46b53774b79009ca26ed62dd0921736ee6b8..00b2bf042cb1f20d28ccbfd5ccc6a9deda64d998 100644 (file)
@@ -1,41 +1,44 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2016  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.
+// 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, 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
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #ifndef __VECTORUTILS_HXX__
 #define __VECTORUTILS_HXX__
 
+#include <algorithm>
 #include <sstream>
 #include <numeric>
 #include <string>
 #include <cmath>
 #include <map>
 
-/// Precision used for tests of 3D part of INTERP_KERNEL
-#define VOL_PREC 1.0e-6
-
-/// Default relative tolerance in epsilonEqualRelative
-#define DEFAULT_REL_TOL 1.0e-6
-
-/// Default absolute tolerance in epsilonEqual and epsilonEqualRelative
-#define DEFAULT_ABS_TOL 5.0e-12
 
 namespace INTERP_KERNEL
 {
+  /// Precision used for tests of 3D part of INTERP_KERNEL
+  const double VOL_PREC = 1.0e-6;
+  
+  /// Default relative tolerance in epsilonEqualRelative
+  const double DEFAULT_REL_TOL = 1.0e-6;
+  
+  /// Default absolute tolerance in epsilonEqual and epsilonEqualRelative
+  const double DEFAULT_ABS_TOL = 5.0e-12;
+
   /**
    * @param a first point. Should point on a array of size at least equal to SPACEDIM.
    * @param b second point. Should point on a array of size at least equal to SPACEDIM.
@@ -79,6 +82,19 @@ namespace INTERP_KERNEL
     return ss.str();
   }
 
+  /**
+   * Adds a double[3] - vector to another one.
+   *
+   * @param v     vector v
+   * @param res   vector in which to store the result res + v.
+   */
+  inline void add(const double* v, double* res)
+  {
+    res[0] += v[0];
+    res[1] += v[1];
+    res[2] += v[2];
+  }
+
   /**
    * Calculates the cross product of two double[3] - vectors.
    *
@@ -131,6 +147,19 @@ namespace INTERP_KERNEL
     //    return std::fabs(x - y) < errTol;
   }
 
+
+  /**
+   * Test whether two 3D vectors are colinear. The two vectors are expected to be of unit norm (not checked)
+   * Implemented by checking that the norm of the cross product is null.
+   */
+  inline bool isColinear3D(const double *v1, const double *v2, const double eps = DEFAULT_ABS_TOL)
+  {
+    double cros[3];
+    cross(v1, v2, cros);
+    return epsilonEqual(dot(cros, cros), 0.0, eps);
+  }
+
+
   /**
    * Compares doubles using a relative tolerance
    * This is suitable mainly for comparing larger values to each other. Before performing the relative test,