Salome HOME
Task 3.9. Detect free points in the sketcher (issue #2927)
[modules/shaper.git] / src / GeomAPI / GeomAPI_Circ2d.cpp
index cbb16dd4be9757a23c4c84b90dc6cef6553a33ca..5204f25e5ca5def7ac0d599552ca98c73737a5fd 100644 (file)
@@ -1,26 +1,35 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        GeomAPI_Circ2d.cpp
-// Created:     29 May 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_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>()
 
+
 static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY, const gp_Dir2d theDir,
                             const double theRadius)
 {
@@ -44,48 +53,7 @@ static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY,
   return newCirc2d(theCenterX, theCenterY, aDir, aRadius);
 }
 
-static gp_Circ2d* newCirc2d(const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
-                            const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint,
-                            const std::shared_ptr<GeomAPI_Pnt2d>& theThirdPoint)
-{
-  gp_XY aFirstPnt(theFirstPoint->x(), theFirstPoint->y());
-  gp_XY aSecondPnt(theSecondPoint->x(), theSecondPoint->y());
-  gp_XY aThirdPnt(theThirdPoint->x(), theThirdPoint->y());
-
-  gp_XY aVec12 = aSecondPnt - aFirstPnt;
-  gp_XY aVec23 = aThirdPnt - aSecondPnt;
-  gp_XY aVec31 = aFirstPnt - aThirdPnt;
-
-  // coefficients to calculate center
-  double aCoeff1, aCoeff2, aCoeff3;
-
-  // square of parallelogram
-  double aSquare2 = aVec12.Crossed(aVec23);
-  aSquare2 *= aSquare2 * 2.0;
-  if (aSquare2 < 1.e-20) {
-    // if two points are equal, build a circle on two different points as on diameter
-    double aSqLen12 = aVec12.SquareModulus();
-    double aSqLen23 = aVec23.SquareModulus();
-    double aSqLen31 = aVec31.SquareModulus();
-    if (aSqLen12 < Precision::SquareConfusion() &&
-        aSqLen23 < Precision::SquareConfusion() &&
-        aSqLen31 < Precision::SquareConfusion())
-      return NULL;
-    aCoeff1 = aCoeff2 = aCoeff3 = 1.0 / 3.0;
-  }
-  else {
-    aCoeff1 = aVec23.Dot(aVec23) / aSquare2 * aVec12.Dot(aVec31.Reversed());
-    aCoeff2 = aVec31.Dot(aVec31) / aSquare2 * aVec23.Dot(aVec12.Reversed());
-    aCoeff3 = aVec12.Dot(aVec12) / aSquare2 * aVec31.Dot(aVec23.Reversed());
-  }
-  // center
-  gp_XY aCenter = aFirstPnt * aCoeff1 + aSecondPnt * aCoeff2 + aThirdPnt * aCoeff3;
-  // radius
-  double aRadius = (aFirstPnt - aCenter).Modulus();
 
-  gp_Dir2d aDir(aFirstPnt - aCenter);
-  return newCirc2d(aCenter.X(), aCenter.Y(), aDir, aRadius);
-}
 
 GeomAPI_Circ2d::GeomAPI_Circ2d(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
                                const std::shared_ptr<GeomAPI_Pnt2d>& theCirclePoint)
@@ -101,13 +69,6 @@ GeomAPI_Circ2d::GeomAPI_Circ2d(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
 {
 }
 
-GeomAPI_Circ2d::GeomAPI_Circ2d(const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
-                               const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint,
-                               const std::shared_ptr<GeomAPI_Pnt2d>& theThirdPoint)
-    : GeomAPI_Interface(newCirc2d(theFirstPoint, theSecondPoint, theThirdPoint))
-{
-}
-
 const std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Circ2d::project(
     const std::shared_ptr<GeomAPI_Pnt2d>& thePoint) const
 {
@@ -157,7 +118,8 @@ const bool GeomAPI_Circ2d::parameter(const std::shared_ptr<GeomAPI_Pnt2d> thePoi
                                    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;
+  return GeomLib_Tool::Parameter(aCurve, thePoint->impl<gp_Pnt2d>(),
+                                 theTolerance, theParameter) == Standard_True;
 }
 
 //=================================================================================================