X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FINTERP_KERNEL%2FVectorUtils.hxx;h=efb5937ba61b70078f7548e571e5b0bb661e0d4f;hb=b832b15337be013a56e0976170e5e235b89fcb03;hp=b261b453327f38bfce441e000d6c430fda53c85b;hpb=8763c12d01e33d6845dd53be65b001514d00bd42;p=tools%2Fmedcoupling.git diff --git a/src/INTERP_KERNEL/VectorUtils.hxx b/src/INTERP_KERNEL/VectorUtils.hxx index b261b4533..efb5937ba 100644 --- a/src/INTERP_KERNEL/VectorUtils.hxx +++ b/src/INTERP_KERNEL/VectorUtils.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2014 CEA/DEN, EDF R&D +// Copyright (C) 2007-2024 CEA, EDF // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -20,12 +20,14 @@ #ifndef __VECTORUTILS_HXX__ #define __VECTORUTILS_HXX__ +#include #include #include #include #include #include + namespace INTERP_KERNEL { /// Precision used for tests of 3D part of INTERP_KERNEL @@ -145,6 +147,29 @@ 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); + } + + /** + * Caracteristic vector size (its biggest component, in absolute) + */ + inline double caracteristicDimVector(const double *v) + { + double ret = 0; + for (int i = 0; i < 3; i++) + ret = std::max(ret, std::fabs(v[i])); + return ret; + } + /** * Compares doubles using a relative tolerance * This is suitable mainly for comparing larger values to each other. Before performing the relative test, @@ -170,6 +195,23 @@ namespace INTERP_KERNEL return relError < relTol; } + inline double sumOfAbsoluteValues(const double row[3]) + { + double ret(0.); + std::for_each(row,row+3,[&ret](double v) { ret += std::abs(v); }); + return ret; + } + + /*! + * Returns the infinite norm of a 3x3 input matrix \a mat. + * The max of absolute value of row sum. + */ + inline double normInf(const double mat[9]) + { + double ret(std::max(sumOfAbsoluteValues(mat),sumOfAbsoluteValues(mat+3))); + return std::max(ret,sumOfAbsoluteValues(mat+6)); + } + } #endif