Salome HOME
Improve code coverage for elliptic arcs.
[modules/shaper.git] / src / GeomAPI / GeomAPI_Vertex.cpp
index 6c3d05e3556f1caff93dccd40fb1d07eb92f080e..683413c63e9a2aa92cdc35af97daa64a06464f29 100644 (file)
@@ -1,8 +1,21 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        GeomAPI_Vertex.cpp
-// Created:     24 Jul 2014
-// Author:      Artem ZHIDKOV
+// 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<GeomAPI_Vertex.h>
 #include<GeomAPI_Pnt.h>
@@ -12,6 +25,7 @@
 #include <TopoDS.hxx>
 #include <TopoDS_Vertex.hxx>
 #include <BRep_Tool.hxx>
+#include <BRep_Builder.hxx>
 #include <gp_Pnt.hxx>
 #include <Precision.hxx>
 
@@ -27,6 +41,14 @@ GeomAPI_Vertex::GeomAPI_Vertex(const std::shared_ptr<GeomAPI_Shape>& theShape)
   }
 }
 
+GeomAPI_Vertex::GeomAPI_Vertex(double theX, double theY, double theZ)
+{
+  TopoDS_Vertex aVertex;
+  BRep_Builder aBuilder;
+  aBuilder.MakeVertex(aVertex, gp_Pnt(theX, theY, theZ), Precision::Confusion());
+  setImpl(new TopoDS_Shape(aVertex));
+}
+
 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Vertex::point()
 {
   const TopoDS_Shape& aShape = const_cast<GeomAPI_Vertex*>(this)->impl<TopoDS_Shape>();
@@ -35,16 +57,21 @@ std::shared_ptr<GeomAPI_Pnt> GeomAPI_Vertex::point()
   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
 }
 
-bool GeomAPI_Vertex::isEqual(std::shared_ptr<GeomAPI_Shape> theVert)
+bool GeomAPI_Vertex::isEqual(const std::shared_ptr<GeomAPI_Shape> theVert) const
 {
+  if (!theVert.get() || ! theVert->isVertex())
+    return false;
   const TopoDS_Shape& aMyShape = const_cast<GeomAPI_Vertex*>(this)->impl<TopoDS_Shape>();
   const TopoDS_Shape& aInShape = theVert->impl<TopoDS_Shape>();
 
+  if (aMyShape.ShapeType() != aInShape.ShapeType())
+    return false;
+
   TopoDS_Vertex aVertex1 = TopoDS::Vertex(aMyShape);
   gp_Pnt aPoint1 = BRep_Tool::Pnt(aVertex1);
 
   TopoDS_Vertex aVertex2 = TopoDS::Vertex(aInShape);
   gp_Pnt aPoint2 = BRep_Tool::Pnt(aVertex2);
 
-  return aPoint1.IsEqual(aPoint2, Precision::Confusion());
+  return aPoint1.IsEqual(aPoint2, Precision::Confusion()) == Standard_True;
 }