Salome HOME
Issue #1860: fix end lines with spaces
[modules/shaper.git] / src / GeomAPI / GeomAPI_Circ.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAPI_Circ2cpp
4 // Created:     24 Jun 2014
5 // Author:      Artem ZHIDKOV
6
7 #include <GeomAPI_Circ.h>
8
9 #include <GeomAPI_Ax2.h>
10 #include <GeomAPI_Pnt.h>
11 #include <GeomAPI_Dir.h>
12
13 #include <gp_Dir.hxx>
14 #include <gp_Circ.hxx>
15 #include <gp_Pnt.hxx>
16 #include <gp_Ax2.hxx>
17
18 #include <Geom_Circle.hxx>
19 #include <GeomAPI_ProjectPointOnCurve.hxx>
20 #include <GeomLib_Tool.hxx>
21
22 #define MY_CIRC implPtr<gp_Circ>()
23
24 static gp_Circ* newCirc(const gp_Pnt& theCenter, const gp_Dir& theDir, const double theRadius)
25 {
26   return new gp_Circ(gp_Ax2(theCenter, theDir), theRadius);
27 }
28
29 //=================================================================================================
30 GeomAPI_Circ::GeomAPI_Circ(const std::shared_ptr<GeomAPI_Ax2> theAx2,
31                            const double theRadius)
32 : GeomAPI_Interface(new gp_Circ(theAx2->impl<gp_Ax2>(), theRadius))
33 {
34
35 }
36
37
38 //=================================================================================================
39 GeomAPI_Circ::GeomAPI_Circ(const std::shared_ptr<GeomAPI_Pnt>& theCenter,
40                            const std::shared_ptr<GeomAPI_Dir>& theDir, double theRadius)
41     : GeomAPI_Interface(newCirc(theCenter->impl<gp_Pnt>(), theDir->impl<gp_Dir>(), theRadius))
42 {
43 }
44
45 //=================================================================================================
46 const std::shared_ptr<GeomAPI_Pnt> GeomAPI_Circ::center() const
47 {
48   const gp_Pnt& aCenter = MY_CIRC->Location();
49   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aCenter.X(), aCenter.Y(), aCenter.Z()));
50 }
51
52 //=================================================================================================
53 double GeomAPI_Circ::radius() const
54 {
55   return MY_CIRC->Radius();
56 }
57
58 //=================================================================================================
59 const std::shared_ptr<GeomAPI_Pnt> GeomAPI_Circ::project(
60     const std::shared_ptr<GeomAPI_Pnt>& thePoint) const
61 {
62   std::shared_ptr<GeomAPI_Pnt> aResult;
63   if (!MY_CIRC)
64   return aResult;
65
66   Handle(Geom_Circle) aCircle = new Geom_Circle(*MY_CIRC);
67
68   const gp_Pnt& aPoint = thePoint->impl<gp_Pnt>();
69
70   GeomAPI_ProjectPointOnCurve aProj(aPoint, aCircle);
71   Standard_Integer aNbPoint = aProj.NbPoints();
72   if (aNbPoint > 0) {
73     double aMinDistance = Precision::Infinite(), aDistance;
74     for (Standard_Integer j = 1; j <= aNbPoint; j++) {
75       gp_Pnt aNewPoint = aProj.Point(j);
76       aDistance = aNewPoint.Distance(aPoint);
77       if (aDistance < aMinDistance) {
78         aMinDistance = aDistance;
79         aResult = std::shared_ptr<GeomAPI_Pnt>(
80             new GeomAPI_Pnt(aNewPoint.X(), aNewPoint.Y(), aNewPoint.Z()));
81       }
82     }
83   }
84   return aResult;
85 }
86
87 //=================================================================================================
88 const bool GeomAPI_Circ::parameter(const std::shared_ptr<GeomAPI_Pnt> thePoint,
89                                    const double theTolerance,
90                                    double& theParameter) const
91 {
92   Handle(Geom_Circle) aCurve = new Geom_Circle(*MY_CIRC);
93   return GeomLib_Tool::Parameter(aCurve, thePoint->impl<gp_Pnt>(),
94                                  theTolerance, theParameter) == Standard_True;
95 }
96
97 //=================================================================================================
98 std::shared_ptr<GeomAPI_Dir> GeomAPI_Circ::normal() const
99 {
100   const gp_Ax1& anAxis = MY_CIRC->Axis();
101   const gp_Dir& aDir = anAxis.Direction();
102   return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
103 }