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_Dir2d.hxx>
12 #include <gp_Circ2d.hxx>
13 #include <gp_Pnt2d.hxx>
14 #include <gp_Ax2d.hxx>
15 #include <Geom2d_Circle.hxx>
16 #include <Geom2dAPI_ProjectPointOnCurve.hxx>
17 #include <Precision.hxx>
19 #include <IntAna2d_AnaIntersection.hxx>
21 #define MY_CIRC2D static_cast<gp_Circ2d*>(myImpl)
23 static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY, const gp_Dir2d theDir,
24 const double theRadius)
26 gp_Pnt2d aCenter(theCenterX, theCenterY);
27 return new gp_Circ2d(gp_Ax2d(aCenter, theDir), theRadius);
30 static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY,
31 const double thePointX, const double thePointY)
33 gp_Pnt2d aCenter(theCenterX, theCenterY);
34 gp_Pnt2d aPoint(thePointX, thePointY);
36 double aRadius = aCenter.Distance(aPoint);
38 if (aCenter.IsEqual(aPoint, Precision::Confusion()))
41 gp_Dir2d aDir(theCenterX - thePointX, theCenterY - thePointY);
43 return newCirc2d(theCenterX, theCenterY, aDir, aRadius);
46 GeomAPI_Circ2d::GeomAPI_Circ2d(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
47 const std::shared_ptr<GeomAPI_Pnt2d>& theCirclePoint)
49 newCirc2d(theCenter->x(), theCenter->y(), theCirclePoint->x(), theCirclePoint->y()))
53 GeomAPI_Circ2d::GeomAPI_Circ2d(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
54 const std::shared_ptr<GeomAPI_Dir2d>& theDir, double theRadius)
56 newCirc2d(theCenter->x(), theCenter->y(), theDir->impl<gp_Dir2d>(), theRadius))
61 const std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Circ2d::project(
62 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint) const
64 std::shared_ptr<GeomAPI_Pnt2d> aResult;
68 const gp_Pnt2d& aCenter = MY_CIRC2D->Location();
69 const gp_Pnt2d& aPoint = thePoint->impl<gp_Pnt2d>();
71 double aDist = aCenter.Distance(aPoint);
72 if (aDist < Precision::Confusion())
75 if (Abs(aDist - MY_CIRC2D->Radius()) < Precision::Confusion()) {
76 // Point on the circle
77 aResult = std::shared_ptr<GeomAPI_Pnt2d>(
78 new GeomAPI_Pnt2d(thePoint->x(), thePoint->y()));
80 gp_Dir2d aDir(aPoint.XY() - aCenter.XY());
81 gp_XY aNewPoint = aCenter.XY() + aDir.XY() * MY_CIRC2D->Radius();
82 aResult = std::shared_ptr<GeomAPI_Pnt2d>(
83 new GeomAPI_Pnt2d(aNewPoint.X(), aNewPoint.Y()));
89 const std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Circ2d::center() const
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
97 return MY_CIRC2D->Radius();