From d49e1793a5adb5ca46aaa868b3cf7d4f3a60348f Mon Sep 17 00:00:00 2001 From: Thomas De Maet <thomas.demaet@uclouvain.be> Date: Tue, 25 Sep 2012 16:59:34 +0000 Subject: [PATCH] isinside: security for dims > dimElmt --- Geo/MElementOctree.cpp | 51 +++++++++++++++++++++--------------------- Geo/MLine.h | 2 +- Geo/MQuadrangle.h | 2 +- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/Geo/MElementOctree.cpp b/Geo/MElementOctree.cpp index ff352299a0..2c7f841ff7 100644 --- a/Geo/MElementOctree.cpp +++ b/Geo/MElementOctree.cpp @@ -132,8 +132,7 @@ std::vector<MElement *> MElementOctree::findAll(double x, double y, double z, in std::vector<void*> v; std::vector<MElement*> e; Octree_SearchAll(P, _octree,&v); - for (std::vector<void*>::iterator it = v.begin(); - it != v.end(); ++it){ + for (std::vector<void*>::iterator it = v.begin(); it != v.end(); ++it) { MElement *el = (MElement*) *it; if (dim == -1 || el->getDim() == dim)e.push_back(el); } @@ -146,14 +145,14 @@ std::vector<MElement *> MElementOctree::findAll(double x, double y, double z, in std::vector<GEntity*> entities; _gm->getEntities(entities); for(unsigned int i = 0; i < entities.size(); i++){ - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ - MElement* el = entities[i]->getMeshElement(j); - if (dim == -1 || el->getDim() == dim){ - if (MElementInEle(el, P)){ + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + MElement* el = entities[i]->getMeshElement(j); + if (dim == -1 || el->getDim() == dim){ + if (MElementInEle(el, P)){ e.push_back(el); - } - } - } + } + } + } } if(!e.empty()) { MElement::setTolerance(initialTol); @@ -212,15 +211,15 @@ MElement *MElementOctree::find(double x, double y, double z, int dim, bool stric std::vector<GEntity*> entities; _gm->getEntities(entities); for(unsigned int i = 0; i < entities.size(); i++){ - for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ - e = entities[i]->getMeshElement(j); - if (dim == -1 || e->getDim() == dim){ - if (MElementInEle(e, P)){ - MElement::setTolerance(initialTol); - return e; - } - } - } + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + e = entities[i]->getMeshElement(j); + if (dim == -1 || e->getDim() == dim){ + if (MElementInEle(e, P)) { + MElement::setTolerance(initialTol); + return e; + } + } + } } } MElement::setTolerance(initialTol); @@ -233,14 +232,14 @@ MElement *MElementOctree::find(double x, double y, double z, int dim, bool stric tol *= 10.0; MElement::setTolerance(tol); for(unsigned int i = 0; i < _elems.size(); i++){ - e = _elems[i]; - if (dim == -1 || e->getDim() == dim){ - if (MElementInEle(e, P)){ - MElement::setTolerance(initialTol); - return e; - } - } - } + e = _elems[i]; + if (dim == -1 || e->getDim() == dim){ + if (MElementInEle(e, P)){ + MElement::setTolerance(initialTol); + return e; + } + } + } } MElement::setTolerance(initialTol); //Msg::Warning("Point %g %g %g not found",x,y,z); diff --git a/Geo/MLine.h b/Geo/MLine.h index f5231ff9f9..68a22428c5 100644 --- a/Geo/MLine.h +++ b/Geo/MLine.h @@ -76,7 +76,7 @@ class MLine : public MElement { virtual bool isInside(double u, double v, double w) { double tol = _isInsideTolerance; - if(u < -(1. + tol) || u > (1. + tol)) + if(u < -(1. + tol) || u > (1. + tol) || fabs(v) > tol || fabs(w) > tol) return false; return true; } diff --git a/Geo/MQuadrangle.h b/Geo/MQuadrangle.h index 4484c1dad8..65d1fde7cd 100644 --- a/Geo/MQuadrangle.h +++ b/Geo/MQuadrangle.h @@ -140,7 +140,7 @@ class MQuadrangle : public MElement { virtual bool isInside(double u, double v, double w) { double tol = _isInsideTolerance; - if(u < -(1. + tol) || v < -(1. + tol) || u > (1. + tol) || v > (1. + tol)) + if(u < -(1. + tol) || v < -(1. + tol) || u > (1. + tol) || v > (1. + tol) || fabs(w) > tol) return false; return true; } -- GitLab