Salome HOME
Replace void* with shared_ptr<void> in GeomAPI_Interface
[modules/shaper.git] / src / GeomAPI / GeomAPI_Circ2d.cpp
index 78c26d69f12049724139dcf49f75b2f26cedbe5d..0e0a21a310363b97656f94d14f5b6ecd05f17ee9 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:        GeomAPI_Circ2d.cpp
 // Created:     29 May 2014
 // Author:      Artem ZHIDKOV
 
 #include <IntAna2d_AnaIntersection.hxx>
 
-#define MY_CIRC2D static_cast<gp_Circ2d*>(myImpl)
+#define MY_CIRC2D implPtr<gp_Circ2d>()
 
-static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY,
-                            const gp_Dir2d theDir, const double theRadius)
+static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY, const gp_Dir2d theDir,
+                            const double theRadius)
 {
   gp_Pnt2d aCenter(theCenterX, theCenterY);
   return new gp_Circ2d(gp_Ax2d(aCenter, theDir), theRadius);
 }
 
 static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY,
-                            const double thePointX,   const double thePointY)
+                            const double thePointX, const double thePointY)
 {
   gp_Pnt2d aCenter(theCenterX, theCenterY);
   gp_Pnt2d aPoint(thePointX, thePointY);
@@ -34,61 +36,60 @@ static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY,
   double aRadius = aCenter.Distance(aPoint);
 
   if (aCenter.IsEqual(aPoint, Precision::Confusion()))
-      return NULL;
+    return NULL;
 
   gp_Dir2d aDir(theCenterX - thePointX, theCenterY - thePointY);
-  
+
   return newCirc2d(theCenterX, theCenterY, aDir, aRadius);
 }
 
-GeomAPI_Circ2d::GeomAPI_Circ2d(const boost::shared_ptr<GeomAPI_Pnt2d>& theCenter,
-                               const boost::shared_ptr<GeomAPI_Pnt2d>& theCirclePoint)
-  : GeomAPI_Interface(newCirc2d(theCenter->x(), theCenter->y(),
-                                theCirclePoint->x(),   theCirclePoint->y()))
-{}
-
-GeomAPI_Circ2d::GeomAPI_Circ2d(const boost::shared_ptr<GeomAPI_Pnt2d>& theCenter,
-                               const boost::shared_ptr<GeomAPI_Dir2d>& theDir,
-                               double theRadius)
- : GeomAPI_Interface(newCirc2d(theCenter->x(), theCenter->y(),
-                               theDir->impl<gp_Dir2d>(), theRadius))
+GeomAPI_Circ2d::GeomAPI_Circ2d(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+                               const std::shared_ptr<GeomAPI_Pnt2d>& theCirclePoint)
+    : GeomAPI_Interface(
+        newCirc2d(theCenter->x(), theCenter->y(), theCirclePoint->x(), theCirclePoint->y()))
+{
+}
+
+GeomAPI_Circ2d::GeomAPI_Circ2d(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+                               const std::shared_ptr<GeomAPI_Dir2d>& theDir, double theRadius)
+    : GeomAPI_Interface(
+        newCirc2d(theCenter->x(), theCenter->y(), theDir->impl<gp_Dir2d>(), theRadius))
 {
 
 }
 
-const boost::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Circ2d::project(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const
+const std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Circ2d::project(
+    const std::shared_ptr<GeomAPI_Pnt2d>& thePoint) const
 {
-  boost::shared_ptr<GeomAPI_Pnt2d> aResult;
+  std::shared_ptr<GeomAPI_Pnt2d> aResult;
   if (!MY_CIRC2D)
     return aResult;
 
-  Handle(Geom2d_Circle) aCircle = new Geom2d_Circle(MY_CIRC2D->Axis(), MY_CIRC2D->Radius());//(aCirc);
-
+  const gp_Pnt2d& aCenter = MY_CIRC2D->Location();
   const gp_Pnt2d& aPoint = thePoint->impl<gp_Pnt2d>();
 
-  Geom2dAPI_ProjectPointOnCurve aProj(aPoint, aCircle);
-  Standard_Integer aNbPoint = aProj.NbPoints();
-  double aX, anY;
-  if (aNbPoint > 0) {
-    double aMinDistance = 0, aDistance;
-    for (Standard_Integer j = 1; j <= aNbPoint; j++) {
-      gp_Pnt2d aNewPoint = aProj.Point(j);
-      aDistance = aNewPoint.Distance(aPoint);
-      if (!aMinDistance || aDistance < aMinDistance) {
-        aX = aNewPoint.X();
-        anY = aNewPoint.Y();
-        aMinDistance = aDistance;
-        aResult = boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, anY));
-      }
-    }
+  double aDist = aCenter.Distance(aPoint);
+  if (aDist < Precision::Confusion())
+    return aResult;
+
+  if (Abs(aDist - MY_CIRC2D->Radius()) < Precision::Confusion()) {
+    // Point on the circle
+    aResult = std::shared_ptr<GeomAPI_Pnt2d>(
+        new GeomAPI_Pnt2d(thePoint->x(), thePoint->y()));
+  } else {
+    gp_Dir2d aDir(aPoint.XY() - aCenter.XY());
+    gp_XY aNewPoint = aCenter.XY() + aDir.XY() * MY_CIRC2D->Radius();
+    aResult = std::shared_ptr<GeomAPI_Pnt2d>(
+        new GeomAPI_Pnt2d(aNewPoint.X(), aNewPoint.Y()));
   }
+
   return aResult;
 }
 
-const boost::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Circ2d::center() const
+const std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Circ2d::center() const
 {
   const gp_Pnt2d& aCenter = MY_CIRC2D->Location();
-  return boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aCenter.X(), aCenter.Y()));
+  return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aCenter.X(), aCenter.Y()));
 }
 
 double GeomAPI_Circ2d::radius() const