Salome HOME
Correct case when the weak-named attribute is dumped in Geom mode: geometrical repres...
[modules/shaper.git] / src / GeomAPI / GeomAPI_Circ2d.cpp
index 65ef9b10786b77808f75544a3097b726e9bfdee9..5df372df7d1762ae09d2ec65984abcd522dc2b2d 100644 (file)
@@ -1,22 +1,35 @@
-// File:        GeomAPI_Circ2d.cpp
-// Created:     29 May 2014
-// Author:      Artem ZHIDKOV
+// Copyright (C) 2014-2017  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<mailto:webmaster.salome@opencascade.com>
+//
 
 #include <GeomAPI_Circ2d.h>
 #include <GeomAPI_Pnt2d.h>
 #include <GeomAPI_Dir2d.h>
 
-#include <gp_Dir2d.hxx>
 #include <gp_Circ2d.hxx>
 #include <gp_Pnt2d.hxx>
-#include <gp_Ax2d.hxx>
+#include <GeomLib_Tool.hxx>
 #include <Geom2d_Circle.hxx>
-#include <Geom2dAPI_ProjectPointOnCurve.hxx>
 #include <Precision.hxx>
 
-#include <IntAna2d_AnaIntersection.hxx>
+#define MY_CIRC2D implPtr<gp_Circ2d>()
 
-#define MY_CIRC2D static_cast<gp_Circ2d*>(myImpl)
 
 static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY, const gp_Dir2d theDir,
                             const double theRadius)
@@ -36,64 +49,86 @@ static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY,
   if (aCenter.IsEqual(aPoint, Precision::Confusion()))
     return NULL;
 
-  gp_Dir2d aDir(theCenterX - thePointX, theCenterY - thePointY);
+  gp_Dir2d aDir(thePointX - theCenterX, thePointY - theCenterY);
 
   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_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 boost::shared_ptr<GeomAPI_Pnt2d>& theCenter,
-                               const boost::shared_ptr<GeomAPI_Dir2d>& theDir, double theRadius)
+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);
+    return aResult;
 
+  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
 {
+  if (!MY_CIRC2D)
+    return std::shared_ptr<GeomAPI_Pnt2d>();
   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
 {
+  if (!MY_CIRC2D)
+    return 0.0;
   return MY_CIRC2D->Radius();
 }
 
+//=================================================================================================
+const bool GeomAPI_Circ2d::parameter(const std::shared_ptr<GeomAPI_Pnt2d> thePoint,
+                                   const double theTolerance,
+                                   double& theParameter) const
+{
+  Handle(Geom2d_Circle) aCurve = new Geom2d_Circle(*MY_CIRC2D);
+  return GeomLib_Tool::Parameter(aCurve, thePoint->impl<gp_Pnt2d>(),
+                                 theTolerance, theParameter) == Standard_True;
+}
+
+//=================================================================================================
+void GeomAPI_Circ2d::D0(const double theU, std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+  Handle(Geom2d_Circle) aCurve = new Geom2d_Circle(*MY_CIRC2D);
+  gp_Pnt2d aPnt;
+  aCurve->D0(theU, aPnt);
+  thePoint.reset(new GeomAPI_Pnt2d(aPnt.X(), aPnt.Y()));
+}
+