1 // File: GeomAPI_Circ2d.cpp
2 // Created: 29 May 2014
3 // Author: Artem ZHIDKOV
5 #include <GeomAPI_Circ2d.h>
6 #include <GeomAPI_Pnt2d.h>
7 #include <GeomAPI_Dir2d.h>
9 #include <gp_Dir2d.hxx>
10 #include <gp_Circ2d.hxx>
11 #include <gp_Pnt2d.hxx>
12 #include <gp_Ax2d.hxx>
13 #include <Geom2d_Circle.hxx>
14 #include <Geom2dAPI_ProjectPointOnCurve.hxx>
15 #include <Precision.hxx>
17 #include <IntAna2d_AnaIntersection.hxx>
19 #define MY_CIRC2D static_cast<gp_Circ2d*>(myImpl)
21 static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY, const gp_Dir2d theDir,
22 const double theRadius)
24 gp_Pnt2d aCenter(theCenterX, theCenterY);
25 return new gp_Circ2d(gp_Ax2d(aCenter, theDir), theRadius);
28 static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY,
29 const double thePointX, const double thePointY)
31 gp_Pnt2d aCenter(theCenterX, theCenterY);
32 gp_Pnt2d aPoint(thePointX, thePointY);
34 double aRadius = aCenter.Distance(aPoint);
36 if (aCenter.IsEqual(aPoint, Precision::Confusion()))
39 gp_Dir2d aDir(theCenterX - thePointX, theCenterY - thePointY);
41 return newCirc2d(theCenterX, theCenterY, aDir, aRadius);
44 GeomAPI_Circ2d::GeomAPI_Circ2d(const boost::shared_ptr<GeomAPI_Pnt2d>& theCenter,
45 const boost::shared_ptr<GeomAPI_Pnt2d>& theCirclePoint)
47 newCirc2d(theCenter->x(), theCenter->y(), theCirclePoint->x(), theCirclePoint->y()))
51 GeomAPI_Circ2d::GeomAPI_Circ2d(const boost::shared_ptr<GeomAPI_Pnt2d>& theCenter,
52 const boost::shared_ptr<GeomAPI_Dir2d>& theDir, double theRadius)
54 newCirc2d(theCenter->x(), theCenter->y(), theDir->impl<gp_Dir2d>(), theRadius))
59 const boost::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Circ2d::project(
60 const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const
62 boost::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 = boost::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 = boost::shared_ptr<GeomAPI_Pnt2d>(
81 new GeomAPI_Pnt2d(aNewPoint.X(), aNewPoint.Y()));
87 const boost::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Circ2d::center() const
89 const gp_Pnt2d& aCenter = MY_CIRC2D->Location();
90 return boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aCenter.X(), aCenter.Y()));
93 double GeomAPI_Circ2d::radius() const
95 return MY_CIRC2D->Radius();