Salome HOME
Update copyrights
[modules/shaper.git] / src / ModelGeomAlgo / ModelGeomAlgo_Point2D.cpp
old mode 100755 (executable)
new mode 100644 (file)
index a7fe103..6eff0ea
@@ -1,8 +1,21 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        ModelAPI_Tools.cpp
-// Created:     20 Jul 2016
-// Author:      Natalia ERMOLAEVA
+// Copyright (C) 2014-2019  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, 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.
+//
+// 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
+//
 
 #include "ModelGeomAlgo_Point2D.h"
 
@@ -26,6 +39,7 @@
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Lin.h>
 #include <GeomAPI_Circ.h>
+#include <GeomAPI_ShapeExplorer.h>
 
 //#define DEBUG_POINT_INSIDE_SHAPE
 #ifdef DEBUG_POINT_INSIDE_SHAPE
@@ -281,7 +295,7 @@ void ModelGeomAlgo_Point2D::getPointsInsideShape(
     std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = anAttribute->pnt();
     std::shared_ptr<GeomAPI_Pnt> aPoint = aPnt2d->to3D(theOrigin, theDirX, theDirY);
     std::shared_ptr<GeomAPI_Pnt> aProjectedPoint;
-    if (isPointOnEdge(theBaseShape, aPoint, aProjectedPoint)) {
+    if (isInnerPointOnEdge(theBaseShape, aPoint, aProjectedPoint)) {
       if (thePointToAttributeOrObject.find(aProjectedPoint) != thePointToAttributeOrObject.end())
         thePointToAttributeOrObject.at(aProjectedPoint).first.push_back(anAttribute);
       else {
@@ -322,7 +336,7 @@ void ModelGeomAlgo_Point2D::getPointsInsideShape_p(
     std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = anAttribute->pnt();
     std::shared_ptr<GeomAPI_Pnt> aPoint = aPnt2d->to3D(theOrigin, theDirX, theDirY);
     std::shared_ptr<GeomAPI_Pnt> aProjectedPoint;
-    if (isPointOnEdge(theBaseShape, aPoint, aProjectedPoint)) {
+    if (isInnerPointOnEdge(theBaseShape, aPoint, aProjectedPoint)) {
       thePoints.push_back(aProjectedPoint);
       theAttributeToPoint[anAttribute] = aProjectedPoint;
     }
@@ -353,6 +367,28 @@ bool ModelGeomAlgo_Point2D::isPointOnEdge(const std::shared_ptr<GeomAPI_Shape> t
   return isInside;
 }
 
+
+bool ModelGeomAlgo_Point2D::isInnerPointOnEdge(const std::shared_ptr<GeomAPI_Shape> theBaseShape,
+                     const std::shared_ptr<GeomAPI_Pnt>& thePoint,
+                     std::shared_ptr<GeomAPI_Pnt>& theProjectedPoint)
+{
+  bool isInside = isPointOnEdge(theBaseShape, thePoint, theProjectedPoint);
+  if (isInside) {
+    std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theBaseShape));
+    if (!anEdge->isCircle()) {
+      // check the point is not on the boundary
+      GeomVertexPtr aVertex(new GeomAPI_Vertex(theProjectedPoint->x(),
+          theProjectedPoint->y(), theProjectedPoint->z()));
+      GeomAPI_ShapeExplorer anExp(anEdge, GeomAPI_Shape::VERTEX);
+      for (; anExp.more(); anExp.next()) {
+        GeomVertexPtr aCurV = anExp.current()->vertex();
+        isInside = !GeomAlgoAPI_ShapeTools::isSubShapeInsideShape(aVertex, aCurV);
+      }
+    }
+  }
+  return isInside;
+}
+
 std::string doubleToString(double theValue)
 {
   std::string aValueStr;