1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAPI_Circ2d.cpp
4 // Created: 29 May 2014
5 // Author: Artem ZHIDKOV
7 #include <GeomAPI_Circ2d.h>
8 #include <GeomAPI_Pnt2d.h>
9 #include <GeomAPI_Dir2d.h>
11 #include <gp_Circ2d.hxx>
12 #include <gp_Pnt2d.hxx>
13 #include <GeomLib_Tool.hxx>
14 #include <Geom2d_Circle.hxx>
15 #include <Precision.hxx>
17 #define MY_CIRC2D implPtr<gp_Circ2d>()
20 static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY, const gp_Dir2d theDir,
21 const double theRadius)
23 gp_Pnt2d aCenter(theCenterX, theCenterY);
24 return new gp_Circ2d(gp_Ax2d(aCenter, theDir), theRadius);
27 static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY,
28 const double thePointX, const double thePointY)
30 gp_Pnt2d aCenter(theCenterX, theCenterY);
31 gp_Pnt2d aPoint(thePointX, thePointY);
33 double aRadius = aCenter.Distance(aPoint);
35 if (aCenter.IsEqual(aPoint, Precision::Confusion()))
38 gp_Dir2d aDir(thePointX - theCenterX, thePointY - theCenterY);
40 return newCirc2d(theCenterX, theCenterY, aDir, aRadius);
45 GeomAPI_Circ2d::GeomAPI_Circ2d(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
46 const std::shared_ptr<GeomAPI_Pnt2d>& theCirclePoint)
48 newCirc2d(theCenter->x(), theCenter->y(), theCirclePoint->x(), theCirclePoint->y()))
52 GeomAPI_Circ2d::GeomAPI_Circ2d(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
53 const std::shared_ptr<GeomAPI_Dir2d>& theDir, double theRadius)
55 newCirc2d(theCenter->x(), theCenter->y(), theDir->impl<gp_Dir2d>(), theRadius))
59 const std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Circ2d::project(
60 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint) const
62 std::shared_ptr<GeomAPI_Pnt2d> aResult;
66 const gp_Pnt2d& aCenter = MY_CIRC2D->Location();
67 const gp_Pnt2d& aPoint = thePoint->impl<gp_Pnt2d>();
69 double aDist = aCenter.Distance(aPoint);
70 if (aDist < Precision::Confusion())
73 if (Abs(aDist - MY_CIRC2D->Radius()) < Precision::Confusion()) {
74 // Point on the circle
75 aResult = std::shared_ptr<GeomAPI_Pnt2d>(
76 new GeomAPI_Pnt2d(thePoint->x(), thePoint->y()));
78 gp_Dir2d aDir(aPoint.XY() - aCenter.XY());
79 gp_XY aNewPoint = aCenter.XY() + aDir.XY() * MY_CIRC2D->Radius();
80 aResult = std::shared_ptr<GeomAPI_Pnt2d>(
81 new GeomAPI_Pnt2d(aNewPoint.X(), aNewPoint.Y()));
87 const std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Circ2d::center() const
90 return std::shared_ptr<GeomAPI_Pnt2d>();
91 const gp_Pnt2d& aCenter = MY_CIRC2D->Location();
92 return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aCenter.X(), aCenter.Y()));
95 double GeomAPI_Circ2d::radius() const
99 return MY_CIRC2D->Radius();
102 //=================================================================================================
103 const bool GeomAPI_Circ2d::parameter(const std::shared_ptr<GeomAPI_Pnt2d> thePoint,
104 const double theTolerance,
105 double& theParameter) const
107 Handle(Geom2d_Circle) aCurve = new Geom2d_Circle(*MY_CIRC2D);
108 return GeomLib_Tool::Parameter(aCurve, thePoint->impl<gp_Pnt2d>(),
109 theTolerance, theParameter) == Standard_True;
112 //=================================================================================================
113 void GeomAPI_Circ2d::D0(const double theU, std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
115 Handle(Geom2d_Circle) aCurve = new Geom2d_Circle(*MY_CIRC2D);
117 aCurve->D0(theU, aPnt);
118 thePoint.reset(new GeomAPI_Pnt2d(aPnt.X(), aPnt.Y()));